[PATCH] D27303: [ELF] - Implemented R_386_16 and R_386PC16 relocations

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 2 23:40:45 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL288581: [ELF] - Implemented R_386_16 and R_386PC16 relocations (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D27303?vs=80051&id=80173#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27303

Files:
  lld/trunk/ELF/Target.cpp
  lld/trunk/test/ELF/i386-pc16.test


Index: lld/trunk/test/ELF/i386-pc16.test
===================================================================
--- lld/trunk/test/ELF/i386-pc16.test
+++ lld/trunk/test/ELF/i386-pc16.test
@@ -0,0 +1,40 @@
+# REQUIRES: x86
+
+# RUN: yaml2obj %s -o %t.o
+# RUN: ld.lld %t.o -o %t.exe
+# RUN: llvm-objdump -s -section=.text %t.exe 2>&1 | FileCheck %s
+
+# CHECK:      Contents of section .text:
+# CHECK-NEXT:  11000 56441111 52341111
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS32
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_386
+Sections:
+  - Type:            SHT_PROGBITS
+    Name:            .text
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x04
+    Content:         "1111111111111111"
+  - Type:            SHT_REL
+    Name:            .rel.text
+    Link:            .symtab
+    Info:            .text
+    AddressAlign:    0x04
+    Relocations:
+      - Offset:          0
+        Symbol:          _start
+        Type:            R_386_16
+      - Offset:          4
+        Symbol:          _start
+        Type:            R_386_PC16
+Symbols:
+  Global:
+    - Name:     _start
+      Type:     STT_FUNC
+      Section:  .text
+      Value:    0x12345
+      Size:     4
Index: lld/trunk/ELF/Target.cpp
===================================================================
--- lld/trunk/ELF/Target.cpp
+++ lld/trunk/ELF/Target.cpp
@@ -329,6 +329,7 @@
     return R_TLSLD;
   case R_386_PLT32:
     return R_PLT_PC;
+  case R_386_PC16:
   case R_386_PC32:
     return R_PC;
   case R_386_GOTPC:
@@ -437,11 +438,13 @@
   switch (Type) {
   default:
     return 0;
+  case R_386_16:
   case R_386_32:
   case R_386_GOT32:
   case R_386_GOT32X:
   case R_386_GOTOFF:
   case R_386_GOTPC:
+  case R_386_PC16:
   case R_386_PC32:
   case R_386_PLT32:
   case R_386_TLS_LE:
@@ -452,6 +455,13 @@
 void X86TargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
                                 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) {
+    write16le(Loc, Val);
+    return;
+  }
   write32le(Loc, Val);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27303.80173.patch
Type: text/x-patch
Size: 2278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161203/aa1a286f/attachment.bin>


More information about the llvm-commits mailing list