diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -194,7 +194,7 @@ bool timeTraceEnabled; bool tocOptimize; bool undefinedVersion; - bool unique = false; + bool unique; bool useAndroidRelrTags = false; bool warnBackrefs; bool warnCommon; diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -680,22 +680,21 @@ std::function add; add = [&](InputSectionBase *s) { - if (s->isLive() && !s->parent) { - orphanSections.push_back(s); - - StringRef name = getOutputSectionName(s); - - if (config->unique) { - v.push_back(createSection(s, name)); - } else if (OutputSection *sec = findByName(sectionCommands, name)) { - sec->recordSection(s); - } else { - if (OutputSection *os = addInputSec(map, s, name)) - v.push_back(os); - assert(isa(s) || - s->getOutputSection()->sectionIndex == UINT32_MAX); - } + if (s->isLive() && !s->parent) { + orphanSections.push_back(s); + + StringRef name = getOutputSectionName(s); + if (config->unique) { + v.push_back(createSection(s, name)); + } else if (OutputSection *sec = findByName(sectionCommands, name)) { + sec->recordSection(s); + } else { + if (OutputSection *os = addInputSec(map, s, name)) + v.push_back(os); + assert(isa(s) || + s->getOutputSection()->sectionIndex == UINT32_MAX); } + } if (config->relocatable) for (InputSectionBase *depSec : s->dependentSections) diff --git a/lld/test/ELF/unique-orphans.s b/lld/test/ELF/unique-orphans.s --- a/lld/test/ELF/unique-orphans.s +++ b/lld/test/ELF/unique-orphans.s @@ -21,6 +21,6 @@ ## Test that --unique does not affect sections specified in output section descriptions. # RUN: echo 'SECTIONS { .foo : { *(.foo) }}' > %t.script # RUN: ld.lld %t.o -o %t2.elf -T %t.script --unique -# RUN: llvm-readelf -S %t2.elf | FileCheck --check-prefix UNIQUE_SCRIPT %s -# UNIQUE_SCRIPT: .foo -# UNIQUE_SCRIPT-NOT: .foo +# RUN: llvm-readelf -S %t2.elf | FileCheck --check-prefix SCRIPT %s +# SCRIPT: .foo +# SCRIPT-NOT: .foo