[ELF] - Linkerscript: disallow discarding COMMON.
This patch restricts following construction:
/DISCARD/ : { *(COMMON) }
Previously LLD would crash.
Differential revision: https://reviews.llvm.org/D36468
llvm-svn: 310554
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 1fb787a..805d50b 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -319,8 +319,8 @@
void LinkerScript::discard(ArrayRef<InputSectionBase *> 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);
}
diff --git a/lld/test/ELF/linkerscript/discard-section-err.s b/lld/test/ELF/linkerscript/discard-section-err.s
index 5d99555..8796843 100644
--- a/lld/test/ELF/linkerscript/discard-section-err.s
+++ b/lld/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