From 3cdf0d969a81bd0b293eda328a99e8cdfa272d74 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 23 Feb 2018 10:15:54 +0000 Subject: [ELF] - Report error if removed empty output section declaration used undefined symbols. This is for fixing PR36297. Issue itself is that if we have SECTIONS { .bar (a+b) : { *(.stub) } }; script and no section .stub, when LLD will remove .bar, but produce output with undefined symbols a and b. Differential revision: https://reviews.llvm.org/D43069 llvm-svn: 325875 --- lld/ELF/LinkerScript.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lld/ELF/LinkerScript.cpp') diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index e9ea4f84587..0426c503df0 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -767,6 +767,13 @@ void LinkerScript::removeEmptyCommands() { } 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 we + // 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; -- cgit v1.2.3