assembly - gnu assembler printf error -
my os ubuntu 13.04 64 bit
i wasted many hours fix need help
this test.s returns
accessing corrupted shared library       .code32  .section .data par1: .int 33 msg: .asciz "%d\n" .section .text .globl _start _start: pushl $par1 pushl $msg call printf    cikis: movl $1,%eax movl $1,%ebx int $0x80   ldd test.out
ldd test.out     linux-vdso.so.1 =>  (0x00007fff615fe000)     libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbfb56f8000)     /lib32/libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x00007fbfb5ae0000)   makefile
as test.s -o test.o ld -dynamic-linker /lib/ld-linux.so.2 -lc test.o -o test.out   // tried
ld -dynamic-linker /lib32/ld-linux.so.2 -lc test.o -o test.out   how can use c functions in gas on 64 bit ubuntu
change both how assemble , link program , how you're pushing $par1 instead of par1:
.section .data n: .int 33 fmt: .asciz "n: %d\n" .section .text .global _start _start: pushl n pushl $fmt call printf  movl $1, %eax movl $0, %ebx int $0x80   assemble , link with:
cc -nostdlib -os -wall -g3 -m32 -lc printf-x86.s -o printf-x86   cc here alias gcc. regular compiler driver know right options pass as , ld plus means assembler source (.s) gets passed through c preprocessor , can use header files <sys/sdt.h>.
here's gnu make fragment in case need it:
%: %.s         $(cc) -nostdlib $(cflags) $(ldflags) $< -o $@ printf-x86: cflags+=-m32 printf-x86: ldflags+=-lc      
Comments
Post a Comment