diff options
| -rw-r--r-- | lld/ELF/Driver.cpp | 5 | ||||
| -rw-r--r-- | lld/ELF/ICF.cpp | 4 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 5 | ||||
| -rw-r--r-- | lld/test/ELF/partition-icf.s | 7 |
4 files changed, 11 insertions, 10 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 36cda3a1e3d..9cab10e49da 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1919,6 +1919,11 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) { // Create output sections described by SECTIONS commands. script->processSectionCommands(); + // Linker scripts control how input sections are assigned to output sections. + // Input sections that were not handled by scripts are called "orphans", and + // they are assigned to output sections by the default rule. Process that. + script->addOrphanSections(); + // Two input sections with different output sections should not be folded. // ICF runs after processSectionCommands() so that we know the output sections. if (config->icf != ICFLevel::None) { diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index a780ee12448..8664811a4a5 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -306,8 +306,8 @@ bool ICF<ELFT>::equalsConstant(const InputSection *a, const InputSection *b) { return false; // If two sections have different output sections, we cannot merge them. - if (getOutputSectionName(a) != getOutputSectionName(b) || - a->getParent() != b->getParent()) + assert(a->getParent() && b->getParent()); + if (a->getParent() != b->getParent()) return false; if (a->areRelocsRela) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 5c6fcc8532c..a01c326b0d7 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -534,11 +534,6 @@ template <class ELFT> void elf::createSyntheticSections() { // The main function of the writer. template <class ELFT> void Writer<ELFT>::run() { - // Linker scripts controls how input sections are assigned to output sections. - // Input sections that were not handled by scripts are called "orphans", and - // they are assigned to output sections by the default rule. Process that. - script->addOrphanSections(); - if (config->discard != DiscardPolicy::All) copyLocalSymbols(); diff --git a/lld/test/ELF/partition-icf.s b/lld/test/ELF/partition-icf.s index 58be0c1ad00..e8608c899fc 100644 --- a/lld/test/ELF/partition-icf.s +++ b/lld/test/ELF/partition-icf.s @@ -3,15 +3,16 @@ // RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections --icf=all // RUN: llvm-readelf -S -s %t | FileCheck %s -// CHECK: [[MAIN:[0-9]+]]] .text +// CHECK: part1 // CHECK: [[P1:[0-9]+]]] .text +// CHECK: part2 // CHECK: [[P2:[0-9]+]]] .text // CHECK: Symbol table '.symtab' // CHECK: [[P1]] f1 // CHECK: [[P2]] f2 -// CHECK: [[MAIN]] g1 -// CHECK: [[MAIN]] g2 +// CHECK: [[P1]] g1 +// CHECK: [[P2]] g2 .section .llvm_sympart.f1,"",@llvm_sympart .asciz "part1" |

