Index: lld/ELF/LinkerScript.cpp =================================================================== --- lld/ELF/LinkerScript.cpp +++ lld/ELF/LinkerScript.cpp @@ -911,7 +911,7 @@ LinkerScript::findMemoryRegion(OutputSection *sec, MemoryRegion *hint) { // Non-allocatable sections are not part of the process image. if (!(sec->flags & SHF_ALLOC)) { - if (!sec->memoryRegionName.empty()) + if (!sec->memoryRegionName.empty() && sec->hasInputSections) warn("ignoring memory region assignment for non-allocatable section '" + sec->name + "'"); return {nullptr, nullptr}; Index: lld/test/ELF/linkerscript/memory-nonalloc-no-warn.test =================================================================== --- /dev/null +++ lld/test/ELF/linkerscript/memory-nonalloc-no-warn.test @@ -0,0 +1,70 @@ +REQUIRES: x86 + +# RUN: split-file %s %t +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o + +## Check if the linker can generate the final file, containing all non-empty sections, +## without warnings for .intvec0_out, .intvec1_out1, .intvec2_out, because their +## input sections are empty. Althoung, the linker must generate a warning for the +## first ".nonalloc" section, as expected. + +RUN: ld.lld %t/a.o -T %t/a.lds -o /dev/null 2>&1 | FileCheck %s --check-prefix=WARN + +WARN: warning: ignoring memory region assignment for non-allocatable section '.nonalloc' + +## The Map file must include all sections. + +# RUN: ld.lld %t/a.o -T %t/a.lds -o /dev/null -Map=%t.map +# RUN: FileCheck %s < %t.map + +# CHECK: VMA LMA Size Align Out In Symbol +# CHECK-NEXT: 0 0 0 1 VEC_START = 0x803FE000 +# CHECK-NEXT: 0 0 1000 1 .nonalloc +# CHECK-NEXT: 0 0 1000 1 {{.*}}{{/|\\}}a.o:(.nonalloc) +# CHECK-NEXT: 0 0 8 1 .comment +# CHECK-NEXT: 0 0 8 1 :(.comment) +# CHECK-NEXT: 0 0 48 8 .symtab +# CHECK-NEXT: 0 0 48 8 :(.symtab) +# CHECK-NEXT: 0 0 68 1 .shstrtab +# CHECK-NEXT: 0 0 68 1 :(.shstrtab) +# CHECK-NEXT: 0 0 12 1 .strtab +# CHECK-NEXT: 0 0 12 1 :(.strtab) +# CHECK-NEXT: 0 0 0 1 .intvec0_out +# CHECK-NEXT: 0 0 0 1 .intvec1_out +# CHECK-NEXT: 0 0 0 1 .intvec2_out +# CHECK-NEXT: 803fe060 803fe060 4 1 .intvec3_out +# CHECK-NEXT: 803fe060 803fe060 4 1 {{.*}}{{/|\\}}a.o:(.intvec3) +# CHECK-NEXT: 803fe064 803fe064 0 4 .text +# CHECK-NEXT: 803fe064 803fe064 0 4 {{.*}}{{/|\\}}a.o:(.text) +# CHECK-NEXT: 803fe064 803fe064 0 1 _start + + +#--- a.s +.global _start +.text +_start: + .section .nonalloc,"w" + .zero 0x1000 + +.section .intvec3,"ax",@progbits +.long 1 + +#--- a.lds +MEMORY { + MEM1 : ORIGIN = 0x10000000, LENGTH = 1M + MEM2 (rx) : ORIGIN = 0x80000000, LENGTH = 4M +} + +VEC_START = 0x803FE000; + +SECTIONS { + .nonalloc : { *(.nonalloc) } > MEM + .intvec0_out (VEC_START + 0x0000) : {KEEP (*(.intvec1)) } > MEM2 + .intvec1_out (VEC_START + 0x0020) : {KEEP (*(.intvec1)) } > MEM2 + .intvec2_out (VEC_START + 0x0040) : {KEEP (*(.intvec2)) } > MEM2 + .intvec3_out (VEC_START + 0x0060) : {KEEP (*(.intvec3)) } > MEM2 +} + + + +