0

我的操作系统是 ubuntu 13.04 64 位


我浪费了很多时间来修复它真的需要你的帮助

这个 test.s 返回

Accessing a 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)

生成文件

as test.s -o test.o
ld -dynamic-linker /lib/ld-linux.so.2 -lc test.o -o test.out

// 我也试过

ld -dynamic-linker /lib32/ld-linux.so.2 -lc test.o -o test.out

如何在 64 位 ubuntu 上的 gas 中使用 C 函数

4

1 回答 1

0

更改组装和链接程序的方式以及推送$par1方式,而不是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

组装和链接:

cc -nostdlib -Os -Wall -g3 -m32 -lc printf-x86.S -o printf-x86

cc这里只是gcc的别名。常规编译器驱动程序知道传递给asld的正确选项,这意味着您的汇编源代码 (.S) 通过 C 预处理器传递,您可以使用头文件,如<sys/sdt.h>.

如果您需要,这里有一个 GNU make 片段:

%: %.S
        $(CC) -nostdlib $(CFLAGS) $(LDFLAGS) $< -o $@
printf-x86: CFLAGS+=-m32
printf-x86: LDFLAGS+=-lc
于 2013-05-14T23:54:35.147 回答