Skip to content

Commit 1ca853b

Browse files
authored
[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: bminor/binutils-gdb@3d5a60d and bminor/binutils-gdb@4a54cb0 ABI: https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/357de358ba68eb779822dfcbb45f7ee2d9d09193
1 parent a160e51 commit 1ca853b

File tree

12 files changed

+30
-29
lines changed

12 files changed

+30
-29
lines changed

clang/test/Driver/relax.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s
99

1010
// REL: R_X86_64_REX_GOTPCRELX foo
11-
// REL: R_X86_64_REX2_GOTPCRELX foo
11+
// REL: R_X86_64_CODE_4_GOTPCRELX foo
1212

1313
movq foo@GOTPCREL(%rip), %rax
1414
movq foo@GOTPCREL(%rip), %r16

lld/ELF/Arch/X86_64.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ RelExpr X86_64::getRelExpr(RelType type, const Symbol &s,
394394
case R_X86_64_GOTPCREL:
395395
case R_X86_64_GOTPCRELX:
396396
case R_X86_64_REX_GOTPCRELX:
397-
case R_X86_64_REX2_GOTPCRELX:
397+
case R_X86_64_CODE_4_GOTPCRELX:
398398
case R_X86_64_GOTTPOFF:
399399
return R_GOT_PC;
400400
case R_X86_64_GOTOFF64:
@@ -738,7 +738,7 @@ int64_t X86_64::getImplicitAddend(const uint8_t *buf, RelType type) const {
738738
case R_X86_64_GOTPCREL:
739739
case R_X86_64_GOTPCRELX:
740740
case R_X86_64_REX_GOTPCRELX:
741-
case R_X86_64_REX2_GOTPCRELX:
741+
case R_X86_64_CODE_4_GOTPCRELX:
742742
case R_X86_64_PC32:
743743
case R_X86_64_GOTTPOFF:
744744
case R_X86_64_PLT32:
@@ -821,7 +821,7 @@ void X86_64::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
821821
break;
822822
case R_X86_64_GOTPCRELX:
823823
case R_X86_64_REX_GOTPCRELX:
824-
case R_X86_64_REX2_GOTPCRELX:
824+
case R_X86_64_CODE_4_GOTPCRELX:
825825
if (rel.expr != R_GOT_PC) {
826826
relaxGot(loc, rel, val);
827827
} else {
@@ -873,13 +873,13 @@ void X86_64::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
873873

874874
RelExpr X86_64::adjustGotPcExpr(RelType type, int64_t addend,
875875
const uint8_t *loc) const {
876-
// Only R_X86_64_[REX_]|[REX2_]GOTPCRELX can be relaxed. GNU as may emit
876+
// Only R_X86_64_[REX_]|[CODE_4_]GOTPCRELX can be relaxed. GNU as may emit
877877
// GOTPCRELX with addend != -4. Such an instruction does not load the full GOT
878878
// entry, so we cannot relax the relocation. E.g. movl x@GOTPCREL+4(%rip),
879879
// %rax (addend=0) loads the high 32 bits of the GOT entry.
880880
if (!ctx.arg.relax || addend != -4 ||
881881
(type != R_X86_64_GOTPCRELX && type != R_X86_64_REX_GOTPCRELX &&
882-
type != R_X86_64_REX2_GOTPCRELX))
882+
type != R_X86_64_CODE_4_GOTPCRELX))
883883
return R_GOT_PC;
884884
const uint8_t op = loc[-2];
885885
const uint8_t modRm = loc[-1];
@@ -1002,7 +1002,8 @@ static void relaxGot(uint8_t *loc, const Relocation &rel, uint64_t val) {
10021002
// We are relaxing a rip relative to an absolute, so compensate
10031003
// for the old -4 addend.
10041004
assert(!rel.sym->file || !rel.sym->file->ctx.arg.isPic);
1005-
relaxGotNoPic(loc, val + 4, op, modRm, rel.type == R_X86_64_REX2_GOTPCRELX);
1005+
relaxGotNoPic(loc, val + 4, op, modRm,
1006+
rel.type == R_X86_64_CODE_4_GOTPCRELX);
10061007
return;
10071008
}
10081009

lld/test/ELF/x86-64-gotpc-no-relax-err.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# CHECK-NEXT: error: {{.*}}:(.text+0x9): relocation R_X86_64_REX_GOTPCRELX out of range: 2147483659 is not in [-2147483648, 2147483647]; references '__stop_data'
1414
# CHECK-NEXT: >>> defined in <internal>
1515
# CHECK-EMPTY:
16-
# CHECK-NEXT: error: {{.*}}:(.text+0x11): relocation R_X86_64_REX2_GOTPCRELX out of range: 2147483651 is not in [-2147483648, 2147483647]; references '__stop_data'
16+
# CHECK-NEXT: error: {{.*}}:(.text+0x11): relocation R_X86_64_CODE_4_GOTPCRELX out of range: 2147483651 is not in [-2147483648, 2147483647]; references '__stop_data'
1717
# CHECK-NEXT: >>> defined in <internal>
1818

1919
#--- a.s

lld/test/ELF/x86-64-gotpc-relax-nopic.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ _start:
134134
xorq bar@GOTPCREL(%rip), %r8
135135
testq %r15, bar@GOTPCREL(%rip)
136136

137-
## R_X86_64_REX2_GOTPCRELX
137+
## R_X86_64_CODE_4_GOTPCRELX
138138
adcq bar@GOTPCREL(%rip), %r16
139139
addq bar@GOTPCREL(%rip), %r17
140140
andq bar@GOTPCREL(%rip), %r18

lld/test/ELF/x86-64-gotpc-relax.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# REQUIRES: x86
2-
## Test R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX/R_X86_64_REX2_GOTPCRELX GOT optimization.
2+
## Test R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX/R_X86_64_CODE_4_GOTPCRELX GOT optimization.
33

44
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
55
# RUN: ld.lld %t.o -o %t1 --no-apply-dynamic-relocs

llvm/include/llvm/BinaryFormat/ELFRelocs/x86_64.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ ELF_RELOC(R_X86_64_TLSDESC, 36)
4343
ELF_RELOC(R_X86_64_IRELATIVE, 37)
4444
ELF_RELOC(R_X86_64_GOTPCRELX, 41)
4545
ELF_RELOC(R_X86_64_REX_GOTPCRELX, 42)
46-
ELF_RELOC(R_X86_64_REX2_GOTPCRELX, 43)
46+
ELF_RELOC(R_X86_64_CODE_4_GOTPCRELX, 43)

llvm/lib/MC/MCTargetOptionsCommandFlags.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
145145

146146
static cl::opt<bool> X86RelaxRelocations(
147147
"x86-relax-relocations",
148-
cl::desc("Emit GOTPCRELX/REX_GOTPCRELX/REX2_GOTPCRELX instead of "
148+
cl::desc("Emit GOTPCRELX/REX_GOTPCRELX/CODE_4_GOTPCRELX instead of "
149149
"GOTPCREL on x86-64 ELF"),
150150
cl::init(true));
151151
MCBINDOPT(X86RelaxRelocations);

llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
207207
case MCSymbolRefExpr::VK_GOTPCREL:
208208
checkIs32(Ctx, Loc, Type);
209209
// Older versions of ld.bfd/ld.gold/lld
210-
// do not support GOTPCRELX/REX_GOTPCRELX/REX2_GOTPCRELX,
210+
// do not support GOTPCRELX/REX_GOTPCRELX/CODE_4_GOTPCRELX,
211211
// and we want to keep back-compatibility.
212212
if (!Ctx.getTargetOptions()->X86RelaxRelocations)
213213
return ELF::R_X86_64_GOTPCREL;
@@ -221,7 +221,7 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
221221
return ELF::R_X86_64_REX_GOTPCRELX;
222222
case X86::reloc_riprel_4byte_relax_rex2:
223223
case X86::reloc_riprel_4byte_movq_load_rex2:
224-
return ELF::R_X86_64_REX2_GOTPCRELX;
224+
return ELF::R_X86_64_CODE_4_GOTPCRELX;
225225
}
226226
llvm_unreachable("unexpected relocation type!");
227227
case MCSymbolRefExpr::VK_GOTPCREL_NORELAX:

llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ void X86MCCodeEmitter::emitMemModRMByte(
641641
case X86::MOV64rm:
642642
// movq loads is a subset of reloc_riprel_4byte_relax_rex/rex2. It is a
643643
// special case because COFF and Mach-O don't support ELF's more
644-
// flexible R_X86_64_REX_GOTPCRELX/R_X86_64_REX2_GOTPCRELX relaxation.
644+
// flexible R_X86_64_REX_GOTPCRELX/R_X86_64_CODE_4_GOTPCRELX relaxation.
645645
return Kind == REX2 ? X86::reloc_riprel_4byte_movq_load_rex2
646646
: X86::reloc_riprel_4byte_movq_load;
647647
case X86::ADC32rm:

llvm/test/MC/ELF/relocation-alias.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ movabsq $memcpy+2, %rax
1717
# CHECK: movq (%rip), %rax
1818
# CHECK-NEXT: R_X86_64_REX_GOTPCRELX abs-0x4
1919
# CHECK: movq (%rip), %r16
20-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX abs-0x4
20+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX abs-0x4
2121
movq abs@GOTPCREL(%rip), %rax
2222
movq abs@GOTPCREL(%rip), %r16
2323
abs = 42

llvm/test/MC/X86/gotpcrelx.s

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@
3737
# CHECK-NEXT: R_X86_64_REX_GOTPCRELX sbb
3838
# CHECK-NEXT: R_X86_64_REX_GOTPCRELX sub
3939
# CHECK-NEXT: R_X86_64_REX_GOTPCRELX xor
40-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX mov
41-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX test
42-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX adc
43-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX add
44-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX and
45-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX cmp
46-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX or
47-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX sbb
48-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX sub
49-
# CHECK-NEXT: R_X86_64_REX2_GOTPCRELX xor
40+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX mov
41+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX test
42+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX adc
43+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX add
44+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX and
45+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX cmp
46+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX or
47+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX sbb
48+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX sub
49+
# CHECK-NEXT: R_X86_64_CODE_4_GOTPCRELX xor
5050
# CHECK-NEXT: }
5151

5252
# NORELAX-NEXT: R_X86_64_GOTPCREL mov

llvm/test/MC/X86/reloc-directive-elf-64.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# PRINT-NEXT: .reloc 0, R_X86_64_64, .data+2
1010
# PRINT-NEXT: .reloc 0, R_X86_64_GOTPCRELX, foo+3
1111
# PRINT-NEXT: .reloc 0, R_X86_64_REX_GOTPCRELX, 5
12-
# PRINT-NEXT: .reloc 0, R_X86_64_REX2_GOTPCRELX, 7
12+
# PRINT-NEXT: .reloc 0, R_X86_64_CODE_4_GOTPCRELX, 7
1313
# PRINT: .reloc 0, BFD_RELOC_NONE, 9
1414
# PRINT-NEXT: .reloc 0, BFD_RELOC_8, 9
1515
# PRINT-NEXT: .reloc 0, BFD_RELOC_16, 9
@@ -22,7 +22,7 @@
2222
# CHECK-NEXT: 0x0 R_X86_64_64 .data 0x2
2323
# CHECK-NEXT: 0x0 R_X86_64_GOTPCRELX foo 0x3
2424
# CHECK-NEXT: 0x0 R_X86_64_REX_GOTPCRELX - 0x5
25-
# CHECK-NEXT: 0x0 R_X86_64_REX2_GOTPCRELX - 0x7
25+
# CHECK-NEXT: 0x0 R_X86_64_CODE_4_GOTPCRELX - 0x7
2626
# CHECK-NEXT: 0x0 R_X86_64_NONE - 0x9
2727
# CHECK-NEXT: 0x0 R_X86_64_8 - 0x9
2828
# CHECK-NEXT: 0x0 R_X86_64_16 - 0x9
@@ -39,7 +39,7 @@
3939
.reloc 0, R_X86_64_64, .data+2
4040
.reloc 0, R_X86_64_GOTPCRELX, foo+3
4141
.reloc 0, R_X86_64_REX_GOTPCRELX, 5
42-
.reloc 0, R_X86_64_REX2_GOTPCRELX, 7
42+
.reloc 0, R_X86_64_CODE_4_GOTPCRELX, 7
4343

4444
.reloc 0, BFD_RELOC_NONE, 9
4545
.reloc 0, BFD_RELOC_8, 9

0 commit comments

Comments
 (0)