[PATCH] D43069: [ELF] - Report error if removed empty output section declaration used undefined symbols.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 9 08:29:39 PST 2018


grimar updated this revision to Diff 133625.
grimar added a comment.

- Reimplemented to keep output sections with custom address/align expressions alive in `isAllSectionDescription`.


https://reviews.llvm.org/D43069

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/address-expr-symbols.s


Index: test/ELF/linkerscript/address-expr-symbols.s
===================================================================
--- test/ELF/linkerscript/address-expr-symbols.s
+++ 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
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -765,6 +765,13 @@
 }
 
 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 still
+  // 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43069.133625.patch
Type: text/x-patch
Size: 1557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180209/7fd7427e/attachment.bin>


More information about the llvm-commits mailing list