访问损坏的共享库 [英] Accessing a corrupted shared library

查看:21
本文介绍了访问损坏的共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是cpuid2.s的代码:

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

.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

我是这样组装、链接和运行它的:

I assemble, link, and run it as so:

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 上搜索过这个错误.我发现 这个问题 与我的相似.我尝试了@rasion 给出的方法.像这样:

I've searched StackOverflow for this error. I found this question which is similar to mine. And I tried the method given by @rasion. Like this:

as -32 -o cpuid2.o cpuid2.s
ld -melf_i386 -L/lib -lc -o cpuid2 cpuid2.o
ld: cannot find -lc

他的回答并没有解决我的问题.我希望有人能帮助我.

His answer doesn't solve my problem. I hope someone can help me.

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

I'm using AT&T syntax with GNU assembler.

我的电脑有 64 位 Ubuntu 14.04.

My computer has 64 bit Ubuntu 14.04.

推荐答案

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

As you've sort of realized, you're trying to compile assembly for a 32 bit machine, on a 64 bit machine. With the commands you copied and pasted, you're letting as and ld know that you're compiling something 32 bit.

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

The issue you've run into is that you don't have a 32 bit version of libc available to link against.

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'

这篇关于访问损坏的共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆