[PATCH] D25560: [ELF] Emit relocation for GOT entry even if it is an absolute symbol

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 13 07:47:43 PDT 2016


evgeny777 created this revision.
evgeny777 added reviewers: ruiu, rafael.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.

This should be done in the following case

sample.s:

  .long symbol at gotpcrel  

sample.t:

  PROVIDE_HIDDEN(symbol = ADDR(.section));

Both ld and gold will produce *_RELATIVE relocation for 'symbol' if we compile sample.s and link shared object using script shared.t.
This patch implements the same behavior for lld.


Repository:
  rL LLVM

https://reviews.llvm.org/D25560

Files:
  ELF/Relocations.cpp
  test/ELF/abs-hidden.s
  test/ELF/arm-got-relative.s
  test/ELF/pie-weak.s


Index: test/ELF/pie-weak.s
===================================================================
--- test/ELF/pie-weak.s
+++ test/ELF/pie-weak.s
@@ -4,13 +4,16 @@
 # RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s
 
 # RELOCS:      Relocations [
+# RELOCS-NEXT:  Section (4) .rela.dyn {
+# RELOCS-NEXT:    0x20B0 R_X86_64_RELATIVE - 0x0
+# RELOCS-NEXT:  }
 # RELOCS-NEXT: ]
 
 .weak foo
 
 .globl _start
 _start:
 # DISASM: _start:
-# DISASM-NEXT: 1000: 48 8b 05 69 10 00 00 movq 4201(%rip), %rax
+# DISASM-NEXT:1000: 48 8b 05 a9 10 00 00  movq  4265(%rip), %rax
 #                                              ^ .got - (.text + 7)
 mov foo at gotpcrel(%rip), %rax
Index: test/ELF/arm-got-relative.s
===================================================================
--- test/ELF/arm-got-relative.s
+++ test/ELF/arm-got-relative.s
@@ -28,7 +28,8 @@
  bx lr
 
 // CHECK: Dynamic Relocations {
-// CHECK-NEXT:  0x204C R_ARM_GLOB_DAT function 0x0
+// CHECK-NEXT:  0x2050 R_ARM_RELATIVE - 0x0
+// CHECK-NEXT:  0x2054 R_ARM_GLOB_DAT function 0x0
 
 // CHECK: Name: _GLOBAL_OFFSET_TABLE_ (16)
 // CHECK-NEXT:    Value: 0x0
@@ -48,6 +49,6 @@
 // CODE-NEXT:    100c:        1e ff 2f e1    bx      lr
 // CODE:$d.1:
 // (_GLOBAL_OFFSET_TABLE_ = 0x2048) - (0x1008 + 8) 0x1038
-// CODE-NEXT:    1010:        38 10 00 00
+// CODE-NEXT:    1010:        40 10 00 00
 // (Got(function) - GotBase = 0x4
 // CODE-NEXT:    1014:        04 00 00 00
Index: test/ELF/abs-hidden.s
===================================================================
--- test/ELF/abs-hidden.s
+++ test/ELF/abs-hidden.s
@@ -21,17 +21,17 @@
 // CHECK-NEXT: AddressAlignment: 4
 // CHECK-NEXT: EntrySize: 0
 // CHECK-NEXT: SectionData (
-// CHECK-NEXT:   0000: 42000000 00000000 58100000
-//                                       0x2060 - (0x1000 + 8) = 1058
+// CHECK-NEXT:   0000: 42000000 00000000 98100000
+//                                       0x20a0 - (0x1000 + 8) = 1098
 // CHECK-NEXT: )
 
-// CHECK:      Name: .got (38)
+// CHECK:      Name: .got (48)
 // CHECK-NEXT: Type: SHT_PROGBITS
 // CHECK-NEXT: Flags [
 // CHECK-NEXT:   SHF_ALLOC
 // CHECK-NEXT:   SHF_WRITE
 // CHECK-NEXT: ]
-// CHECK-NEXT: Address: 0x2060
+// CHECK-NEXT: Address: 0x20A0
 // CHECK-NEXT: Offset:
 // CHECK-NEXT: Size: 8
 // CHECK-NEXT: Link: 0
@@ -43,4 +43,8 @@
 // CHECK-NEXT: )
 
 // CHECK:      Relocations [
+// CHECK-NEXT:  Section (4) .rela.dyn {
+// CHECK-NEXT:    0x20A0 R_X86_64_RELATIVE - 0x42
+// CHECK-NEXT:  }
 // CHECK-NEXT: ]
+
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -709,7 +709,7 @@
         continue;
 
       Out<ELFT>::Got->addEntry(Body);
-      if (Preemptible || (Config->Pic && !isAbsolute<ELFT>(Body))) {
+      if (Preemptible || Config->Pic) {
         uint32_t DynType;
         if (Body.isTls())
           DynType = Target->TlsGotRel;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25560.74513.patch
Type: text/x-patch
Size: 2927 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161013/00ec3604/attachment.bin>


More information about the llvm-commits mailing list