Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -316,10 +316,15 @@ void LinkerScript::createSections(OutputSectionFactory &Factory) { processCommands(Factory); // Add orphan sections. - for (ObjectFile *F : Symtab::X->getObjectFiles()) - for (InputSectionBase *S : F->getSections()) - if (!isDiscarded(S) && !S->OutSec) + for (ObjectFile *F : Symtab::X->getObjectFiles()) { + for (InputSectionBase *S : F->getSections()) { + if (!isDiscarded(S) && !S->OutSec) { addSection(Factory, S, getOutputSectionName(S)); + elf::log("unplaced orphan section " + S->Name + " from " + + getFilename(F)); + } + } + } } // Sets value of a section-defined symbol. Two kinds of Index: test/ELF/linkerscript/orphan-handling.s =================================================================== --- test/ELF/linkerscript/orphan-handling.s +++ test/ELF/linkerscript/orphan-handling.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { .foo.1 : { *(.foo.1) } }" > %t.script + +# RUN: ld.lld -o %t.out --script %t.script %t.o --verbose | FileCheck %s +# CHECK: unplaced orphan section .text from {{.*}}.o +# CHECK: unplaced orphan section .foo.2 from {{.*}}.o + +.text +.globl _start +_start: + +.section .foo.1,"a" + .quad 1 + +.section .foo.2,"a" + .quad 2