[PATCH] D52830: [ELF] - Set sh_info and sh_link for .rela.plt sections.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 3 07:01:42 PDT 2018


grimar created this revision.
grimar added reviewers: ruiu, emaste.
Herald added a reviewer: javed.absar.
Herald added a subscriber: arichardson.
Herald added a reviewer: espindola.

This is https://bugs.llvm.org/show_bug.cgi?id=37538,

Currently, LLD may set both sh_link and sh_info for
`.rela.Iplt` section to zero. GNU tools do not like that.

For the case when we have no .dynsym, patch sets sh_link to
index of the .symtab.

Also, it set sh_info to the index of the section to which the
relocation applies, as ELF spec says.
(https://docs.oracle.com/cd/E19683-01/817-3677/chapter6-94076/index.html)

As a result, behavior matches the gold and GNU tools are
happy.


https://reviews.llvm.org/D52830

Files:
  ELF/SyntheticSections.cpp
  test/ELF/aarch64-gnu-ifunc.s
  test/ELF/dynamic-reloc.s
  test/ELF/gnu-ifunc-i386.s
  test/ELF/gnu-ifunc.s


Index: test/ELF/gnu-ifunc.s
===================================================================
--- test/ELF/gnu-ifunc.s
+++ test/ELF/gnu-ifunc.s
@@ -15,11 +15,16 @@
 // CHECK-NEXT:  Address: [[RELA:.*]]
 // CHECK-NEXT:  Offset: 0x158
 // CHECK-NEXT:  Size: 48
-// CHECK-NEXT:  Link: 0
-// CHECK-NEXT:  Info: 0
+// CHECK-NEXT:  Link: [[SYMTAB:.*]]
+// CHECK-NEXT:  Info: [[PLT:.*]]
 // CHECK-NEXT:  AddressAlignment: 8
 // CHECK-NEXT:  EntrySize: 24
 // CHECK-NEXT: }
+// CHECK:      Index: [[PLT]]
+// CHECK-NEXT: Name: .plt
+// CHECK:      Index: [[SYMTAB]]
+// CHECK-NEXT: Name: .symtab
+// CHECK-NEXT: Type: SHT_SYMTAB
 // CHECK:      Relocations [
 // CHECK-NEXT:   Section ({{.*}}) .rela.plt {
 // CHECK-NEXT:     0x202000 R_X86_64_IRELATIVE
Index: test/ELF/gnu-ifunc-i386.s
===================================================================
--- test/ELF/gnu-ifunc-i386.s
+++ test/ELF/gnu-ifunc-i386.s
@@ -15,8 +15,8 @@
 // CHECK-NEXT:  Address: [[RELA:.*]]
 // CHECK-NEXT:  Offset: 0xD4
 // CHECK-NEXT:  Size: 16
-// CHECK-NEXT:  Link: 0
-// CHECK-NEXT:  Info: 0
+// CHECK-NEXT:  Link: 6
+// CHECK-NEXT:  Info: 3
 // CHECK-NEXT:  AddressAlignment: 4
 // CHECK-NEXT:  EntrySize: 8
 // CHECK-NEXT: }
Index: test/ELF/dynamic-reloc.s
===================================================================
--- test/ELF/dynamic-reloc.s
+++ test/ELF/dynamic-reloc.s
@@ -18,7 +18,7 @@
 // CHECK-NEXT: Offset:
 // CHECK-NEXT: Size: [[RELASIZE:.*]]
 // CHECK-NEXT: Link: 1
-// CHECK-NEXT: Info: 0
+// CHECK-NEXT: Info: 6
 // CHECK-NEXT: AddressAlignment: 8
 // CHECK-NEXT: EntrySize: 24
 
Index: test/ELF/aarch64-gnu-ifunc.s
===================================================================
--- test/ELF/aarch64-gnu-ifunc.s
+++ test/ELF/aarch64-gnu-ifunc.s
@@ -15,8 +15,8 @@
 // CHECK-NEXT:  Address: [[RELA:.*]]
 // CHECK-NEXT:  Offset: 0x158
 // CHECK-NEXT:  Size: 48
-// CHECK-NEXT:  Link: 0
-// CHECK-NEXT:  Info: 0
+// CHECK-NEXT:  Link: 6
+// CHECK-NEXT:  Info: 3
 // CHECK-NEXT:  AddressAlignment: 8
 // CHECK-NEXT:  EntrySize: 24
 // CHECK-NEXT: }
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1493,11 +1493,21 @@
 void RelocationBaseSection::finalizeContents() {
   // If all relocations are R_*_RELATIVE they don't refer to any
   // dynamic symbol and we don't need a dynamic symbol table. If that
-  // is the case, just use 0 as the link.
-  Link = In.DynSymTab ? In.DynSymTab->getParent()->SectionIndex : 0;
+  // is the case, just use the index of the regular symbol table section
+  // as the link to suppress the warnings reported by GNU tools like readelf.
+  Link = In.DynSymTab ? In.DynSymTab->getParent()->SectionIndex
+                      : In.SymTab->getParent()->SectionIndex;
+
+  if (In.RelaIplt == this)
+    Info = In.Iplt->getParent()->SectionIndex;
+  else if (In.RelaPlt == this)
+    Info = In.Plt->getParent()->SectionIndex;
+  else // RelaDyn
+    Info = 0;
 
   // Set required output section properties.
   getParent()->Link = Link;
+  getParent()->Info = Info;
 }
 
 RelrBaseSection::RelrBaseSection()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52830.168109.patch
Type: text/x-patch
Size: 3157 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181003/c715276a/attachment.bin>


More information about the llvm-commits mailing list