[lld] r294289 - [ELF] - Use SignExtend when reading R_386_PC8, R_386_PC16 addends.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 7 01:58:28 PST 2017
Author: grimar
Date: Tue Feb 7 03:58:27 2017
New Revision: 294289
URL: http://llvm.org/viewvc/llvm-project?rev=294289&view=rev
Log:
[ELF] - Use SignExtend when reading R_386_PC8, R_386_PC16 addends.
Previously we did not do that. For example, for R_386_PC8,
0xFF addend was not treated as 0xFFFFFFFF(-1),
but was 0x000000FF.
Recently added checks for R_386_PC8/R_386_PC16 failed because of calculation
overflow as a result.
Differential revision: https://reviews.llvm.org/D29490
Added:
lld/trunk/test/ELF/i386-pc8-pc16-addend.s
Modified:
lld/trunk/ELF/Target.cpp
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=294289&r1=294288&r2=294289&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Tue Feb 7 03:58:27 2017
@@ -491,11 +491,13 @@ int64_t X86TargetInfo::getImplicitAddend
default:
return 0;
case R_386_8:
- case R_386_PC8:
return *Buf;
+ case R_386_PC8:
+ return SignExtend64<8>(*Buf);
case R_386_16:
- case R_386_PC16:
return read16le(Buf);
+ case R_386_PC16:
+ return SignExtend64<16>(read16le(Buf));
case R_386_32:
case R_386_GOT32:
case R_386_GOT32X:
Added: lld/trunk/test/ELF/i386-pc8-pc16-addend.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/i386-pc8-pc16-addend.s?rev=294289&view=auto
==============================================================================
--- lld/trunk/test/ELF/i386-pc8-pc16-addend.s (added)
+++ lld/trunk/test/ELF/i386-pc8-pc16-addend.s Tue Feb 7 03:58:27 2017
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %s -o %t1.o
+
+# RUN: ld.lld %t1.o -o %t.out
+# RUN: llvm-objdump -s -t %t.out | FileCheck %s
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 11000 020000
+## 0x11003 - 0x11000 + addend(-1) = 0x02
+## 0x11003 - 0x11001 + addend(-2) = 0x0000
+# CHECK: SYMBOL TABLE:
+# CHECK: 00011003 .und
+
+.byte und-.-1
+.short und-.-2
+
+.section .und, "ax"
+und:
More information about the llvm-commits
mailing list