Linking standalone NASM binary with libc

Giorgos Keramidas keramida at ceid.upatras.gr
Tue Aug 30 10:38:13 GMT 2005


On 2005-08-30 04:29, Jonathon McKitrick <jcm at 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$



More information about the freebsd-questions mailing list