Skip to content

Commit

Permalink
[X86] Produce R_X86_64_GOTPCRELX for test/binop instructions (MOV32rm…
Browse files Browse the repository at this point in the history
…/TEST32rm/...) when -Wa,-mrelax-relocations=yes is enabled

We have been producing R_X86_64_REX_GOTPCRELX (MOV64rm/TEST64rm/...) and
R_X86_64_GOTPCRELX for CALL64m/JMP64m without the REX prefix since 2016 (to be
consistent with GNU as), but not for MOV32rm/TEST32rm/...
  • Loading branch information
MaskRay committed Oct 24, 2020
1 parent 1e09dbb commit f04d92a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 22 deletions.
1 change: 1 addition & 0 deletions llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class ELFLinkGraphBuilder_x86_64 {
case ELF::R_X86_64_64:
return ELF_x86_64_Edges::ELFX86RelocationKind::Pointer64;
case ELF::R_X86_64_GOTPCREL:
case ELF::R_X86_64_GOTPCRELX:
case ELF::R_X86_64_REX_GOTPCRELX:
return ELF_x86_64_Edges::ELFX86RelocationKind::PCRel32GOTLoad;
}
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,17 @@ void X86MCCodeEmitter::emitMemModRMByte(const MCInst &MI, unsigned Op,
switch (Opcode) {
default:
return X86::reloc_riprel_4byte;
case X86::ADC32rm:
case X86::ADD32rm:
case X86::AND32rm:
case X86::CMP32rm:
case X86::MOV32rm:
case X86::OR32rm:
case X86::SBB32rm:
case X86::SUB32rm:
case X86::TEST32mr:
case X86::XOR32rm:
return X86::reloc_riprel_4byte_relax;
case X86::MOV64rm:
assert(HasREX);
return X86::reloc_riprel_4byte_movq_load;
Expand Down
21 changes: 0 additions & 21 deletions llvm/test/MC/ELF/got-relaxed.s

This file was deleted.

2 changes: 1 addition & 1 deletion llvm/test/MC/ELF/got.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// CHECK: Relocations [
// CHECK: Section ({{[^ ]+}}) .rela.text {
// CHECK-NEXT: 0x{{[^ ]+}} R_X86_64_GOT32 foo 0x{{[^ ]+}}
// CHECK-NEXT: 0x{{[^ ]+}} R_X86_64_GOTPCREL foo 0x{{[^ ]+}}
// CHECK-NEXT: 0x{{[^ ]+}} R_X86_64_GOTPCRELX foo 0x{{[^ ]+}}
// CHECK-NEXT: }
// CHECK-NEXT: ]

Expand Down
49 changes: 49 additions & 0 deletions llvm/test/MC/X86/gotpcrelx.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s | llvm-readobj -r - | FileCheck %s
# RUN: llvm-mc -filetype=obj -triple=x86_64 -relax-relocations=false %s | llvm-readobj -r - | FileCheck --check-prefix=NORELAX %s

# CHECK: Relocations [
# CHECK-NEXT: Section ({{.*}}) .rela.text {
# CHECK-NEXT: R_X86_64_GOTPCRELX mov
# CHECK-NEXT: R_X86_64_GOTPCRELX test
# CHECK-NEXT: R_X86_64_GOTPCRELX adc
# CHECK-NEXT: R_X86_64_GOTPCRELX add
# CHECK-NEXT: R_X86_64_GOTPCRELX and
# CHECK-NEXT: R_X86_64_GOTPCRELX cmp
# CHECK-NEXT: R_X86_64_GOTPCRELX or
# CHECK-NEXT: R_X86_64_GOTPCRELX sbb
# CHECK-NEXT: R_X86_64_GOTPCRELX sub
# CHECK-NEXT: R_X86_64_GOTPCRELX xor
# CHECK-NEXT: R_X86_64_GOTPCRELX call
# CHECK-NEXT: R_X86_64_GOTPCRELX jmp
# CHECK-NEXT: }
# CHECK-NEXT: ]

# NORELAX: Relocations [
# NORELAX-NEXT: Section ({{.*}}) .rela.text {
# NORELAX-NEXT: R_X86_64_GOTPCREL mov
# NORELAX-NEXT: R_X86_64_GOTPCREL test
# NORELAX-NEXT: R_X86_64_GOTPCREL adc
# NORELAX-NEXT: R_X86_64_GOTPCREL add
# NORELAX-NEXT: R_X86_64_GOTPCREL and
# NORELAX-NEXT: R_X86_64_GOTPCREL cmp
# NORELAX-NEXT: R_X86_64_GOTPCREL or
# NORELAX-NEXT: R_X86_64_GOTPCREL sbb
# NORELAX-NEXT: R_X86_64_GOTPCREL sub
# NORELAX-NEXT: R_X86_64_GOTPCREL xor
# NORELAX-NEXT: R_X86_64_GOTPCREL call
# NORELAX-NEXT: R_X86_64_GOTPCREL jmp
# NORELAX-NEXT: }
# NORELAX-NEXT: ]

movl mov@GOTPCREL(%rip), %eax
test %eax, test@GOTPCREL(%rip)
adc adc@GOTPCREL(%rip), %eax
add add@GOTPCREL(%rip), %eax
and and@GOTPCREL(%rip), %eax
cmp cmp@GOTPCREL(%rip), %eax
or or@GOTPCREL(%rip), %eax
sbb sbb@GOTPCREL(%rip), %eax
sub sub@GOTPCREL(%rip), %eax
xor xor@GOTPCREL(%rip), %eax
call *call@GOTPCREL(%rip)
jmp *jmp@GOTPCREL(%rip)

0 comments on commit f04d92a

Please sign in to comment.