汇编 bash: ./cpuid: Accessing a corrupted shared library

这个问题的主要原因是:

原因

 操作系统:Ubuntu 14 操作系统和 cpu是64位的
 as -o cpuid2 cpuid2.s
 ld  -dynamic-linker /lib/ld-linux.so.2 -o cpuid2 -lc cpuid2.o
 :output
 bash: ./cpuid: Accessing a corrupted shared library
 我们按照书上的代码,是基于32cpu 的,但是现在的大多数64CPU和操作系统,我们需要修改一下命令生成32位的目标文件 链接生成32位的可执行文件,问题是我们现在生成和链接的是64的,但是cpuid2.s 命令确实32位的指令,不是64位的,所以俩种解决办法:1.生成32位的文件 2. 32位指令换成64位指令。

cpuid2.s 内容

cpuid2.s 内容:

#cpuid2.s Sample program to extract the processor Vender ID
.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
add $8, %esp
push $0
call exit

解决方法

方法一

as --32 -o cpuid2.o  cpuid2.s
ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o cpuid2 -lc cpuid2.o

方法二

修改指令位64位的,我不会

猜你喜欢

转载自blog.csdn.net/li740207611/article/details/53966612