[lld] r288451 - Write the addent to got entries when using Elf_Rel.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 17:57:25 PST 2016


Author: rafael
Date: Thu Dec  1 19:57:24 2016
New Revision: 288451

URL: http://llvm.org/viewvc/llvm-project?rev=288451&view=rev
Log:
Write the addent to got entries when using Elf_Rel.

Added:
    lld/trunk/test/ELF/dynamic-got.s
Modified:
    lld/trunk/ELF/Relocations.cpp

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=288451&r1=288450&r2=288451&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Dec  1 19:57:24 2016
@@ -760,9 +760,11 @@ static void scanRelocs(InputSectionBase<
       else
         DynType = Target->GotRel;
 
-      if (Preemptible || (Config->Pic && !isAbsolute<ELFT>(Body)))
+      // FIXME: this logic is almost duplicated above.
+      bool Constant = !Preemptible && !(Config->Pic && !isAbsolute<ELFT>(Body));
+      if (!Constant)
         AddDyn({DynType, In<ELFT>::Got, Off, !Preemptible, &Body, 0});
-      else
+      if (Constant || !RelTy::IsRela)
         In<ELFT>::Got->Relocations.push_back({GotRE, DynType, Off, 0, &Body});
       continue;
     }

Added: lld/trunk/test/ELF/dynamic-got.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dynamic-got.s?rev=288451&view=auto
==============================================================================
--- lld/trunk/test/ELF/dynamic-got.s (added)
+++ lld/trunk/test/ELF/dynamic-got.s Thu Dec  1 19:57:24 2016
@@ -0,0 +1,33 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t.o
+// RUN: ld.lld %t.o -o %t.so -shared
+// RUN: llvm-readobj -s -l -section-data %t.so | FileCheck %s
+
+// CHECK:      Name: .got
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT:   SHF_ALLOC
+// CHECK-NEXT:   SHF_WRITE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address:
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size:
+// CHECK-NEXT: Link:
+// CHECK-NEXT: Info:
+// CHECK-NEXT: AddressAlignment:
+// CHECK-NEXT: EntrySize:
+// CHECK-NEXT: SectionData (
+// CHECK-NEXT:   0000: 00200000                |
+// CHECK-NEXT: )
+
+// CHECK:      Type: PT_DYNAMIC
+// CHECK-NEXT: Offset: 0x2000
+// CHECK-NEXT: VirtualAddress: 0x2000
+// CHECK-NEXT: PhysicalAddress: 0x2000
+
+        calll   .L0$pb
+.L0$pb:
+        popl    %eax
+.Ltmp0:
+        addl    $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %eax
+        movl    _DYNAMIC at GOT(%eax), %eax




More information about the llvm-commits mailing list