Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -319,8 +319,8 @@ void LinkerScript::discard(ArrayRef V) { for (InputSectionBase *S : V) { S->Live = false; - if (S == InX::ShStrTab || S == InX::Dynamic || S == InX::DynSymTab || - S == InX::DynStrTab) + if (S == InX::ShStrTab || S == InX::Common || S == InX::Dynamic || + S == InX::DynSymTab || S == InX::DynStrTab) error("discarding " + S->Name + " section is not allowed"); discard(S->DependentSections); } Index: lld/trunk/test/ELF/linkerscript/discard-section-err.s =================================================================== --- lld/trunk/test/ELF/linkerscript/discard-section-err.s +++ lld/trunk/test/ELF/linkerscript/discard-section-err.s @@ -21,3 +21,10 @@ # RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \ # RUN: FileCheck -check-prefix=DYNSTR %s # DYNSTR: discarding .dynstr section is not allowed + +# RUN: echo "SECTIONS { /DISCARD/ : { *(COMMON) } }" > %t.script +# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \ +# RUN: FileCheck -check-prefix=COMMON %s +# COMMON: discarding COMMON section is not allowed + +.comm foo,4,4