Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -257,15 +257,6 @@ if (Pat.SortOuter == SortSectionPolicy::None) return; - if (Pat.SortOuter == SortSectionPolicy::Default && - Config->SortSection == SortSectionPolicy::Default) { - // If -symbol-ordering-file was given, sort accordingly. - // Usually, Order is empty. - if (!Order.empty()) - sortByOrder(Vec, [&](InputSectionBase *S) { return Order.lookup(S); }); - return; - } - if (Pat.SortInner == SortSectionPolicy::Default) sortSections(Vec, Config->SortSection); else Index: ELF/OutputSections.h =================================================================== --- ELF/OutputSections.h +++ ELF/OutputSections.h @@ -143,8 +143,6 @@ namespace elf { uint64_t getHeaderSize(); -void sortByOrder(llvm::MutableArrayRef In, - std::function Order); extern std::vector OutputSections; } // namespace elf Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -134,8 +134,8 @@ } } -void elf::sortByOrder(MutableArrayRef In, - std::function Order) { +static void sortByOrder(MutableArrayRef In, + std::function Order) { typedef std::pair Pair; auto Comp = [](const Pair &A, const Pair &B) { return A.first < B.first; }; Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -1020,8 +1020,6 @@ // If no layout was provided by linker script, we want to apply default // sorting for special input sections and handle --symbol-ordering-file. template void Writer::sortInputSections() { - assert(!Script->HasSectionsCommand); - // Sort input sections by priority using the list provided // by --symbol-ordering-file. DenseMap Order = buildSectionOrder(); @@ -1031,6 +1029,9 @@ if (Sec->Live) Sec->sort([&](InputSectionBase *S) { return Order.lookup(S); }); + if (Script->HasSectionsCommand) + return; + // Sort input sections by section name suffixes for // __attribute__((init_priority(N))). if (OutputSection *Sec = findSection(".init_array")) @@ -1057,9 +1058,9 @@ if (auto *Sec = dyn_cast(Base)) Sec->SortRank = getSectionRank(Sec); - if (!Script->HasSectionsCommand) { - sortInputSections(); + sortInputSections(); + if (!Script->HasSectionsCommand) { // We know that all the OutputSections are contiguous in this case. auto E = Script->SectionCommands.end(); auto I = Script->SectionCommands.begin(); Index: test/ELF/linkerscript/symbol-ordering-file.s =================================================================== --- test/ELF/linkerscript/symbol-ordering-file.s +++ test/ELF/linkerscript/symbol-ordering-file.s @@ -14,6 +14,10 @@ # AFTER: Contents of section .foo: # AFTER-NEXT: 2211 +# RUN: echo "SECTIONS { .text : { *(.text) } }" > %t2.script +# RUN: ld.lld --symbol-ordering-file %t.ord %t.o --script %t2.script -o %t3.out +# RUN: llvm-objdump -s %t3.out| FileCheck %s --check-prefix=AFTER + .section .foo,"ax",@progbits,unique,1 _foo1: .byte 0x11