Date: Tue, 30 Aug 2005 13:37:02 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Jonathon McKitrick <jcm@FreeBSD-uk.eu.org> Cc: freebsd-questions@freebsd.org Subject: Re: Linking standalone NASM binary with libc Message-ID: <20050830103702.GA80388@orion.daedalusnetworks.priv> In-Reply-To: <20050830032917.GA39730@dogma.freebsd-uk.eu.org> References: <20050830032917.GA39730@dogma.freebsd-uk.eu.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-08-30 04:29, Jonathon McKitrick <jcm@FreeBSD-uk.eu.org> wrote: > > I'm doing some experimentation with assembly code based on the int80h.org > tutorials. But since I am going to use malloc and some other functions, > I need to make my code link with libc rather than stand totally on its own. > > ld -s -o foo foo.o -lc > > leaves 'environ' and '__progname' undefined. What is the correct way to link > standalone asm code with needed libraries? That depends on what the ``standalone'' code contains. If your foo.o object file defines a 'main' function, then you can just use cc(1): % tesla:/tmp/foo$ cat -n foo.asm % 1 global main % 2 main: % 3 mov eax,1 ; exit() syscall % 4 mov ebx,1 ; exit code % 5 int 0x80 ; trap into kernel % tesla:/tmp/foo$ nasm -f elf -o foo.o foo.asm ==> % tesla:/tmp/foo$ cc -o foo foo.o % tesla:/tmp/foo$ ./foo % tesla:/tmp/foo$ echo $? % 1 % tesla:/tmp/foo$
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050830103702.GA80388>