[all-commits] [llvm/llvm-project] 25c8fb: [X86] Don't emit R_X86_64_[REX_]GOTPCRELX for a GO...

Fangrui Song via All-commits all-commits at lists.llvm.org
Mon Nov 30 08:32:29 PST 2020


  Branch: refs/heads/temp-test-main
  Home:   https://github.com/llvm/llvm-project
  Commit: 25c8fbb3d92fd8321af59bb370e901f0e229b1c9
      https://github.com/llvm/llvm-project/commit/25c8fbb3d92fd8321af59bb370e901f0e229b1c9
  Author: Fangrui Song <i at maskray.me>
  Date:   2020-11-30 (Mon, 30 Nov 2020)

  Changed paths:
    M llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
    M llvm/test/MC/ELF/got-relaxed-rex.s
    M llvm/test/MC/X86/gotpcrelx.s

  Log Message:
  -----------
  [X86] Don't emit R_X86_64_[REX_]GOTPCRELX for a GOT load with an offset

clang may produce `movl x at GOTPCREL+4(%rip), %eax` when loading the high
32 bits of the address of a global variable in -fpic/-fpie mode.

If assembled by GNU as, the fixup emits R_X86_64_GOTPCRELX with an addend != -4.
The instruction loads from the GOT entry with an offset and thus it is incorrect
to relax the instruction.

This patch does not emit a relaxable relocation for a GOT load with an offset
because R_X86_64_[REX_]GOTPCRELX do not make sense for instructions which cannot
be relaxed.  The result is good enough for LLD to work. GNU ld relaxes
mov+GOTPCREL as well, but it suppresses the relaxation if addend != -4.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D92114




More information about the All-commits mailing list