[ELF] - Do not remove empty sections that use symbols in expressions.

This is PR36515.

Currenly if we have a script like .debug_info 0 : { *(.debug_info) },
we would not remove this section and keep it in the output.
That does not work, because it is common case for
debug sections to have a zero address expression.
Patch changes behavior so that we remove only sections
that do not use symbols in its expressions.

Differential revision: https://reviews.llvm.org/D43863

llvm-svn: 326430
This commit is contained in:
George Rimar
2018-03-01 12:27:04 +00:00
parent d1cf7ff5ab
commit c4df670dea
4 changed files with 27 additions and 5 deletions

View File

@@ -778,11 +778,10 @@ static bool isDiscardable(OutputSection &Sec) {
if (!Sec.Phdrs.empty())
return false;
// 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 (Sec.AddrExpr || Sec.AlignExpr || Sec.LMAExpr)
// We do not want to remove sections that reference symbols in address and
// other expressions. We add script symbols as undefined, and want to ensure
// all of them are defined in the output, hence have to keep them.
if (Sec.ExpressionsUseSymbols)
return false;
for (BaseCommand *Base : Sec.SectionCommands)