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(*Base)) return false; 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