Hi all.  I am trying to learn asm with NASM on a FreeBSD system.  I really
need to debug my programs while I learn, so I want to use printf.  This is
what I am using to assemble and link:

nasm -f elf use_printf.asm
ld -o use_printf use_printf.asm -lc

but then when I run the program:

$./use_printf
/usr/libexec/ld-elf.so.1: /lib/libc.so.5: Undefined symbol "environ"

If I try to use static linking, I get this:

$ld -static -o use_printf use_printf.asm -lc
/usr/lib/libc.a(getenv.o): In function `getenv':
getenv.o(.text+0x19): undefined reference to `environ'
getenv.o(.text+0x29): undefined reference to `environ'
getenv.o(.text+0x63): undefined reference to `environ'
/usr/lib/libc.a(getenv.o): In function `__findenv':
getenv.o(.text+0xd5): undefined reference to `environ'
getenv.o(.text+0xe2): undefined reference to `environ'
/usr/lib/libc.a(getenv.o)(.text+0x113): more undefined references to `environ' follow
/usr/lib/libc.a(getprogname.o): In function `_getprogname':
getprogname.o(.text+0x4): undefined reference to `__progname'

Can somebody see where I am going wrong?  This is kindof holding me back.  I
added the 'extern environ' and 'extern __progname' beause I get this otherwise:
(when NOT using -static)

/usr/lib/libc.so: undefined reference to `environ'
/usr/lib/libc.so: undefined reference to `__progname'

Here's what I have:


;;;;;;;;;;;;;;;;;;;;;; BEGIN CODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;

extern  printf
extern  environ
extern  __progname

section .data
mesg            db       'the number is %d\n',0
mesglen         equ      $-mesg

errormesg       db       'libc error',0ah,0
errormesglen    equ      $-errormesg

newline         db      10
number          dw      0x10

kernel:
       int 80h
       ret

align 4
section .text
global _start
_start:

        ; call printf from libc
        push dword      number
        push dword      mesg
        call printf

        ; error if eax < 1  ( we should have wrote some chars )
        cmp eax , 0x1
        jl      .error

        ; use write() system call to print message
        push    dword   mesglen
        push    dword   mesg
        push    dword   0x1   ; stdout
        mov     eax   , 0x4   ; 4 == write system call
        call    kernel

        ; output a newline
        push    dword   1
        push    dword   newline
        push    dword   0x1
        mov     eax   , 0x4
        call    kernel


        mov  eax  , 0x1 ; exit syscall number
        push dword  0x0 ; exit status
        call kernel

.error:

        push dword  errormesglen
        push dword  errormesg
        push dword  0x1
        mov         eax , 0x4
        call        kernel

        mov         eax  , 0x1
        push        dword  0xff
        call        kernel


;;;;;;;;;;;;;;;;  END CODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;

Any suggestions will be greatly appreciated.  Thanks

-Adam


_______________________________________________
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to