[lld] r282244 - Linker script: fix crash when discarding section

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 23 06:17:16 PDT 2016


Author: evgeny777
Date: Fri Sep 23 08:17:16 2016
New Revision: 282244

URL: http://llvm.org/viewvc/llvm-project?rev=282244&view=rev
Log:
Linker script: fix crash when discarding section

If section contains local symbols ldd crashes, because local
symbols are added to symbol table before section is discarded
by linker script processor. This patch calls copyLocalSymbols()
after createSections, so discarded section symbols are not copied

Added:
    lld/trunk/test/ELF/linkerscript/discard-section.s
Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=282244&r1=282243&r2=282244&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Sep 23 08:17:16 2016
@@ -244,8 +244,6 @@ template <class ELFT> static std::vector
 
 // The main function of the writer.
 template <class ELFT> void Writer<ELFT>::run() {
-  if (Config->Discard != DiscardPolicy::All)
-    copyLocalSymbols();
   addReservedSymbols();
 
   if (Target->NeedsThunks)
@@ -262,6 +260,9 @@ template <class ELFT> void Writer<ELFT>:
     Script<ELFT>::X->processCommands(Factory);
   }
 
+  if (Config->Discard != DiscardPolicy::All)
+    copyLocalSymbols();
+
   finalizeSections();
   if (HasError)
     return;

Added: lld/trunk/test/ELF/linkerscript/discard-section.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/discard-section.s?rev=282244&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/discard-section.s (added)
+++ lld/trunk/test/ELF/linkerscript/discard-section.s Fri Sep 23 08:17:16 2016
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "SECTIONS { /DISCARD/ : { *(.aaa*) } }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
+# CHECK-NOT: .aaa
+
+.section .aaa,"a"
+aaa:
+  .quad 0




More information about the llvm-commits mailing list