简体   繁体   中英

GOTPCREL(%rip) in GAS Intel syntax

How can i write following: movq variable@GOTPCREL(%rip), %r8 in GAS Intel syntax?

.intel_syntax noprefix allows only this: mov r8, variable@GOTPCREL , it does not understand () , and resulting code is different - i receive segmentation fault. How can i specify RIP-relative addressing?

At this moment i have to use following syntax switcher:

.att_syntax
movq variable@GOTPCREL(%rip), %r8
.intel_syntax noprefix

I prefer Intel syntax, and my code uses it mostly. This switcher is inconvenience when porting code to GAS. Is it possible to write it shortly in Intel syntax?

It's the standard effective address syntax. As such, you write it as mov r8, [variable@GOTPCREL + rip]

The syntax GAS expects for RIP relative addressing when using Intel syntax is displacement [rip] . So for example:

    .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

GAS will also accept [rip + displacement ] and maybe some other forms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM