diff options
author | Eugene Leviant <evgeny.leviant@gmail.com> | 2016-09-23 13:17:16 +0000 |
---|---|---|
committer | Eugene Leviant <evgeny.leviant@gmail.com> | 2016-09-23 13:17:16 +0000 |
commit | d4dea164dd453f567d9d33f3c158c33d6904987f (patch) | |
tree | a04b9fb3517ab599aa9cf7dd45c934d83bda22b5 | |
parent | c8ccd1f1c5cba21a36e65f284929499b2f7a31b5 (diff) | |
download | bcm5719-llvm-d4dea164dd453f567d9d33f3c158c33d6904987f.tar.gz bcm5719-llvm-d4dea164dd453f567d9d33f3c158c33d6904987f.zip |
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
llvm-svn: 282244
-rw-r--r-- | lld/ELF/Writer.cpp | 5 | ||||
-rw-r--r-- | lld/test/ELF/linkerscript/discard-section.s | 10 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index e42240fdd83..5ab9d64e116 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -244,8 +244,6 @@ template <class ELFT> static std::vector<DefinedCommon *> getCommonSymbols() { // 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>::run() { Script<ELFT>::X->processCommands(Factory); } + if (Config->Discard != DiscardPolicy::All) + copyLocalSymbols(); + finalizeSections(); if (HasError) return; diff --git a/lld/test/ELF/linkerscript/discard-section.s b/lld/test/ELF/linkerscript/discard-section.s new file mode 100644 index 00000000000..d7d2acff1b4 --- /dev/null +++ b/lld/test/ELF/linkerscript/discard-section.s @@ -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 |