[PATCH] D13522: [ELF2] - fix for using PLT/GOT for X86TargetInfo

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 7 10:59:47 PDT 2015


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
grimar added a project: lld.

I noticed that functions from DSO looks to be always called via PLT+GOT on elf32-i386 linked with modern ld. I think the same approach as was used in X86_64TargetInfo::relocNeedsPlt() should be applied here.

I took the object file and dso from relocation-i686.s test and linked them to executable:

ld --emit-relocs -melf_i386 tmain.o tshared.so -o tmain

And found that .dynamic_reloc section has calls to PLT.

Disassembly of section .dynamic_reloc:
08048199 <.dynamic_reloc>:
 8048199:	e8 d6 ff ff ff       	call   8048174 <bar at plt+0x4>

So this fix makes the behavior to be consistent with ld.


http://reviews.llvm.org/D13522

Files:
  ELF/Target.cpp
  test/elf2/relocation-i686.s

Index: test/elf2/relocation-i686.s
===================================================================
--- test/elf2/relocation-i686.s
+++ test/elf2/relocation-i686.s
@@ -62,7 +62,7 @@
         call bar+4
 // CHECK:      Disassembly of section .dynamic_reloc:
 // CHECK-NEXT: .dynamic_reloc:
-// CHECK-NEXT:   12019:  e8 00 00 00 00  calll  0
+// CHECK-NEXT:   12019:  e8 16 00 00 00 calll 22
 
 .section .R_386_GOT32,"ax", at progbits
 .global R_386_GOT32
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -56,7 +56,14 @@
 }
 
 bool X86TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
-  return Type == R_386_PLT32;
+  switch (Type) {
+  default:
+    return false;
+  case R_386_PC32:
+    return S.isShared();
+  case R_386_PLT32:
+    return true;
+  }
 }
 
 static void add32le(uint8_t *L, int32_t V) { write32le(L, read32le(L) + V); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13522.36768.patch
Type: text/x-patch
Size: 940 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151007/22b4b788/attachment.bin>


More information about the llvm-commits mailing list