[buug] cannot execute binary file or use printf
Ian Zimmerman
itz at buug.org
Mon Apr 13 19:43:33 PDT 2009
If I try to use printf I can't link:
-------------------------------
john at ldev:~/asm/test$ cat add.s
.section .data
output:
.asciz "%d = %d + %d\n"
.section .text
.globl _start
_start:
nop
movl $9, %eax
movl $22, %ebx
pushl %ebx
pushl %eax
xadd %eax, %ebx
pushl %ebx
pushl $output
call printf
call exit
john at ldev:~/asm/test$ as ./add.s -o add.o
john at ldev:~/asm/test$ ld -dynamic-linker /lib/ld-linux.so.2 -o add add.o
add.o: In function `_start':
(.text+0x17): undefined reference to `printf'
add.o: In function `_start':
(.text+0x1c): undefined reference to `exit
john at ldev:~/asm/test$
If you execute ld explicitly (as opposed to having gcc execute it for you),
you must also list all libraries, including libc. So adding -lc (and possibly
-lm) to your command should help.
I assume your system is Linux .. you know better than not telling us :)
Not sure exactly about the first problem, but it happens to me too.
I also tried it with gcc:
itz at matica:~$ gcc -nostartfiles -nostdlib -o jump jump.s
itz at matica:~$ ./jump
bash: ./jump: cannot execute binary file
Have you upgraded the kernel recently? I did.
--
Ian Zimmerman <itz at buug.org>
gpg public key: 1024D/C6FF61AD
fingerprint: 66DC D68F 5C1B 4D71 2EE5 BD03 8A00 786C C6FF 61AD
Ham is for reading, not for eating.
More information about the buug
mailing list