Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -886,7 +886,8 @@ // in case it is empty. bool IsEmpty = getInputSections(Sec).empty(); if (IsEmpty) - Sec->Flags = Flags & (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR); + Sec->Flags = + Flags & ((Sec->NonAlloc ? 0 : SHF_ALLOC) | SHF_WRITE | SHF_EXECINSTR); if (IsEmpty && isDiscardable(*Sec)) { Sec->Live = false; Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -752,6 +752,7 @@ } else { skip(); // This is "COPY", "INFO" or "OVERLAY". Cmd->NonAlloc = true; + Cmd->Type = SHT_PROGBITS; } expect(")"); return true; Index: test/ELF/linkerscript/info-section-type.s =================================================================== --- test/ELF/linkerscript/info-section-type.s +++ test/ELF/linkerscript/info-section-type.s @@ -29,6 +29,10 @@ # RUN: ld.lld -o %t --script %t.script %t.o # RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC +# RUN: echo "SECTIONS { .bar (INFO) : { . += 1; } };" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC + # RUN: echo "SECTIONS { .bar 0x20000 (INFO) : { *(.foo) } };" > %t.script # RUN: ld.lld -o %t --script %t.script %t.o # RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC