diff options
Diffstat (limited to 'lld/MachO/MapFile.cpp')
| -rw-r--r-- | lld/MachO/MapFile.cpp | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp index 93abea2ed08b..8f9381ff0d79 100644 --- a/lld/MachO/MapFile.cpp +++ b/lld/MachO/MapFile.cpp @@ -40,18 +40,32 @@ using namespace llvm::sys; using namespace lld; using namespace lld::macho; -// Returns a list of all symbols that we want to print out. -static std::vector<Defined *> getSymbols() { - std::vector<Defined *> v; +using Symbols = std::vector<Defined *>; +// Returns a pair where the left element is a container of all live Symbols and +// the right element is a container of all dead symbols. +static std::pair<Symbols, Symbols> getSymbols() { + Symbols liveSymbols, deadSymbols; for (InputFile *file : inputFiles) if (isa<ObjFile>(file)) for (Symbol *sym : file->symbols) if (auto *d = dyn_cast_or_null<Defined>(sym)) - if (d->isLive() && d->isec && d->getFile() == file) { - assert(!shouldOmitFromOutput(d->isec)); - v.push_back(d); + if (d->isec && d->getFile() == file) { + if (d->isLive()) { + assert(!shouldOmitFromOutput(d->isec)); + liveSymbols.push_back(d); + } else { + deadSymbols.push_back(d); + } } - return v; + parallelSort(liveSymbols.begin(), liveSymbols.end(), + [](Defined *a, Defined *b) { + return a->getVA() != b->getVA() ? a->getVA() < b->getVA() + : a->getName() < b->getName(); + }); + parallelSort( + deadSymbols.begin(), deadSymbols.end(), + [](Defined *a, Defined *b) { return a->getName() < b->getName(); }); + return {std::move(liveSymbols), std::move(deadSymbols)}; } // Construct a map from symbols to their stringified representations. @@ -104,14 +118,6 @@ void macho::writeMapFile() { } } - // Collect symbol info that we want to print out. - std::vector<Defined *> syms = getSymbols(); - parallelSort(syms.begin(), syms.end(), [](Defined *a, Defined *b) { - return a->getVA() != b->getVA() ? a->getVA() < b->getVA() - : a->getName() < b->getName(); - }); - DenseMap<Symbol *, std::string> symStr = getSymbolStrings(syms); - // Dump table of sections os << "# Sections:\n"; os << "# Address\tSize \tSegment\tSection\n"; @@ -125,12 +131,29 @@ void macho::writeMapFile() { } // Dump table of symbols + Symbols liveSymbols, deadSymbols; + std::tie(liveSymbols, deadSymbols) = getSymbols(); + + DenseMap<Symbol *, std::string> liveSymbolStrings = + getSymbolStrings(liveSymbols); os << "# Symbols:\n"; os << "# Address\t File Name\n"; - for (Symbol *sym : syms) { + for (Symbol *sym : liveSymbols) { + assert(sym->isLive()); os << format("0x%08llX\t[%3u] %s\n", sym->getVA(), - readerToFileOrdinal[sym->getFile()], symStr[sym].c_str()); + readerToFileOrdinal[sym->getFile()], + liveSymbolStrings[sym].c_str()); } - // TODO: when we implement -dead_strip, we should dump dead stripped symbols + if (config->deadStrip) { + DenseMap<Symbol *, std::string> deadSymbolStrings = + getSymbolStrings(deadSymbols); + os << "# Dead Stripped Symbols:\n"; + os << "# Address\t File Name\n"; + for (Symbol *sym : deadSymbols) { + assert(!sym->isLive()); + os << format("<<dead>>\t[%3u] %s\n", readerToFileOrdinal[sym->getFile()], + deadSymbolStrings[sym].c_str()); + } + } } |
