https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106834

--- Comment #10 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
Okay, so this should have been reported against Binutils, but since we are
having the conversation here: the current behavior is not good, gas is silently
selecting a different relocation kind for no clear reason. Why is it not a
warning or an error? Note that if you assemble such GOT reference via NASM:

extern _GLOBAL_OFFSET_TABLE_
default rel
f:
        mov     rax, [_GLOBAL_OFFSET_TABLE_ wrt ..gotpc]
        ret

then t.o has

0000000000000000 <f>:
   0:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 7 <f+0x7>
                        3: R_X86_64_GOTPCREL    _GLOBAL_OFFSET_TABLE_-0x4
   7:   c3                      ret

and ld -shared --no-relax -o t.so t.o does not reject it and t.so has

0000000000001000 <f>:
    1000:       48 8b 05 f1 1f 00 00    mov    0x1ff1(%rip),%rax        # 2ff8
<_DYNAMIC+0xe0>
    1007:       c3                      ret

and without --no-relax:

0000000000001000 <f>:
    1000:       48 8d 05 f9 1f 00 00    lea    0x1ff9(%rip),%rax        # 3000
<_GLOBAL_OFFSET_TABLE_>
    1007:       c3                      ret

So I don't see the reason why it's special-cased in gas.

Reply via email to