[PATCH] D53881: [ELF] Fallback to sh_link=0 if neither .dynsym nor .symtab exists

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 30 12:51:21 PDT 2018


MaskRay updated this revision to Diff 171767.
MaskRay added a comment.

Update comment


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D53881

Files:
  ELF/SyntheticSections.cpp
  test/ELF/gnu-ifunc-relative.s


Index: test/ELF/gnu-ifunc-relative.s
===================================================================
--- test/ELF/gnu-ifunc-relative.s
+++ test/ELF/gnu-ifunc-relative.s
@@ -1,7 +1,9 @@
 // REQUIRES: x86
 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-// RUN: ld.lld -static %t.o -o %tout
-// RUN: llvm-readobj -r -t %tout | FileCheck %s
+// RUN: ld.lld --strip-all %t.o -o %t
+// RUN: llvm-readobj -r %t | FileCheck %s
+// RUN: ld.lld %t.o -o %t
+// RUN: llvm-readobj -r -t %t | FileCheck %s --check-prefixes=CHECK,SYM
 
 .type foo STT_GNU_IFUNC
 .globl foo
@@ -16,8 +18,8 @@
 // CHECK-NEXT:   R_X86_64_IRELATIVE - 0x[[ADDR:.*]]
 // CHECK-NEXT: }
 
-// CHECK:      Name: foo
-// CHECK-NEXT: Value: 0x[[ADDR]]
-// CHECK-NEXT: Size: 0
-// CHECK-NEXT: Binding: Global
-// CHECK-NEXT: Type: GNU_IFunc
+// SYM:      Name: foo
+// SYM-NEXT: Value: 0x[[ADDR]]
+// SYM-NEXT: Size: 0
+// SYM-NEXT: Binding: Global
+// SYM-NEXT: Type: GNU_IFunc
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1491,11 +1491,13 @@
 }
 
 void RelocationBaseSection::finalizeContents() {
-  // If all relocations are R_*_RELATIVE they don't refer to any
+  // If all relocations are R_*_{,I}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 the index of the regular symbol table section.
-  getParent()->Link = In.DynSymTab ? In.DynSymTab->getParent()->SectionIndex
-                                   : In.SymTab->getParent()->SectionIndex;
+  // is the case, use the index of the regular symbol table section (if exists)
+  // or 0.
+  getParent()->Link =
+      In.DynSymTab ? In.DynSymTab->getParent()->SectionIndex
+                   : In.SymTab ? In.SymTab->getParent()->SectionIndex : 0;
 
   if (In.RelaIplt == this || In.RelaPlt == this)
     getParent()->Info = In.GotPlt->getParent()->SectionIndex;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53881.171767.patch
Type: text/x-patch
Size: 2003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181030/00e9dc2e/attachment.bin>


More information about the llvm-commits mailing list