diff options
author | George Rimar <grimar@accesssoftek.com> | 2017-06-28 09:59:34 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2017-06-28 09:59:34 +0000 |
commit | e0b43df32eea01af96fd5489c07141844be19675 (patch) | |
tree | 95456eefac4f036aff7e17c089f817d7bf9785d2 | |
parent | dbe843d602488af7b8095babf582db65fa8a4b4e (diff) | |
download | bcm5719-llvm-e0b43df32eea01af96fd5489c07141844be19675.tar.gz bcm5719-llvm-e0b43df32eea01af96fd5489c07141844be19675.zip |
[ELF] - Do not crash when LLD synthesizes output sections with BYTE commands and -r
This is PR33596. Previously LLD would crash
because BYTE command synthesized output section,
but it was not assigned to Sec member of OutputSectionCommand.
Behaviour of -script and -r combination is not well defined,
but it seems after this change LLD naturally inherits behavior of
GNU linkers - creates output section requested in script and does not
crash anymore.
Differential revision: https://reviews.llvm.org/D34676
llvm-svn: 306527
-rw-r--r-- | lld/ELF/Writer.cpp | 8 | ||||
-rw-r--r-- | lld/test/ELF/relocatable-script.s | 7 |
2 files changed, 11 insertions, 4 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index b167dddd981..112eee5715c 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1014,13 +1014,13 @@ findOrphanPos(std::vector<BaseCommand *>::iterator B, } template <class ELFT> void Writer<ELFT>::sortSections() { + if (Script->Opt.HasSections) + Script->adjustSectionsBeforeSorting(); + // Don't sort if using -r. It is not necessary and we want to preserve the // relative order for SHF_LINK_ORDER sections. if (Config->Relocatable) - return; - - if (Script->Opt.HasSections) - Script->adjustSectionsBeforeSorting(); + return; for (BaseCommand *Base : Script->Opt.Commands) if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base)) diff --git a/lld/test/ELF/relocatable-script.s b/lld/test/ELF/relocatable-script.s new file mode 100644 index 00000000000..133d61f4805 --- /dev/null +++ b/lld/test/ELF/relocatable-script.s @@ -0,0 +1,7 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux -o %t1.o %s +# RUN: echo "SECTIONS { .foo : { BYTE(0x0) } }" > %t.script +# RUN: ld.lld -r %t1.o -script %t.script -o %t2.o +# RUN: llvm-readobj -sections %t2.o | FileCheck %s + +# CHECK: Name: .foo |