[lld] r353437 - Fix a bug in R_X86_64_PC{8,16} relocation handling.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 7 10:12:57 PST 2019
Author: ruiu
Date: Thu Feb 7 10:12:57 2019
New Revision: 353437
URL: http://llvm.org/viewvc/llvm-project?rev=353437&view=rev
Log:
Fix a bug in R_X86_64_PC{8,16} relocation handling.
R_X86_64_PC{8,16} relocations are sign-extended, so when we check
for relocation overflow, we had to use checkInt instead of checkUInt.
I confirmed that GNU linkers create the same output for the test case.
Added:
lld/trunk/test/ELF/Inputs/x86-64-pcrel.s
Modified:
lld/trunk/ELF/Arch/X86_64.cpp
lld/trunk/test/ELF/x86-64-pcrel.s
Modified: lld/trunk/ELF/Arch/X86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86_64.cpp?rev=353437&r1=353436&r2=353437&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86_64.cpp (original)
+++ lld/trunk/ELF/Arch/X86_64.cpp Thu Feb 7 10:12:57 2019
@@ -324,15 +324,21 @@ template <class ELFT>
void X86_64<ELFT>::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
switch (Type) {
case R_X86_64_8:
- case R_X86_64_PC8:
checkUInt(Loc, Val, 8, Type);
*Loc = Val;
break;
+ case R_X86_64_PC8:
+ checkInt(Loc, Val, 8, Type);
+ *Loc = Val;
+ break;
case R_X86_64_16:
- case R_X86_64_PC16:
checkUInt(Loc, Val, 16, Type);
write16le(Loc, Val);
break;
+ case R_X86_64_PC16:
+ checkInt(Loc, Val, 16, Type);
+ write16le(Loc, Val);
+ break;
case R_X86_64_32:
checkUInt(Loc, Val, 32, Type);
write32le(Loc, Val);
Added: lld/trunk/test/ELF/Inputs/x86-64-pcrel.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/x86-64-pcrel.s?rev=353437&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/x86-64-pcrel.s (added)
+++ lld/trunk/test/ELF/Inputs/x86-64-pcrel.s Thu Feb 7 10:12:57 2019
@@ -0,0 +1,8 @@
+.globl foo
+foo:
+
+.word _start - foo
+.fill 14,1,0xcc
+
+.byte _start - foo
+.fill 15,1,0xcc
Modified: lld/trunk/test/ELF/x86-64-pcrel.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-pcrel.s?rev=353437&r1=353436&r2=353437&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-pcrel.s (original)
+++ lld/trunk/test/ELF/x86-64-pcrel.s Thu Feb 7 10:12:57 2019
@@ -3,13 +3,15 @@
// This is a test for R_X86_64_PC8 and R_X86_64_PC16.
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
-// RUN: echo '.globl foo; foo:' | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t2.o
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/x86-64-pcrel.s -o %t2.o
// RUN: ld.lld -o %t.exe %t1.o %t2.o
// RUN: llvm-objdump -s %t.exe | FileCheck %s
-// CHECK: Contents of section .text:
-// CHECK: 2000cccc cccccccc cccccccc cccccccc
-// CHECK: 20cccccc cccccccc cccccccc cccccccc
+// CHECK: Contents of section .text:
+// CHECK-NEXT: 2000cccc cccccccc cccccccc cccccccc
+// CHECK-NEXT: 20cccccc cccccccc cccccccc cccccccc
+// CHECK-NEXT: e0ffcccc cccccccc cccccccc cccccccc
+// CHECK-NEXT: e0cccccc cccccccc cccccccc cccccccc
.globl _start
_start:
More information about the llvm-commits
mailing list