[lld] r348748 - [ELF] - Allow discarding .dynsym from the linker script.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 10 01:13:36 PST 2018


Author: grimar
Date: Mon Dec 10 01:13:36 2018
New Revision: 348748

URL: http://llvm.org/viewvc/llvm-project?rev=348748&view=rev
Log:
[ELF] - Allow discarding .dynsym from the linker script.

This is a part of https://bugs.llvm.org/show_bug.cgi?id=39810.
The patch allows discarding the .dynsym section using linker script.

Differential revision: https://reviews.llvm.org/D55218

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/test/ELF/linkerscript/discard-section-err.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=348748&r1=348747&r2=348748&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Dec 10 01:13:36 2018
@@ -415,8 +415,8 @@ LinkerScript::computeInputSections(const
 
 void LinkerScript::discard(ArrayRef<InputSection *> V) {
   for (InputSection *S : V) {
-    if (S == In.ShStrTab || S == In.Dynamic || S == In.DynSymTab ||
-        S == In.RelaDyn || S == In.RelrDyn)
+    if (S == In.ShStrTab || S == In.Dynamic || S == In.RelaDyn ||
+        S == In.RelrDyn)
       error("discarding " + S->Name + " section is not allowed");
 
     // You can discard .hash and .gnu.hash sections by linker scripts. Since

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=348748&r1=348747&r2=348748&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Dec 10 01:13:36 2018
@@ -1508,7 +1508,10 @@ void RelocationBaseSection::finalizeCont
   // relocations due to IFUNC (e.g. strcpy). sh_link will be set to 0 in that
   // case.
   InputSection *SymTab = Config->Relocatable ? In.SymTab : In.DynSymTab;
-  getParent()->Link = SymTab ? SymTab->getParent()->SectionIndex : 0;
+  if (SymTab && SymTab->getParent())
+    getParent()->Link = SymTab->getParent()->SectionIndex;
+  else
+    getParent()->Link = 0;
 
   if (In.RelaIplt == this || In.RelaPlt == this)
     getParent()->Info = In.GotPlt->getParent()->SectionIndex;
@@ -2126,7 +2129,8 @@ GnuHashTableSection::GnuHashTableSection
 }
 
 void GnuHashTableSection::finalizeContents() {
-  getParent()->Link = In.DynSymTab->getParent()->SectionIndex;
+  if (OutputSection *Sec = In.DynSymTab->getParent())
+    getParent()->Link = Sec->SectionIndex;
 
   // Computes bloom filter size in word size. We want to allocate 12
   // bits for each symbol. It must be a power of two.
@@ -2256,7 +2260,8 @@ HashTableSection::HashTableSection()
 }
 
 void HashTableSection::finalizeContents() {
-  getParent()->Link = In.DynSymTab->getParent()->SectionIndex;
+  if (OutputSection *Sec = In.DynSymTab->getParent())
+    getParent()->Link = Sec->SectionIndex;
 
   unsigned NumEntries = 2;                       // nbucket and nchain.
   NumEntries += In.DynSymTab->getNumSymbols();   // The chain entries.

Modified: lld/trunk/test/ELF/linkerscript/discard-section-err.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/discard-section-err.s?rev=348748&r1=348747&r2=348748&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/discard-section-err.s (original)
+++ lld/trunk/test/ELF/linkerscript/discard-section-err.s Mon Dec 10 01:13:36 2018
@@ -12,10 +12,9 @@
 # RUN:   FileCheck -check-prefix=DYNAMIC %s
 # DYNAMIC: discarding .dynamic section is not allowed
 
+## We allow discarding .dynsym, check we don't crash.
 # RUN: echo "SECTIONS { /DISCARD/ : { *(.dynsym) } }" > %t.script
-# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
-# RUN:   FileCheck -check-prefix=DYNSYM %s
-# DYNSYM: discarding .dynsym section is not allowed
+# RUN: ld.lld -pie -o %t --script %t.script %t.o
 
 ## We allow discarding .dynstr, check we don't crash.
 # RUN: echo "SECTIONS { /DISCARD/ : { *(.dynstr) } }" > %t.script




More information about the llvm-commits mailing list