![](/img/trans.png)
[英]How do RIP-relative variable references like "[RIP + _a]" in x86-64 GAS Intel-syntax work?
[英]GOTPCREL(%rip) in GAS Intel syntax
我如何編寫以下內容: movq variable@GOTPCREL(%rip), %r8
in GAS Intel 語法?
.intel_syntax noprefix
只允許這樣: mov r8, variable@GOTPCREL
,它不理解()
,結果代碼不同 - 我收到分段錯誤。 如何指定 RIP 相對尋址?
此時我必須使用以下語法切換器:
.att_syntax
movq variable@GOTPCREL(%rip), %r8
.intel_syntax noprefix
我更喜歡 Intel 語法,我的代碼主要使用它。 這個切換器在將代碼移植到 GAS 時很不方便。 是否可以用 Intel 語法快速編寫它?
這是標准的有效地址語法。 因此,您將其寫為mov r8, [variable@GOTPCREL + rip]
[rip] .當使用英特爾語法時,GAS 期望 RIP 相對尋址的語法是 [rip]
。 例如:
.att_syntax
movq variable@GOTPCREL(%rip), %r8
.intel_syntax noprefix
mov r8, variable@GOTPCREL[rip]
$ as test.s
$ objdump -d -r
a.out: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <.text>:
0: 4c 8b 05 00 00 00 00 mov 0x0(%rip),%r8 # 0x7
3: R_X86_64_REX_GOTPCRELX variable-0x4
7: 4c 8b 05 00 00 00 00 mov 0x0(%rip),%r8 # 0xe
a: R_X86_64_REX_GOTPCRELX variable-0x4
] and maybe some other forms. GAS 也將接受[rip + ]
以及其他一些形式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.