summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/LinkerScript.cpp7
-rw-r--r--lld/test/ELF/linkerscript/address-expr-symbols.s15
2 files changed, 22 insertions, 0 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index e9ea4f84587..0426c503df0 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -767,6 +767,13 @@ void LinkerScript::removeEmptyCommands() {
}
static bool isAllSectionDescription(const OutputSection &Cmd) {
+ // We do not want to remove sections that have custom address or align
+ // expressions set even if them are empty. We keep them because we
+ // want to be sure that any expressions can be evaluated and report
+ // an error otherwise.
+ if (Cmd.AddrExpr || Cmd.AlignExpr || Cmd.LMAExpr)
+ return false;
+
for (BaseCommand *Base : Cmd.SectionCommands)
if (!isa<InputSectionDescription>(*Base))
return false;
diff --git a/lld/test/ELF/linkerscript/address-expr-symbols.s b/lld/test/ELF/linkerscript/address-expr-symbols.s
new file mode 100644
index 00000000000..0b76c91a5c8
--- /dev/null
+++ b/lld/test/ELF/linkerscript/address-expr-symbols.s
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+
+# RUN: echo "SECTIONS { .bar (foo) : { } };" > %t.script
+# RUN: not ld.lld -o %t --script %t.script %t.o 2>&1 | FileCheck %s
+# CHECK: symbol not found: foo
+
+# RUN: echo "SECTIONS { .bar : AT(foo) { } };" > %t.script
+# RUN: not ld.lld -o %t --script %t.script %t.o 2>&1 | FileCheck %s
+
+# RUN: echo "SECTIONS { .bar : ALIGN(foo) { } };" > %t.script
+# RUN: not ld.lld -o %t --script %t.script %t.o 2>&1 | FileCheck %s
+
+# RUN: echo "SECTIONS { .bar : SUBALIGN(foo) { } };" > %t.script
+# RUN: not ld.lld -o %t --script %t.script %t.o 2>&1 | FileCheck %s
OpenPOWER on IntegriCloud