From d8281379f97a3e63ac7ab16582c5f81cd01baba9 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Sat, 24 Mar 2018 13:10:19 +0000 Subject: [ELF] - Do not ignore discarding of .rela.plt/.rela.dyn, allow doing custom layout for them. Currently when we build input sections list in linker script we ignore all rel[a] sections. That was done to support scripts like .rela.dyn : { *(.rela.data) } for emit relocs. Though as a result following scripts were also silently ignored: /DISCARD/ : { *(.rela.plt) /DISCARD/ : { *(.rela.dyn) and we produced output with this sections. That is not ideal. The solution this patch suggests is simple: do not ignore synthetic rel[a] sections. That way we can enable common discarding logic for them and report a proper error. Differential revision: https://reviews.llvm.org/D41640 llvm-svn: 328419 --- lld/ELF/LinkerScript.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lld/ELF/LinkerScript.cpp') diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index e16b49e785b..2240f7a0887 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -380,7 +380,10 @@ LinkerScript::computeInputSections(const InputSectionDescription *Cmd) { // For -emit-relocs we have to ignore entries like // .rela.dyn : { *(.rela.data) } // which are common because they are in the default bfd script. - if (Sec->Type == SHT_REL || Sec->Type == SHT_RELA) + // We do not ignore SHT_REL[A] linker-synthesized sections here because + // want to support scripts that do custom layout for them. + if (!isa(Sec) && + (Sec->Type == SHT_REL || Sec->Type == SHT_RELA)) continue; std::string Filename = getFilename(Sec->File); @@ -405,7 +408,7 @@ LinkerScript::computeInputSections(const InputSectionDescription *Cmd) { void LinkerScript::discard(ArrayRef V) { for (InputSection *S : V) { if (S == InX::ShStrTab || S == InX::Dynamic || S == InX::DynSymTab || - S == InX::DynStrTab) + S == InX::DynStrTab || S == InX::RelaPlt || S == InX::RelaDyn) error("discarding " + S->Name + " section is not allowed"); // You can discard .hash and .gnu.hash sections by linker scripts. Since -- cgit v1.2.3