当它是更好地为汇编使用符号扩展搬迁像R_X86_64_32S而不是零扩展像R_X86_64_32的? [英] When is it better for an assembler to use sign extended relocation like R_X86_64_32S instead of zero extension like R_X86_64_32?

查看:404
本文介绍了当它是更好地为汇编使用符号扩展搬迁像R_X86_64_32S而不是零扩展像R_X86_64_32的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个具体的例子,天然气2.24,动地址:

As a concrete example, on GAS 2.24, moving the address:

mov $s, %eax
s:

as --64 -o a.o a.S
objdump -Sr a.o

使用零扩展:

0000000000000000 <s-0x5>:
   0:   b8 00 00 00 00          mov    $0x0,%eax
                        1: R_X86_64_32  .text+0x5

但内存访问:

mov s, %eax
s:

编译签署扩展:

0000000000000000 <s-0x7>:
   0:   8b 04 25 00 00 00 00    mov    0x0,%eax
                        3: R_X86_64_32S .text+0x7

有没有理由使用无论是在这种特殊情况下,还是有什么看法?我不明白汇编如何将有关情况下,任何更好的假设。

Is there a rationale to using either in this specific case, or in general? I don't understand how the assembler could to any better supposition about either case.

NASM 09年10月2日刚刚使用 R_X86_64_32 两个以上。更新:边缘NASM犯6377180 2.11产生气体的相同的输出,这似乎是一个错误罗斯后述

NASM 2.10.09 just uses R_X86_64_32 for both of the above. Update: an edge nasm commit 6377180 after 2.11 produces the same output of Gas, which seemed like a bug as Ross mentioned.

我已经解释什么,我认为我了解 R_X86_64_32S 在: HTTP: //stackoverflow.com/a/33289761/895245

I have explained what I think I understand about R_X86_64_32S at: http://stackoverflow.com/a/33289761/895245

推荐答案

所不同的是在允许的地址符号取值。与R_X86_64_32第一种情况下,符号必须在0x00000000'00000000到0x00000000'FFFFFFFF的范围内。在与R_X86_64_32S,0xFFFFFFFF'80000000和0x00000000'7FFFFFFF之间的符号必须的地址第二种情况。如果取值在这些范围之外的地址,最终则链接器会给出一个错误。

The difference is in the allowed addresses for the symbol s. In the first case with R_X86_64_32, the symbol must be in the range of 0x00000000'00000000 to 0x00000000'FFFFFFFF. In the second case with R_X86_64_32S, the address of the symbol must between 0xFFFFFFFF'80000000 and 0x00000000'7FFFFFFF. If s ends up with an address outside of these ranges then linker will give an error.

这相当于CPU如何跨$ P $点 32位值S 连接coded到两个指令。在第一指令,其中,它是一个立即操作数的32位的值是零扩展到RAX。在第二指令的32位的值是在一个存储器操作数的位移,并因此被符号扩展,以形成一个64位的地址。

This corresponds to how the CPU interprets the 32-bit value of s encoded into the two instructions. In the first instruction, where it's an immediate operand, the 32-bit value is zero extended into RAX. In the second instruction the 32-bit value is a displacement in a memory operand, and so is sign extended to form a 64-bit address.

NASM不应使用无符号R_X86_64_32搬迁为第二指令。这不是问题,其中之一就是更好,这里使用R_X86_64_32简直是不正确。 NASM将允许是0x00000000'80000000 S的地址,但CPU会结束访问0xFFFFFFFF'80000000来代替。

NASM shouldn't be using the unsigned R_X86_64_32 relocation for the second instruction. It's not question of which one is better, using R_X86_64_32 here is simply incorrect. NASM would permit the address of s to be 0x00000000'80000000, but CPU would end up accessing 0xFFFFFFFF'80000000 instead.

这篇关于当它是更好地为汇编使用符号扩展搬迁像R_X86_64_32S而不是零扩展像R_X86_64_32的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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