[PATCH] D29493: [ELF] - Use SignExtend when reading R_386_PC16 addend.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 3 08:52:20 PST 2017
grimar updated this revision to Diff 86973.
grimar added a comment.
Simplified testcase.
https://reviews.llvm.org/D29493
Files:
ELF/Target.cpp
test/ELF/i386-pc16-addend.s
Index: test/ELF/i386-pc16-addend.s
===================================================================
--- test/ELF/i386-pc16-addend.s
+++ test/ELF/i386-pc16-addend.s
@@ -0,0 +1,24 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %S/Inputs/i386-pc8.s -o %t2.o
+# RUN: llvm-objdump -d %t1.o | FileCheck %s --check-prefix=OBJDISASM
+
+## Show that we have relocation with addend = 0xFFFE(-2),
+## we do sign extend for its value in the code.
+# OBJDISASM: Disassembly of section .text:
+# OBJDISASM-NEXT: .text:
+# OBJDISASM-NEXT: 0: fe ff
+
+# RUN: ld.lld %t1.o %t2.o -o %t.out
+# RUN: llvm-objdump -d %t.out | FileCheck %s --check-prefix=DISASM
+# RUN: llvm-readobj -symbols %t.out | FileCheck %s --check-prefix=SYM
+# DISASM: Disassembly of section .text:
+# DISASM-NEXT: .text:
+# DISASM-NEXT: 11000: 02 00
+## 0x11004 - 0x11000 + addend = 0x2
+# SYM: Symbol {
+# SYM: Name: und
+# SYM-NEXT: Value: 0x11004
+
+.code16
+.word und-.-2
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -495,8 +495,9 @@
case R_386_PC8:
return *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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29493.86973.patch
Type: text/x-patch
Size: 1432 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170203/dc24d168/attachment.bin>
More information about the llvm-commits
mailing list