[PATCH] D28094: [ELF] - Implemented support for R_386_PC8/R_386_8 relocations.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 24 03:27:59 PST 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.
Herald added a subscriber: emaste.

Previously we implemented R_386_PC16/R_386_16 relocations for
FreeBSD boot loaders.
I am not aware of users of PC8/8 ones, but problem is that we
just silently creating broken output now, so I guess better to have them implemented too.


https://reviews.llvm.org/D28094

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


Index: test/ELF/i386-pc8.s
===================================================================
--- test/ELF/i386-pc8.s
+++ test/ELF/i386-pc8.s
@@ -0,0 +1,17 @@
+# 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: ld.lld %t1.o %t2.o -o %t.out
+# RUN: llvm-objdump -s -section=.text %t.out | FileCheck %s
+
+# CHECK:      Contents of section .text:
+# CHECK-NEXT:  11000 15263344
+
+.text
+.global foo
+foo:
+
+.byte und-foo+0x11
+.byte und-foo+0x22
+.byte foo+0x33
+.byte foo+0x44
Index: test/ELF/Inputs/i386-pc8.s
===================================================================
--- test/ELF/Inputs/i386-pc8.s
+++ test/ELF/Inputs/i386-pc8.s
@@ -0,0 +1,2 @@
+.global und
+und:
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -364,6 +364,7 @@
     return R_TLSLD;
   case R_386_PLT32:
     return R_PLT_PC;
+  case R_386_PC8:
   case R_386_PC16:
   case R_386_PC32:
     return R_PC;
@@ -478,6 +479,9 @@
   switch (Type) {
   default:
     return 0;
+  case R_386_8:
+  case R_386_PC8:
+    return read<uint8_t, endianness::little>(Buf);
   case R_386_16:
   case R_386_PC16:
     return read16le(Buf);
@@ -497,13 +501,14 @@
                                 uint64_t Val) const {
   checkInt<32>(Loc, Val, Type);
 
-  // R_386_PC16 and R_386_16 are not part of the current i386 psABI. They are
-  // used by 16-bit x86 objects, like boot loaders.
-  if (Type == R_386_16 || Type == R_386_PC16) {
+  // R_386_*8, R_386_*16 relocations are not part of the current i386 psABI.
+  // They are used by 16-bit x86 objects, like boot loaders.
+  if (Type == R_386_8 || Type == R_386_PC8)
+    write<uint8_t, endianness::little>(Loc, Val);
+  else if (Type == R_386_16 || Type == R_386_PC16)
     write16le(Loc, Val);
-    return;
-  }
-  write32le(Loc, Val);
+  else
+    write32le(Loc, Val);
 }
 
 void X86TargetInfo::relaxTlsGdToLe(uint8_t *Loc, uint32_t Type,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28094.82439.patch
Type: text/x-patch
Size: 2066 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161224/d381a8d6/attachment.bin>


More information about the llvm-commits mailing list