[X86][MC,LLD][NFC] Rename R_X86_64_REX2_GOTPCRELX (#116737)

Rename R_X86_64_REX2_GOTPCRELX to R_X86_64_CODE_4_GOTPCRELX, to align
with GCC/binutils and ABI.

GCC/binutils:
3d5a60de52
and
4a54cb0658
ABI:
357de358ba
This commit is contained in:
Feng Zou
2024-11-20 21:02:44 +08:00
committed by GitHub
parent a160e51500
commit 1ca853b2ee
12 changed files with 30 additions and 29 deletions

View File

@@ -8,7 +8,7 @@
// RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s
// REL: R_X86_64_REX_GOTPCRELX foo
// REL: R_X86_64_REX2_GOTPCRELX foo
// REL: R_X86_64_CODE_4_GOTPCRELX foo
movq foo@GOTPCREL(%rip), %rax
movq foo@GOTPCREL(%rip), %r16

View File

@@ -394,7 +394,7 @@ RelExpr X86_64::getRelExpr(RelType type, const Symbol &s,
case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCRELX:
case R_X86_64_REX_GOTPCRELX:
case R_X86_64_REX2_GOTPCRELX:
case R_X86_64_CODE_4_GOTPCRELX:
case R_X86_64_GOTTPOFF:
return R_GOT_PC;
case R_X86_64_GOTOFF64:
@@ -738,7 +738,7 @@ int64_t X86_64::getImplicitAddend(const uint8_t *buf, RelType type) const {
case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCRELX:
case R_X86_64_REX_GOTPCRELX:
case R_X86_64_REX2_GOTPCRELX:
case R_X86_64_CODE_4_GOTPCRELX:
case R_X86_64_PC32:
case R_X86_64_GOTTPOFF:
case R_X86_64_PLT32:
@@ -821,7 +821,7 @@ void X86_64::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
break;
case R_X86_64_GOTPCRELX:
case R_X86_64_REX_GOTPCRELX:
case R_X86_64_REX2_GOTPCRELX:
case R_X86_64_CODE_4_GOTPCRELX:
if (rel.expr != R_GOT_PC) {
relaxGot(loc, rel, val);
} else {
@@ -873,13 +873,13 @@ void X86_64::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
RelExpr X86_64::adjustGotPcExpr(RelType type, int64_t addend,
const uint8_t *loc) const {
// Only R_X86_64_[REX_]|[REX2_]GOTPCRELX can be relaxed. GNU as may emit
// Only R_X86_64_[REX_]|[CODE_4_]GOTPCRELX can be relaxed. GNU as may emit
// GOTPCRELX with addend != -4. Such an instruction does not load the full GOT
// entry, so we cannot relax the relocation. E.g. movl x@GOTPCREL+4(%rip),
// %rax (addend=0) loads the high 32 bits of the GOT entry.
if (!ctx.arg.relax || addend != -4 ||
(type != R_X86_64_GOTPCRELX && type != R_X86_64_REX_GOTPCRELX &&
type != R_X86_64_REX2_GOTPCRELX))
type != R_X86_64_CODE_4_GOTPCRELX))
return R_GOT_PC;
const uint8_t op = loc[-2];
const uint8_t modRm = loc[-1];
@@ -1002,7 +1002,8 @@ static void relaxGot(uint8_t *loc, const Relocation &rel, uint64_t val) {
// We are relaxing a rip relative to an absolute, so compensate
// for the old -4 addend.
assert(!rel.sym->file || !rel.sym->file->ctx.arg.isPic);
relaxGotNoPic(loc, val + 4, op, modRm, rel.type == R_X86_64_REX2_GOTPCRELX);
relaxGotNoPic(loc, val + 4, op, modRm,
rel.type == R_X86_64_CODE_4_GOTPCRELX);
return;
}

View File

@@ -13,7 +13,7 @@
# CHECK-NEXT: error: {{.*}}:(.text+0x9): relocation R_X86_64_REX_GOTPCRELX out of range: 2147483659 is not in [-2147483648, 2147483647]; references '__stop_data'
# CHECK-NEXT: >>> defined in <internal>
# CHECK-EMPTY:
# CHECK-NEXT: error: {{.*}}:(.text+0x11): relocation R_X86_64_REX2_GOTPCRELX out of range: 2147483651 is not in [-2147483648, 2147483647]; references '__stop_data'
# CHECK-NEXT: error: {{.*}}:(.text+0x11): relocation R_X86_64_CODE_4_GOTPCRELX out of range: 2147483651 is not in [-2147483648, 2147483647]; references '__stop_data'
# CHECK-NEXT: >>> defined in <internal>
#--- a.s

View File

@@ -134,7 +134,7 @@ _start:
xorq bar@GOTPCREL(%rip), %r8
testq %r15, bar@GOTPCREL(%rip)
## R_X86_64_REX2_GOTPCRELX
## R_X86_64_CODE_4_GOTPCRELX
adcq bar@GOTPCREL(%rip), %r16
addq bar@GOTPCREL(%rip), %r17
andq bar@GOTPCREL(%rip), %r18

View File

@@ -1,5 +1,5 @@
# REQUIRES: x86
## Test R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX/R_X86_64_REX2_GOTPCRELX GOT optimization.
## Test R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX/R_X86_64_CODE_4_GOTPCRELX GOT optimization.
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -o %t1 --no-apply-dynamic-relocs

View File

@@ -43,4 +43,4 @@ ELF_RELOC(R_X86_64_TLSDESC, 36)
ELF_RELOC(R_X86_64_IRELATIVE, 37)
ELF_RELOC(R_X86_64_GOTPCRELX, 41)
ELF_RELOC(R_X86_64_REX_GOTPCRELX, 42)
ELF_RELOC(R_X86_64_REX2_GOTPCRELX, 43)
ELF_RELOC(R_X86_64_CODE_4_GOTPCRELX, 43)

View File

@@ -145,7 +145,7 @@ llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
static cl::opt<bool> X86RelaxRelocations(
"x86-relax-relocations",
cl::desc("Emit GOTPCRELX/REX_GOTPCRELX/REX2_GOTPCRELX instead of "
cl::desc("Emit GOTPCRELX/REX_GOTPCRELX/CODE_4_GOTPCRELX instead of "
"GOTPCREL on x86-64 ELF"),
cl::init(true));
MCBINDOPT(X86RelaxRelocations);

View File

@@ -207,7 +207,7 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
case MCSymbolRefExpr::VK_GOTPCREL:
checkIs32(Ctx, Loc, Type);
// Older versions of ld.bfd/ld.gold/lld
// do not support GOTPCRELX/REX_GOTPCRELX/REX2_GOTPCRELX,
// do not support GOTPCRELX/REX_GOTPCRELX/CODE_4_GOTPCRELX,
// and we want to keep back-compatibility.
if (!Ctx.getTargetOptions()->X86RelaxRelocations)
return ELF::R_X86_64_GOTPCREL;
@@ -221,7 +221,7 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
return ELF::R_X86_64_REX_GOTPCRELX;
case X86::reloc_riprel_4byte_relax_rex2:
case X86::reloc_riprel_4byte_movq_load_rex2:
return ELF::R_X86_64_REX2_GOTPCRELX;
return ELF::R_X86_64_CODE_4_GOTPCRELX;
}
llvm_unreachable("unexpected relocation type!");
case MCSymbolRefExpr::VK_GOTPCREL_NORELAX:

View File

@@ -641,7 +641,7 @@ void X86MCCodeEmitter::emitMemModRMByte(
case X86::MOV64rm:
// movq loads is a subset of reloc_riprel_4byte_relax_rex/rex2. It is a
// special case because COFF and Mach-O don't support ELF's more
// flexible R_X86_64_REX_GOTPCRELX/R_X86_64_REX2_GOTPCRELX relaxation.
// flexible R_X86_64_REX_GOTPCRELX/R_X86_64_CODE_4_GOTPCRELX relaxation.
return Kind == REX2 ? X86::reloc_riprel_4byte_movq_load_rex2
: X86::reloc_riprel_4byte_movq_load;
case X86::ADC32rm:

View File

@@ -17,7 +17,7 @@ movabsq $memcpy+2, %rax
# CHECK: movq (%rip), %rax
# CHECK-NEXT: R_X86_64_REX_GOTPCRELX abs-0x4
# CHECK: movq (%rip), %r16
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX abs-0x4
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX abs-0x4
movq abs@GOTPCREL(%rip), %rax
movq abs@GOTPCREL(%rip), %r16
abs = 42

View File

@@ -37,16 +37,16 @@
# CHECK-NEXT: R_X86_64_REX_GOTPCRELX sbb
# CHECK-NEXT: R_X86_64_REX_GOTPCRELX sub
# CHECK-NEXT: R_X86_64_REX_GOTPCRELX xor
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX mov
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX test
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX adc
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX add
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX and
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX cmp
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX or
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX sbb
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX sub
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX xor
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX mov
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX test
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX adc
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX add
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX and
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX cmp
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX or
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX sbb
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX sub
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX xor
# CHECK-NEXT: }
# NORELAX-NEXT: R_X86_64_GOTPCREL mov

View File

@@ -9,7 +9,7 @@
# PRINT-NEXT: .reloc 0, R_X86_64_64, .data+2
# PRINT-NEXT: .reloc 0, R_X86_64_GOTPCRELX, foo+3
# PRINT-NEXT: .reloc 0, R_X86_64_REX_GOTPCRELX, 5
# PRINT-NEXT: .reloc 0, R_X86_64_REX2_GOTPCRELX, 7
# PRINT-NEXT: .reloc 0, R_X86_64_CODE_4_GOTPCRELX, 7
# PRINT: .reloc 0, BFD_RELOC_NONE, 9
# PRINT-NEXT: .reloc 0, BFD_RELOC_8, 9
# PRINT-NEXT: .reloc 0, BFD_RELOC_16, 9
@@ -22,7 +22,7 @@
# CHECK-NEXT: 0x0 R_X86_64_64 .data 0x2
# CHECK-NEXT: 0x0 R_X86_64_GOTPCRELX foo 0x3
# CHECK-NEXT: 0x0 R_X86_64_REX_GOTPCRELX - 0x5
# CHECK-NEXT: 0x0 R_X86_64_REX2_GOTPCRELX - 0x7
# CHECK-NEXT: 0x0 R_X86_64_CODE_4_GOTPCRELX - 0x7
# CHECK-NEXT: 0x0 R_X86_64_NONE - 0x9
# CHECK-NEXT: 0x0 R_X86_64_8 - 0x9
# CHECK-NEXT: 0x0 R_X86_64_16 - 0x9
@@ -39,7 +39,7 @@
.reloc 0, R_X86_64_64, .data+2
.reloc 0, R_X86_64_GOTPCRELX, foo+3
.reloc 0, R_X86_64_REX_GOTPCRELX, 5
.reloc 0, R_X86_64_REX2_GOTPCRELX, 7
.reloc 0, R_X86_64_CODE_4_GOTPCRELX, 7
.reloc 0, BFD_RELOC_NONE, 9
.reloc 0, BFD_RELOC_8, 9