Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 May 1999 20:42:23 -0400 (EDT)
From:      Luoqi Chen <luoqi@watermarkgroup.com>
To:        faber@ISI.EDU, freebsd-hackers@FreeBSD.ORG, luoqi@watermarkgroup.com
Subject:   Re:  FreeBSD native xanim (was Re: Native Applixware for FreeBSD -- When? )
Message-ID:  <199905120042.UAA05242@lor.watermarkgroup.com>

next in thread | raw e-mail | index | archive | help
> > On a related note, I don't know if people use xanim, a movie viewer in
> > the ports collection, but it's recently been upgraded to support
> > dynamically loadable codecs.  The problem is that none of the codecs
> > are compiled for FreeBSD, although there are three Linux versions :-).
> > To use them (really to use the program at all) you have to compile a
> > Linux version of xanim and run under emulation (which works really well, thanks
> > emulation guys!).
> > 
> > Yes, I've tried using the Linux codecs on the FreeBSD binary.  No dice. 
> > 
> > The author is perfectly willing to compile these codecs for FreeBSD,
> > but because he's under NDA for the codecs he can only release compiled
> > versions.  He's only willing to compile versions for other OSes under
> > Linux (i.e. compile the codecs for FreeBSD on his Linux machine) or on
> > a donated machine.  (His reasoning for this, which IMHO is rational,
> > is on http://xanim.va.pubnix.com/xa_dlls.html )
> > 
> > Given that he's running Linux, is a "cross-compiling environment" any
> > more complex than having him link against our libc?  If not can
> > someone give me an idea what he does need.
> > 
> > I'm delighted to act as a contact point and a tester for the xanim
> > author, but I just don't know enough about our link environment.
> > 
> > Anyone want to enlighten me?  (I tried this on multimedia, and got no
> > response).
> > 
> > - ----------------------------------------------------------------------
> > Ted Faber                                                faber@isi.edu
> > USC/ISI Computer Scientist                   http://www.isi.edu/~faber
> > (310) 822-1511 x190      PGP Key: http://www.isi.edu/~faber/pubkey.asc
> > 
> The only reason some of the linux codecs are not useable on FreeBSD is
> the reference of symbol __IO_stderr, it should be quite easy to convert
> them to references to &__sF[2].
> 
> -lq
> 
Compile this little program, use it to process the linux .xa files, and they
should be useable on FreeBSD.

-lq

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>

#include <stdio.h>
#include <elf.h>
#include <fcntl.h>

main(int argc, char **argv)
{
	int fd, i;
	void *addr;
	Elf_Ehdr *eh;
	Elf_Phdr *ph;
	Elf_Dyn *ed;
	Elf_Rel *reltab, *er;
	Elf_Sym *symtab;
	char *strtab, *name;
	int relsz, relent;
	struct stat stb;

	if (argc < 2)
		exit(1);

	fd = open(argv[1], O_RDWR);
	if (fd < 0)
		err(1, "%s", argv[1]);

	if (fstat(fd, &stb) < 0) {
		close(fd);
		err(-1, "fstat: %s", argv[1]);
	}

	addr = mmap(0, stb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
	close(fd);

	if ((int)addr == -1)
		err(-1, "mmap");

	eh = (Elf_Ehdr *)addr;
	if (!IS_ELF(*eh))
		err(1, "%s: not an ELF file", argv[1]);

	ph = (Elf_Phdr *)((unsigned)addr + eh->e_phoff);
	for (i = 0; i < eh->e_phnum; i++, ph++) {
		if (ph->p_type == PT_DYNAMIC)
			break;
	}

	if (i >= eh->e_phnum)
		err(-1, "no dynamic section");

	ed = (Elf_Dyn *)((unsigned)addr + ph->p_offset);
	for (; ed->d_tag != DT_NULL; ed++) {
		if (ed->d_tag == DT_STRTAB)
			strtab = (char *)((unsigned)addr + ed->d_un.d_val);
		if (ed->d_tag == DT_SYMTAB)
			symtab = (Elf_Sym *)((unsigned)addr + ed->d_un.d_val);
		if (ed->d_tag == DT_REL)
			reltab = (Elf_Rel *)((unsigned)addr + ed->d_un.d_val);
		if (ed->d_tag == DT_RELSZ)
			relsz = ed->d_un.d_val;
		if (ed->d_tag == DT_RELENT)
			relent = ed->d_un.d_val;
	}

	for (i = 0, er = reltab; i < relsz / relent; i++, er++) {
		name = &strtab[symtab[ELF_R_SYM(er->r_info)].st_name];
		if (strcmp("_IO_stderr_", name))
			continue;
		strcpy(name, "__sF");
		*(unsigned long *)((unsigned)addr + er->r_offset) +=
			(unsigned)stderr - (unsigned)stdin;
	}

	munmap(addr, stb.st_size);
}


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199905120042.UAA05242>