aboutsummaryrefslogtreecommitdiffstats
path: root/ELF/MarkLive.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:45 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:45 +0000
commitd2bd9e70b16db88a7808ee2280b0a107afbfdd3b (patch)
tree12612d2c593445b297ac656911c9db7cf9065bdd /ELF/MarkLive.cpp
parentf1e1c239e31b467e17f1648b1f524fc9ab5b431a (diff)
downloadsrc-vendor/lld.tar.gz
src-vendor/lld.zip
Vendor import of stripped lld trunk r375505, the last commit before thevendor/lld/lld-trunk-r375505vendor/lld
upstream Subversion repository was made read-only, and the LLVM project migrated to GitHub: https://llvm.org/svn/llvm-project/lld/trunk@375505
Notes
Notes: svn path=/vendor/lld/dist/; revision=353950 svn path=/vendor/lld/lld-r375505/; revision=353951; tag=vendor/lld/lld-trunk-r375505
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