diff --git a/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp index 813875d14d0..fe8eba03edf 100644 --- a/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ b/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp @@ -229,6 +229,7 @@ private: 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; } diff --git a/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp b/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp index 533145e57ca..714f45c6e66 100644 --- a/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp +++ b/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp @@ -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; diff --git a/test/MC/ELF/got-relaxed.s b/test/MC/ELF/got-relaxed.s deleted file mode 100644 index 2ac34a8c213..00000000000 --- a/test/MC/ELF/got-relaxed.s +++ /dev/null @@ -1,21 +0,0 @@ -// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux %s -o - | llvm-readobj -r - | FileCheck %s -// RUN: llvm-mc -filetype=obj -relax-relocations=false -triple x86_64-pc-linux %s -o - | llvm-readobj -r - | FileCheck --check-prefix=OLD %s - -// these should produce R_X86_64_GOTPCRELX - - call *call@GOTPCREL(%rip) - jmp *jmp@GOTPCREL(%rip) - -// CHECK: Relocations [ -// CHECK-NEXT: Section ({{.*}}) .rela.text { -// CHECK-NEXT: R_X86_64_GOTPCRELX call -// CHECK-NEXT: R_X86_64_GOTPCRELX jmp -// CHECK-NEXT: } -// CHECK-NEXT: ] - -// OLD: Relocations [ -// OLD-NEXT: Section ({{.*}}) .rela.text { -// OLD-NEXT: R_X86_64_GOTPCREL call -// OLD-NEXT: R_X86_64_GOTPCREL jmp -// OLD-NEXT: } -// OLD-NEXT: ] diff --git a/test/MC/ELF/got.s b/test/MC/ELF/got.s index 7d8e4d059b9..ba1d6eb9798 100644 --- a/test/MC/ELF/got.s +++ b/test/MC/ELF/got.s @@ -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: ] diff --git a/test/MC/X86/gotpcrelx.s b/test/MC/X86/gotpcrelx.s new file mode 100644 index 00000000000..4afc76235b0 --- /dev/null +++ b/test/MC/X86/gotpcrelx.s @@ -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)