[all-commits] [llvm/llvm-project] 589e10: [ELF] Don't relax R_X86_64_GOTPCRELX if addend != -4

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


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

  Changed paths:
    M lld/ELF/Arch/X86_64.cpp
    A lld/test/ELF/x86-64-gotpc-offset.s

  Log Message:
  -----------
  [ELF] Don't relax R_X86_64_GOTPCRELX if addend != -4

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 an 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.

If assembled by the integrated assembler, we emit R_X86_64_GOTPCREL for
relocations that definitely cannot be relaxed (D92114), so this patch is not
needed.

This patch disables the relaxation, which is compatible with the implementation in GNU ld
("Add R_X86_64_[REX_]GOTPCRELX support to gas and ld").

Reviewed By: grimar, jhenderson

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




More information about the All-commits mailing list