[PATCH] D29490: [ELF] - Use SignExtend when reading R_386_PC8, R_386_PC16 addends.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 6 02:07:00 PST 2017


grimar updated this revision to Diff 87201.
grimar retitled this revision from "[ELF] - Use SignExtend when reading R_386_PC8 addend." to "[ELF] - Use SignExtend when reading R_386_PC8, R_386_PC16 addends.".
grimar edited the summary of this revision.
grimar added a comment.

- Merged with https://reviews.llvm.org/D29493 (R_386_PC16 part)
- Addressed review comments.


https://reviews.llvm.org/D29490

Files:
  ELF/Target.cpp
  test/ELF/i386-pc8-pc16-addend.s


Index: test/ELF/i386-pc8-pc16-addend.s
===================================================================
--- test/ELF/i386-pc8-pc16-addend.s
+++ test/ELF/i386-pc8-pc16-addend.s
@@ -0,0 +1,32 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %s -o %t1.o
+# RUN: llvm-objdump -d %t1.o | FileCheck %s --check-prefix=OBJDISASM
+
+## Show that we have R_386_PC8 relocation with addend = 0xFF(-1),
+## and R_386_PC16 relocation with addend = 0xFEFF(-2)
+## we do sign extend for addends values in the code.
+# OBJDISASM:      Disassembly of section .text:
+# OBJDISASM-NEXT: .text:
+# OBJDISASM-NEXT:  0: ff fe
+# OBJDISASM-NEXT:  2: ff
+
+## Check that there is no link error and relocation applied correctly.
+# RUN: ld.lld %t1.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
+# DISASM-NEXT:   11002: 00
+## 0x11003 - 0x11000 + addend(-1) = 0x02
+## 0x11003 - 0x11001 + addend(-2) = 0x0000
+# SYM:     Symbol {
+# SYM:       Name: und
+# SYM-NEXT:  Value: 0x11003
+
+.code16
+.byte und-.-1
+.word und-.-2
+
+.section .und, "ax"
+und:
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -492,11 +492,13 @@
   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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29490.87201.patch
Type: text/x-patch
Size: 1737 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170206/f0b2379f/attachment.bin>


More information about the llvm-commits mailing list