[lld] r358650 - [ELF] Respect NonAlloc when copying flags from the previous sections
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 18 02:22:06 PDT 2019
Author: maskray
Date: Thu Apr 18 02:22:05 2019
New Revision: 358650
URL: http://llvm.org/viewvc/llvm-project?rev=358650&view=rev
Log:
[ELF] Respect NonAlloc when copying flags from the previous sections
Summary:
If the output section contains only symbol assignments, we copy flags
from the previous sections. Don't set SHF_ALLOC if NonAlloc is true.
We also have to change the type from SHT_NOBITS to SHT_PROGBITS.
In ld.bfd, bfd_elf_get_default_section_type maps non-alloctable sections to SHT_PROGBITS.
Non-alloctable SHT_NOBITS sections do not make sense.
Fixes PR38626
Differential Revision: https://reviews.llvm.org/D59986
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/test/ELF/linkerscript/info-section-type.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=358650&r1=358649&r2=358650&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Apr 18 02:22:05 2019
@@ -887,7 +887,8 @@ void LinkerScript::adjustSectionsBeforeS
// in case it is empty.
bool IsEmpty = getInputSections(Sec).empty();
if (IsEmpty)
- Sec->Flags = Flags & (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR);
+ Sec->Flags =
+ Flags & ((Sec->NonAlloc ? 0 : SHF_ALLOC) | SHF_WRITE | SHF_EXECINSTR);
if (IsEmpty && isDiscardable(*Sec)) {
Sec->Live = false;
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=358650&r1=358649&r2=358650&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Thu Apr 18 02:22:05 2019
@@ -752,6 +752,7 @@ bool ScriptParser::readSectionDirective(
} else {
skip(); // This is "COPY", "INFO" or "OVERLAY".
Cmd->NonAlloc = true;
+ Cmd->Type = SHT_PROGBITS;
}
expect(")");
return true;
Modified: lld/trunk/test/ELF/linkerscript/info-section-type.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/info-section-type.s?rev=358650&r1=358649&r2=358650&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/info-section-type.s (original)
+++ lld/trunk/test/ELF/linkerscript/info-section-type.s Thu Apr 18 02:22:05 2019
@@ -29,6 +29,10 @@
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC
+# RUN: echo "SECTIONS { .bar (INFO) : { . += 1; } };" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC
+
# RUN: echo "SECTIONS { .bar 0x20000 (INFO) : { *(.foo) } };" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC
More information about the llvm-commits
mailing list