[lld] r325875 - [ELF] - Report error if removed empty output section declaration used undefined symbols.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 23 02:15:55 PST 2018
Author: grimar
Date: Fri Feb 23 02:15:54 2018
New Revision: 325875
URL: http://llvm.org/viewvc/llvm-project?rev=325875&view=rev
Log:
[ELF] - Report error if removed empty output section declaration used undefined symbols.
This is for fixing PR36297.
Issue itself is that if we have SECTIONS { .bar (a+b) : { *(.stub) } };
script and no section .stub, when LLD will remove .bar, but
produce output with undefined symbols a and b.
Differential revision: https://reviews.llvm.org/D43069
Added:
lld/trunk/test/ELF/linkerscript/address-expr-symbols.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=325875&r1=325874&r2=325875&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Feb 23 02:15:54 2018
@@ -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;
Added: lld/trunk/test/ELF/linkerscript/address-expr-symbols.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/address-expr-symbols.s?rev=325875&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/address-expr-symbols.s (added)
+++ lld/trunk/test/ELF/linkerscript/address-expr-symbols.s Fri Feb 23 02:15:54 2018
@@ -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
More information about the llvm-commits
mailing list