assembly - 访问损坏的共享库

标签 assembly x86 32bit-64bit

这是cpuid2.s的代码:

#cpuid2.s view the cpuid vendor id string using c library calls
.section .data
output:
    .asciz "The processor Vendor ID is '%s'\n"

.section .bss
    .lcomm buffer, 12

.section .text
.global _start
_start:
    movl $0, %eax
    cpuid
    movl $buffer, %edi
    movl %ebx, (%edi)
    movl %edx, 4(%edi)
    movl %ecx, 8(%edi)
    push $buffer
    push $output
    call printf
    addl $8, %esp
    push $0
    call exit

我按如下方式组装、链接和运行它:
as -o cpuid2.o cpuid2.s
ld -dynamic-linker /lib/ld-linux.so.2 -o cpuid2 -lc cpuid2.o
./cpuid2
bash: ./cpuid2: Accessing a corrupted shared library

我已经在 StackOverflow 上搜索过这个错误。我找到了 this question这与我的相似。我尝试了@rasion 给出的方法。像这样:
as -32 -o cpuid2.o cpuid2.s
ld -melf_i386 -L/lib -lc -o cpuid2 cpuid2.o
ld: cannot find -lc

他的回答并没有解决我的问题。我希望有一个人可以帮助我。

我在 GNU 汇编器中使用 AT&T 语法。

我的电脑有 64 位 Ubuntu 14.04。

最佳答案

正如您已经意识到的那样,您正在尝试在 64 位机器上为 32 位机器编译程序集。使用您复制和粘贴的命令,您可以让 asld知道你正在编译 32 位的东西。

您遇到的问题是您没有可用于链接的 32 位版本的 libc。

apt-get install libc6:i386 libc6-dev-i386

然后用以下代码组装代码:
as --32 -o cpuid2.o cpuid2.s

最后将其链接到:
ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o cpuid2 -lc cpuid2.o

然后它应该工作:
[jkominek@kyatt /tmp]$ ./cpuid2 
The processor Vendor ID is 'GenuineIntel'

关于assembly - 访问损坏的共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30419857/

相关文章:

assembly - intel x86 中的 REP stosl 相当于什么

c - 将 __m256i 存储为整数

assembly - Turbo C 和内联 x86 汇编的标签问题

.net - 当生产是32位时在64位机器上开发

c - 以通用方式安全地初始化 C 中的数组

c - 在 GDB 中反汇编 C 函数。 GAS 组装说明的澄清

assembly - 为什么 Linux 上的 NASM 会更改 x86_64 程序集中的寄存器

assembly - 我的程序集冒泡排序有什么问题?

assembly - 为什么要使用ROL指令?

database - 如何在数据库中表示时间结束?