GOTPCREL(%rip) in GAS Intel syntax
Asked Answered
I

2

1

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?

Imperative answered 18/10, 2018 at 17:11 Comment(0)
A
1

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

Aforementioned answered 18/10, 2018 at 17:58 Comment(0)
S
0

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.

Sinking answered 18/10, 2018 at 18:2 Comment(7)
mov r8, variable@GOTPCREL[rip] - it works good. Thank you very much.Imperative
I do not recommend that form. It's only accidental that it works. The official documented version is the [rip + displacement].Aforementioned
@Aforementioned Your scaremongering unnecessary. It's standard Intel syntax. The documentation you linked isn't a complete list, but only "some examples of Intel and AT&T style memory references."Sinking
You have claimed that your form is the "expected" syntax and the other version is "also accepted". The only documentation I found states otherwise. I don't see how sticking to the documented forms is "scaremongering". While indeed the bottom part of the page is showing examples, at the very top it clearly defines how the syntax is supposed to look: section:[base + index*scale + disp]. Furthermore, disassembling produces this form as well.Aforementioned
@Aforementioned gcc.godbolt.org/z/qcevwZ Saying that this syntax only works by accident is scaremongering.Sinking
Since when is recommending to follow the documentation scaremongering? And what is saying that the undocumented one is the "expected" without proof then? Yeah, gcc producing that form pretty much guarantees it won't go away. But you only just mentioned that and it's still undocumented.Aforementioned
@Aforementioned Like your answers, the GNU Assembler documentation is half-assed and lazy. It doesn't document @GOTPCREL either, but it's no accident that it works.Sinking

© 2022 - 2024 — McMap. All rights reserved.