[lld] r287677 - [ELF] Allow `ASSERT` in output section descriptions

Meador Inge via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 22 10:01:50 PST 2016


Author: meadori
Date: Tue Nov 22 12:01:50 2016
New Revision: 287677

URL: http://llvm.org/viewvc/llvm-project?rev=287677&view=rev
Log:
[ELF] Allow `ASSERT` in output section descriptions

GNU LD allows `ASSERT` commands to be in output section descriptions.
Note that LD also mandates that `ASSERT` commands in this context must
end with a semicolon.

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/test/ELF/linkerscript/assert.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=287677&r1=287676&r2=287677&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Nov 22 12:01:50 2016
@@ -470,6 +470,11 @@ template <class ELFT> void LinkerScript<
     return;
   }
 
+  if (auto *AssertCmd = dyn_cast<AssertCommand>(&Base)) {
+    AssertCmd->Expression(Dot);
+    return;
+  }
+
   // It handles single input section description command,
   // calculates and assigns the offsets for each section and also
   // updates the output section size.
@@ -1413,18 +1418,22 @@ ScriptParser::readOutputSectionDescripti
 
   while (!Error && !consume("}")) {
     StringRef Tok = next();
-    if (SymbolAssignment *Assignment = readProvideOrAssignment(Tok))
+    if (SymbolAssignment *Assignment = readProvideOrAssignment(Tok)) {
       Cmd->Commands.emplace_back(Assignment);
-    else if (BytesDataCommand *Data = readBytesDataCommand(Tok))
+    } else if (BytesDataCommand *Data = readBytesDataCommand(Tok)) {
       Cmd->Commands.emplace_back(Data);
-    else if (Tok == "FILL")
+    } else if (Tok == "ASSERT") {
+      Cmd->Commands.emplace_back(new AssertCommand(readAssert()));
+      expect(";");
+    } else if (Tok == "FILL") {
       Cmd->Filler = readFill();
-    else if (Tok == "SORT")
+    } else if (Tok == "SORT") {
       readSort();
-    else if (peek() == "(")
+    } else if (peek() == "(") {
       Cmd->Commands.emplace_back(readInputSectionDescription(Tok));
-    else
+    } else {
       setError("unknown command " + Tok);
+    }
   }
   Cmd->Phdrs = readOutputSectionPhdrs();
 

Modified: lld/trunk/test/ELF/linkerscript/assert.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/assert.s?rev=287677&r1=287676&r2=287677&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/assert.s (original)
+++ lld/trunk/test/ELF/linkerscript/assert.s Tue Nov 22 12:01:50 2016
@@ -29,5 +29,15 @@
 # RUN: ld.lld -shared -o %t5 --script %t5.script %t1.o
 # RUN: llvm-readobj %t5 > /dev/null
 
+## Test assertions inside of output section decriptions.
+# RUN: echo "SECTIONS { .foo : { *(.foo) ASSERT(SIZEOF(.foo) == 8, \"true\"); } }" > %t6.script
+# RUN: ld.lld -shared -o %t6 --script %t6.script %t1.o
+# RUN: llvm-readobj %t6 > /dev/null
+
+# RUN: echo "SECTIONS { .foo : { ASSERT(1, \"true\") } }" > %t7.script
+# RUN: not ld.lld -shared -o %t7 --script %t7.script %t1.o > %t.log 2>&1
+# RUN: FileCheck %s -check-prefix=CHECK-SEMI < %t.log
+# CHECK-SEMI: error: {{.*}}.script:1: ; expected, but got }
+
 .section .foo, "a"
  .quad 0




More information about the llvm-commits mailing list