aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF/LinkerScript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r--lld/ELF/LinkerScript.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index bfb583453735..56d94744fae5 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -310,7 +310,7 @@ void LinkerScript::processInsertCommands() {
for (const InsertCommand &cmd : insertCommands) {
for (StringRef name : cmd.names) {
// If base is empty, it may have been discarded by
- // adjustSectionsBeforeSorting(). We do not handle such output sections.
+ // adjustOutputSections(). We do not handle such output sections.
auto from = llvm::find_if(sectionCommands, [&](SectionCommand *subCmd) {
return isa<OutputSection>(subCmd) &&
cast<OutputSection>(subCmd)->name == name;
@@ -1114,7 +1114,7 @@ static void maybePropagatePhdrs(OutputSection &sec,
}
}
-void LinkerScript::adjustSectionsBeforeSorting() {
+void LinkerScript::adjustOutputSections() {
// If the output section contains only symbol assignments, create a
// corresponding output section. The issue is what to do with linker script
// like ".foo : { symbol = 42; }". One option would be to convert it to
@@ -1148,14 +1148,16 @@ void LinkerScript::adjustSectionsBeforeSorting() {
sec->alignment =
std::max<uint32_t>(sec->alignment, sec->alignExpr().getValue());
- // The input section might have been removed (if it was an empty synthetic
- // section), but we at least know the flags.
- if (sec->hasInputSections)
+ bool isEmpty = (getFirstInputSection(sec) == nullptr);
+ bool discardable = isEmpty && isDiscardable(*sec);
+ // If sec has at least one input section and not discarded, remember its
+ // flags to be inherited by subsequent output sections. (sec may contain
+ // just one empty synthetic section.)
+ if (sec->hasInputSections && !discardable)
flags = sec->flags;
// We do not want to keep any special flags for output section
// in case it is empty.
- bool isEmpty = (getFirstInputSection(sec) == nullptr);
if (isEmpty)
sec->flags = flags & ((sec->nonAlloc ? 0 : (uint64_t)SHF_ALLOC) |
SHF_WRITE | SHF_EXECINSTR);
@@ -1172,7 +1174,7 @@ void LinkerScript::adjustSectionsBeforeSorting() {
if (sec->sectionIndex != UINT32_MAX)
maybePropagatePhdrs(*sec, defPhdrs);
- if (isEmpty && isDiscardable(*sec)) {
+ if (discardable) {
sec->markDead();
cmd = nullptr;
}