Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -470,6 +470,11 @@ return; } + if (auto *AssertCmd = dyn_cast(&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 @@ 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(); Index: test/ELF/linkerscript/assert.s =================================================================== --- test/ELF/linkerscript/assert.s +++ test/ELF/linkerscript/assert.s @@ -29,5 +29,20 @@ # 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 { \ +# RUN: .foo : { \ +# RUN: *(.foo) \ +# RUN: ASSERT(SIZEOF(.foo) == 8, \"true\"); \ +# RUN: } \ +# RUN: }" > %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