【问题标题】:gnu assembler printf errorgnu 汇编程序 printf 错误
【发布时间】:2013-05-14 21:28:54
【问题描述】:

我的操作系统是 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 函数

【问题讨论】:

  • 尝试将-melf_i386 添加到您的ld 命令行...

标签: assembly printf


【解决方案1】:

改变你组装和链接程序的方式以及你推送$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 的别名。常规编译器驱动程序会知道传递给 as 和 ld 的正确选项,这意味着您的汇编源代码 (.S) 通过 C 预处理器传递,您可以使用标头<sys/sdt.h> 之类的文件。

这是一个 GNU make 片段,以备不时之需:

%: %.S
        $(CC) -nostdlib $(CFLAGS) $(LDFLAGS) $< -o $@
printf-x86: CFLAGS+=-m32
printf-x86: LDFLAGS+=-lc

【讨论】:

  • 返回 /usr/bin/ld: 找不到 -lc collect2: 错误:当我写 cc -nostdlib -Os -Wall -g3 -m32 -lc printf-x86.S 时 ld 返回 1 退出状态-o printf-x86
  • @Assembler,安装 i686 glibc 开发包。您可能只有 x86-64 的。该命令在 Fedora 上是“yum install glibc-devel.i686”,在 Ubuntu 和 Debian 上是“apt-get install ia32-libs-dev”或“apt-get install libc6-dev:i386”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-24
  • 2014-07-19
  • 2015-12-20
  • 2016-03-26
  • 2016-11-15
  • 1970-01-01
  • 2010-10-22
相关资源
最近更新 更多