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

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

问题描述

这是 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

我这样组装,链接和运行它:

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.

我正在将AT& T语法与GNU汇编程序一起使用。

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

我的计算机具有64位Ubuntu 14.04。

My computer has 64 bit Ubuntu 14.04.

推荐答案

您已经意识到,您正在尝试为32位编译程序集位机器,在64位机器上。使用复制和粘贴的命令,您可以让 as ld 知道您正在编译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天全站免登陆