Don't crash on an empty section with an ALIGN.

llvm-svn: 308809
This commit is contained in:
Rafael Espindola 2017-07-22 00:00:51 +00:00
parent 6a963f76ca
commit ca5740d95a
2 changed files with 7 additions and 1 deletions

View File

@ -751,7 +751,7 @@ void LinkerScript::adjustSectionsAfterSorting() {
if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base)) { if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base)) {
Cmd->MemRegion = findMemoryRegion(Cmd); Cmd->MemRegion = findMemoryRegion(Cmd);
// Handle align (e.g. ".foo : ALIGN(16) { ... }"). // Handle align (e.g. ".foo : ALIGN(16) { ... }").
if (Cmd->AlignExpr) if (Cmd->AlignExpr && Cmd->Sec)
Cmd->Sec->updateAlignment(Cmd->AlignExpr().getValue()); Cmd->Sec->updateAlignment(Cmd->AlignExpr().getValue());
} }
} }

View File

@ -0,0 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: echo "SECTIONS { .foo : ALIGN(2M) { } }" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o -shared
# We would crash if an empty section had an ALIGN.