summaryrefslogtreecommitdiffstats
path: root/lld/ELF/OutputSections.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2018-02-26 22:32:15 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2018-02-26 22:32:15 +0000
commit79c23eec04499933479874c0b06bc8d51914bde4 (patch)
tree49d9331cefbdcca8e14834cc8b2d514cec1df20a /lld/ELF/OutputSections.cpp
parent6dcbc1dbb387cf465090cffece6fccc1564233ab (diff)
downloadbcm5719-llvm-79c23eec04499933479874c0b06bc8d51914bde4.tar.gz
bcm5719-llvm-79c23eec04499933479874c0b06bc8d51914bde4.zip
Keep flags from phantom synthetic sections.
This fixes pr36475. I think this code can be simplified a bit, but I would like to check in the more direct fix if we are in agreement on the direction and then refactor. This is not something that bfd does. The issue is not noticed in bfd because it keeps fewer sections from the linkerscript in the output. The reasons why it seems reasonable to do this: - As George noticed, we would still keep the flags if the output section had both an empty synthetic section and a regular section - We need an heuristic to find the flags of output sections. Using the flags of a synthetic section that would have been there seems a reasonable heuristic. llvm-svn: 326137
Diffstat (limited to 'lld/ELF/OutputSections.cpp')
-rw-r--r--lld/ELF/OutputSections.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 6a893f03e85..4facba60e9e 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -76,6 +76,25 @@ OutputSection::OutputSection(StringRef Name, uint32_t Type, uint64_t Flags)
Live = false;
}
+bool OutputSection::isAllSectionDescription() const {
+ // We do not remove empty sections that are explicitly
+ // assigned to any segment.
+ if (!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 (AddrExpr || AlignExpr || LMAExpr)
+ return false;
+
+ for (BaseCommand *Base : SectionCommands)
+ if (!isa<InputSectionDescription>(*Base))
+ return false;
+ return true;
+}
+
// We allow sections of types listed below to merged into a
// single progbits section. This is typically done by linker
// scripts. Merging nobits and progbits will force disk space
OpenPOWER on IntegriCloud