[lld] r264160 - Not every x86 relocation is relative.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 23 07:58:25 PDT 2016


Author: rafael
Date: Wed Mar 23 09:58:25 2016
New Revision: 264160

URL: http://llvm.org/viewvc/llvm-project?rev=264160&view=rev
Log:
Not every x86 relocation is relative.

Without this predicate we were not producing R_386_RELATIVE relocations.

Added:
    lld/trunk/test/ELF/i386-relative.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=264160&r1=264159&r2=264160&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Mar 23 09:58:25 2016
@@ -85,6 +85,7 @@ public:
   void writePltZero(uint8_t *Buf) const override;
   void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr,
                 int32_t Index, unsigned RelOff) const override;
+  bool isRelRelative(uint32_t Type) const override;
   bool needsCopyRelImpl(uint32_t Type) const override;
   bool needsDynRelative(uint32_t Type) const override;
   bool needsGot(uint32_t Type, SymbolBody &S) const override;
@@ -396,6 +397,17 @@ X86TargetInfo::X86TargetInfo() {
   PltZeroSize = 16;
 }
 
+bool X86TargetInfo::isRelRelative(uint32_t Type) const {
+  switch (Type) {
+  default:
+    return false;
+  case R_386_PC32:
+  case R_386_PLT32:
+  case R_386_TLS_LDO_32:
+    return true;
+  }
+}
+
 void X86TargetInfo::writeGotPltHeader(uint8_t *Buf) const {
   write32le(Buf, Out<ELF32LE>::Dynamic->getVA());
 }

Added: lld/trunk/test/ELF/i386-relative.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/i386-relative.s?rev=264160&view=auto
==============================================================================
--- lld/trunk/test/ELF/i386-relative.s (added)
+++ lld/trunk/test/ELF/i386-relative.s Wed Mar 23 09:58:25 2016
@@ -0,0 +1,13 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t.o
+// RUN: ld.lld -shared %t.o -o %t.so
+// RUN: llvm-readobj -r %t.so | FileCheck %s
+
+// CHECK:      Relocations [
+// CHECK-NEXT:   Section ({{.*}}) .rel.dyn {
+// CHECK-NEXT:     R_386_RELATIVE - 0x0
+// CHECK-NEXT:   }
+// CHECK-NEXT: ]
+
+foo:
+        .long foo




More information about the llvm-commits mailing list