GNU汇编器:访问损坏的共享库错误 [英] GNU assembler: Accessing a corrupted shared library error

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

问题描述

我正在读《专业汇编语言》这本书.
我想使用动态链接.
我在GNU汇编器中使用AT& T语法.
我的计算机具有Ubuntu 12.04(在64位系统中).
我正在尝试使用cpuid汇编程序操作码和
显示供应商ID字符串 printf C函数而不是linux系统调用.

I'm reading the book: "Professional assembly language".
I want to use dynamic linking.
I'm using AT&T syntax with GNU assembler.
My computer has Ubuntu 12.04 (in a 64 bit system).
I'm trying to display the vendor ID string using the cpuid assembler opcode and
printf C function instead of linux system calls.

hello.s

 .code32
   .section .data
 output:
   .asciz "The processor Vendor ID is '%s'\n"

 .section .bss
   .lcomm buffer, 12

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

我执行了以下命令:

> $ as -o hello.o hello.s
> $ ld -dynamic-linker /lib/ld-linux.so.2 -o hello -lc hello.o
> $ ./hello
  bash: ./hello: Accessing a corrupted shared library

但是我收到了上面显示的错误消息,关于一个损坏的共享库的东西(这是我要解决的错误)
我不太在乎代码(因为我了解它)
我只想学习如何使用汇编代码和GAS使用动态链接.
因此,如果您有任何汇编代码 使用动态链接的应用程序,如果可以向我展示所使用的"as"和"ld"命令,我将不胜感激.

But I'm getting the error message shown above, something about a corrupted shared library (that's the error that I want to solve)
I don't care too much about the code (because I understand it)
I just want to learn how to use dynamic linking using assembly code and GAS.
So if you have any assembly code that uses dynamic linking I appreciate if you can show me the "as" and "ld" commands that you use.

PS:如果有人想了解代码是什么:
CPUID指令使用单个寄存器值作为输入.
EAX寄存器用于确定什么 信息由CPUID指令产生.
根据EAX寄存器的值,CPUID 该指令将在EBX,ECX和EDX寄存器中产生有关处理器的不同信息.
信息以一系列位值和标志的形式返回,必须将其解释为正确的含义

PS: In case somebody wants to understand what does the code:
The CPUID instruction uses a single register value as input .
The EAX register is used to determine what information is produced by the CPUID instruction.
Depending on the value of the EAX register, the CPUID instruction will produce different information about the processor in the EBX, ECX, and EDX registers.
The information is returned as a series of bit values and flags, which must be interpreted to their proper meaning

此代码利用零选项(移动$ 0,%eax)检索简单的供应商ID 处理器中的字符串.当零值放在EAX寄存器中时,CPUID指令 执行后,处理器将在EBX,EDX和ECX寄存器中返回供应商ID字符串,如下所示:

❑EBX包含字符串的低4个字节.
❑EDX包含字符串的中间4个字节.
❑ECX包含字符串的最后4个字节.

字符串值以Little-Endian格式放置在寄存器中.
该代码使用标准的C库函数:printf和exit而不是linux系统调用.

This code utilizes the zero option (movl $0, %eax) to retrieve the simple Vendor ID string from the processor. When the value of zero is placed in the EAX register, and the CPUID instruction is executed, the processor returns the Vendor ID string in the EBX, EDX , and ECX registers as follows:

❑ EBX contains the low 4 bytes of the string.
❑ EDX contains the middle 4 bytes of the string.
❑ ECX contains the last 4 bytes of the string.

The string values are placed in the registers in little-endian format;
This code uses the standard C library functions: printf and exit instead of linux system calls.

推荐答案

我尝试如下操作,并且有效:

I tried it as below, and it works:

as -32 -o hello.o hello.s
ld -melf_i386 -L/lib -lc -o hello hello.o

顺便说一句,在我的机器上,它抱怨缺少/usr/lib/libc.so.1,在我将符号/usr/lib/libc.so.1链接到/lib/ld-linux.so.2之后,它可以工作.
在64位Linux上创建32位ELF,我们需要glibc.i686 glibc.i386已安装.

BTW, on my machine, it complains about missing /usr/lib/libc.so.1 , after I made a symbol link /usr/lib/libc.so.1 to /lib/ld-linux.so.2, it works.
create 32bit ELF on 64bit Linux, we need glibc.i686 or glibc.i386 installed.

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

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