diff options
Diffstat (limited to 'lld/ELF/MapFile.cpp')
| -rw-r--r-- | lld/ELF/MapFile.cpp | 96 |
1 files changed, 51 insertions, 45 deletions
diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp index c4690ae5aefd..06735802f7f1 100644 --- a/lld/ELF/MapFile.cpp +++ b/lld/ELF/MapFile.cpp @@ -139,20 +139,7 @@ static void printEhFrame(raw_ostream &os, const EhFrameSection *sec) { } } -void elf::writeMapFile() { - if (config->mapFile.empty()) - return; - - llvm::TimeTraceScope timeScope("Write map file"); - - // Open a map file for writing. - std::error_code ec; - raw_fd_ostream os(config->mapFile, ec, sys::fs::OF_None); - if (ec) { - error("cannot open " + config->mapFile + ": " + ec.message()); - return; - } - +static void writeMapFile(raw_fd_ostream &os) { // Collect symbol info that we want to print out. std::vector<Defined *> syms = getSymbols(); SymbolMapTy sectionSyms = getSectionSyms(syms); @@ -164,30 +151,30 @@ void elf::writeMapFile() { << " Size Align Out In Symbol\n"; OutputSection* osec = nullptr; - for (BaseCommand *base : script->sectionCommands) { - if (auto *cmd = dyn_cast<SymbolAssignment>(base)) { - if (cmd->provide && !cmd->sym) + for (SectionCommand *cmd : script->sectionCommands) { + if (auto *assign = dyn_cast<SymbolAssignment>(cmd)) { + if (assign->provide && !assign->sym) continue; - uint64_t lma = osec ? osec->getLMA() + cmd->addr - osec->getVA(0) : 0; - writeHeader(os, cmd->addr, lma, cmd->size, 1); - os << cmd->commandString << '\n'; + uint64_t lma = osec ? osec->getLMA() + assign->addr - osec->getVA(0) : 0; + writeHeader(os, assign->addr, lma, assign->size, 1); + os << assign->commandString << '\n'; continue; } - osec = cast<OutputSection>(base); + osec = cast<OutputSection>(cmd); writeHeader(os, osec->addr, osec->getLMA(), osec->size, osec->alignment); os << osec->name << '\n'; // Dump symbols for each input section. - for (BaseCommand *base : osec->sectionCommands) { - if (auto *isd = dyn_cast<InputSectionDescription>(base)) { + for (SectionCommand *subCmd : osec->commands) { + if (auto *isd = dyn_cast<InputSectionDescription>(subCmd)) { for (InputSection *isec : isd->sections) { if (auto *ehSec = dyn_cast<EhFrameSection>(isec)) { printEhFrame(os, ehSec); continue; } - writeHeader(os, isec->getVA(0), osec->getLMA() + isec->getOffset(0), + writeHeader(os, isec->getVA(), osec->getLMA() + isec->outSecOff, isec->getSize(), isec->alignment); os << indent8 << toString(isec) << '\n'; for (Symbol *sym : sectionSyms[isec]) @@ -196,19 +183,20 @@ void elf::writeMapFile() { continue; } - if (auto *cmd = dyn_cast<ByteCommand>(base)) { - writeHeader(os, osec->addr + cmd->offset, osec->getLMA() + cmd->offset, - cmd->size, 1); - os << indent8 << cmd->commandString << '\n'; + if (auto *data = dyn_cast<ByteCommand>(subCmd)) { + writeHeader(os, osec->addr + data->offset, + osec->getLMA() + data->offset, data->size, 1); + os << indent8 << data->commandString << '\n'; continue; } - if (auto *cmd = dyn_cast<SymbolAssignment>(base)) { - if (cmd->provide && !cmd->sym) + if (auto *assign = dyn_cast<SymbolAssignment>(subCmd)) { + if (assign->provide && !assign->sym) continue; - writeHeader(os, cmd->addr, osec->getLMA() + cmd->addr - osec->getVA(0), - cmd->size, 1); - os << indent8 << cmd->commandString << '\n'; + writeHeader(os, assign->addr, + osec->getLMA() + assign->addr - osec->getVA(0), + assign->size, 1); + os << indent8 << assign->commandString << '\n'; continue; } } @@ -234,10 +222,6 @@ void elf::writeWhyExtract() { } } -static void print(StringRef a, StringRef b) { - lld::outs() << left_justify(a, 49) << " " << b << "\n"; -} - // Output a cross reference table to stdout. This is for --cref. // // For each global symbol, we print out a file that defines the symbol @@ -249,10 +233,7 @@ static void print(StringRef a, StringRef b) { // // In this case, strlen is defined by libc.so.6 and used by other two // files. -void elf::writeCrossReferenceTable() { - if (!config->cref) - return; - +static void writeCref(raw_fd_ostream &os) { // Collect symbols and files. MapVector<Symbol *, SetVector<InputFile *>> map; for (InputFile *file : objectFiles) { @@ -265,8 +246,12 @@ void elf::writeCrossReferenceTable() { } } - // Print out a header. - lld::outs() << "Cross Reference Table\n\n"; + auto print = [&](StringRef a, StringRef b) { + os << left_justify(a, 49) << ' ' << b << '\n'; + }; + + // Print a blank line and a header. The format matches GNU ld. + os << "\nCross Reference Table\n\n"; print("Symbol", "File"); // Print out a table. @@ -281,6 +266,27 @@ void elf::writeCrossReferenceTable() { } } +void elf::writeMapAndCref() { + if (config->mapFile.empty() && !config->cref) + return; + + llvm::TimeTraceScope timeScope("Write map file"); + + // Open a map file for writing. + std::error_code ec; + StringRef mapFile = config->mapFile.empty() ? "-" : config->mapFile; + raw_fd_ostream os(mapFile, ec, sys::fs::OF_None); + if (ec) { + error("cannot open " + mapFile + ": " + ec.message()); + return; + } + + if (!config->mapFile.empty()) + writeMapFile(os); + if (config->cref) + writeCref(os); +} + void elf::writeArchiveStats() { if (config->printArchiveStats.empty()) return; @@ -293,8 +299,8 @@ void elf::writeArchiveStats() { return; } - os << "members\tfetched\tarchive\n"; + os << "members\textracted\tarchive\n"; for (const ArchiveFile *f : archiveFiles) - os << f->getMemberCount() << '\t' << f->getFetchedMemberCount() << '\t' + os << f->getMemberCount() << '\t' << f->getExtractedMemberCount() << '\t' << f->getName() << '\n'; } |
