使用Intel语法在GNU汇编器中进行位置无关的寻址 [英] Position independent addressing in GNU assembler with Intel syntax

查看:186
本文介绍了使用Intel语法在GNU汇编器中进行位置无关的寻址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在x86-64上,当使用具有 intel语法的GNU汇编程序时,如何以与位置无关的方式(与PIC和PIE兼容)从.data节中加载地址.

On x86-64, how do I load an address from the .data section in a position independent manner (PIC and PIE compatible) when using the GNU assembler with intel syntax.

例如,使用AT& T语法,您可以这样做:

For example, using AT&T syntax, you can do this:

leaq mystring(%rip), %rdi

英特尔语法是否等效?我似乎无法使用搜索引擎找到答案...

Is there an equivalent for Intel syntax? I can't seem to find the answer using search engines...

实际上,我正在使用noprefix版本的intel语法,以防有所不同.

I am actually using the noprefix version of intel syntax, in case that makes a difference.

谢谢

推荐答案

一种简单的答案是将指令汇编成目标文件,然后以Intel语法反汇编.您可能会使用类似objdump -d -Mintel test.o的命令.

An easy way to answer this is to assemble the instruction into an object file and disassemble it in Intel syntax. You might use a command something like objdump -d -Mintel test.o.

那样做可以给我们:

Disassembly of section .text:

0000000000000000 <test>:
   0:   48 8d 3d 00 00 00 00    lea    rdi,[rip+0x0]        # 7 <test+0x7>

这应该很清楚.请注意,mystring已变成0x0:那些零是占位符字节,将在链接时使用mystring的重定位对其进行调整.在汇编源中,您将在其中使用标识符.

And that should be pretty clear. Note that mystring has turned into 0x0: those zeros are placeholder bytes which will be adjusted at link time using the relocation of mystring. In your assembly source, you would use an identifier there.

为了更加清楚,这是一个示例源文件:

to make it more clear, here is an example source file:

    .intel_syntax noprefix
    .globl test
test:
    lea rdi, [rip+mystring]

这是反汇编(来自objdump -rd -Mintel test.o).注意相对于PC的重定位:

And here is the disassembly (from objdump -rd -Mintel test.o). Note the PC-relative relocation:

0000000000000000 <test>:
   0:   48 8d 3d 00 00 00 00    lea    rdi,[rip+0x0]        # 7 <test+0x7>
                        3: R_X86_64_PC32    mystring+0xfffffffffffffffc

这篇关于使用Intel语法在GNU汇编器中进行位置无关的寻址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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