aboutsummaryrefslogtreecommitdiffstats
path: root/ELF/MarkLive.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ELF/MarkLive.cpp')
-rw-r--r--ELF/MarkLive.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/ELF/MarkLive.cpp b/ELF/MarkLive.cpp
index 36b847f725b8..02ab6d18e537 100644
--- a/ELF/MarkLive.cpp
+++ b/ELF/MarkLive.cpp
@@ -37,11 +37,11 @@
using namespace llvm;
using namespace llvm::ELF;
using namespace llvm::object;
-using namespace llvm::support::endian;
-using namespace lld;
-using namespace lld::elf;
+namespace endian = llvm::support::endian;
+namespace lld {
+namespace elf {
namespace {
template <class ELFT> class MarkLive {
public:
@@ -141,7 +141,7 @@ void MarkLive<ELFT>::scanEhFrameSection(EhInputSection &eh,
if (firstRelI == (unsigned)-1)
continue;
- if (read32<ELFT::TargetEndianness>(piece.data().data() + 4) == 0) {
+ if (endian::read32<ELFT::TargetEndianness>(piece.data().data() + 4) == 0) {
// This is a CIE, we only need to worry about the first relocation. It is
// known to point to the personality function.
resolveReloc(eh, rels[firstRelI], false);
@@ -291,6 +291,10 @@ template <class ELFT> void MarkLive<ELFT>::mark() {
// GOT, which means that the ifunc must be available when the main partition is
// loaded) and TLS symbols (because we only know how to correctly process TLS
// relocations for the main partition).
+//
+// We also need to move sections whose names are C identifiers that are referred
+// to from __start_/__stop_ symbols because there will only be one set of
+// symbols for the whole program.
template <class ELFT> void MarkLive<ELFT>::moveToMain() {
for (InputFile *file : objectFiles)
for (Symbol *s : file->getSymbols())
@@ -299,13 +303,21 @@ template <class ELFT> void MarkLive<ELFT>::moveToMain() {
d->section->isLive())
markSymbol(s);
+ for (InputSectionBase *sec : inputSections) {
+ if (!sec->isLive() || !isValidCIdentifier(sec->name))
+ continue;
+ if (symtab->find(("__start_" + sec->name).str()) ||
+ symtab->find(("__stop_" + sec->name).str()))
+ enqueue(sec, 0);
+ }
+
mark();
}
// Before calling this function, Live bits are off for all
// input sections. This function make some or all of them on
// so that they are emitted to the output file.
-template <class ELFT> void elf::markLive() {
+template <class ELFT> void markLive() {
// If -gc-sections is not given, no sections are removed.
if (!config->gcSections) {
for (InputSectionBase *sec : inputSections)
@@ -367,7 +379,10 @@ template <class ELFT> void elf::markLive() {
message("removing unused section " + toString(sec));
}
-template void elf::markLive<ELF32LE>();
-template void elf::markLive<ELF32BE>();
-template void elf::markLive<ELF64LE>();
-template void elf::markLive<ELF64BE>();
+template void markLive<ELF32LE>();
+template void markLive<ELF32BE>();
+template void markLive<ELF64LE>();
+template void markLive<ELF64BE>();
+
+} // namespace elf
+} // namespace lld