aboutsummaryrefslogtreecommitdiff
path: root/ELF/MapFile.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:32 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:32 +0000
commitf1e1c239e31b467e17f1648b1f524fc9ab5b431a (patch)
treea855e7a2a8808555da60e6aa9601d6867eb23bac /ELF/MapFile.cpp
parent7d6988fdd2aee0e033034e147f16fe05594a60e4 (diff)
downloadsrc-f1e1c239e31b467e17f1648b1f524fc9ab5b431a.tar.gz
src-f1e1c239e31b467e17f1648b1f524fc9ab5b431a.zip
Vendor import of stripped lld trunk r366426 (just before the release_90vendor/lld/lld-trunk-r366426
Notes
Notes: svn path=/vendor/lld/dist/; revision=351288 svn path=/vendor/lld/lld-trunk-r366426/; revision=351289; tag=vendor/lld/lld-trunk-r366426
Diffstat (limited to 'ELF/MapFile.cpp')
-rw-r--r--ELF/MapFile.cpp234
1 files changed, 116 insertions, 118 deletions
diff --git a/ELF/MapFile.cpp b/ELF/MapFile.cpp
index b0dc6203008d..a4a6238fc655 100644
--- a/ELF/MapFile.cpp
+++ b/ELF/MapFile.cpp
@@ -1,9 +1,8 @@
//===- MapFile.cpp --------------------------------------------------------===//
//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
@@ -38,69 +37,67 @@ using namespace llvm::object;
using namespace lld;
using namespace lld::elf;
-typedef DenseMap<const SectionBase *, SmallVector<Defined *, 4>> SymbolMapTy;
+using SymbolMapTy = DenseMap<const SectionBase *, SmallVector<Defined *, 4>>;
-static const std::string Indent8 = " "; // 8 spaces
-static const std::string Indent16 = " "; // 16 spaces
+static const std::string indent8 = " "; // 8 spaces
+static const std::string indent16 = " "; // 16 spaces
// Print out the first three columns of a line.
-static void writeHeader(raw_ostream &OS, uint64_t VMA, uint64_t LMA,
- uint64_t Size, uint64_t Align) {
- if (Config->Is64)
- OS << format("%16llx %16llx %8llx %5lld ", VMA, LMA, Size, Align);
+static void writeHeader(raw_ostream &os, uint64_t vma, uint64_t lma,
+ uint64_t size, uint64_t align) {
+ if (config->is64)
+ os << format("%16llx %16llx %8llx %5lld ", vma, lma, size, align);
else
- OS << format("%8llx %8llx %8llx %5lld ", VMA, LMA, Size, Align);
+ os << format("%8llx %8llx %8llx %5lld ", vma, lma, size, align);
}
// Returns a list of all symbols that we want to print out.
static std::vector<Defined *> getSymbols() {
- std::vector<Defined *> V;
- for (InputFile *File : ObjectFiles)
- for (Symbol *B : File->getSymbols())
- if (auto *DR = dyn_cast<Defined>(B))
- if (!DR->isSection() && DR->Section && DR->Section->Live &&
- (DR->File == File || DR->NeedsPltAddr || DR->Section->Bss))
- V.push_back(DR);
- return V;
+ std::vector<Defined *> v;
+ for (InputFile *file : objectFiles)
+ for (Symbol *b : file->getSymbols())
+ if (auto *dr = dyn_cast<Defined>(b))
+ if (!dr->isSection() && dr->section && dr->section->isLive() &&
+ (dr->file == file || dr->needsPltAddr || dr->section->bss))
+ v.push_back(dr);
+ return v;
}
// Returns a map from sections to their symbols.
-static SymbolMapTy getSectionSyms(ArrayRef<Defined *> Syms) {
- SymbolMapTy Ret;
- for (Defined *DR : Syms)
- Ret[DR->Section].push_back(DR);
+static SymbolMapTy getSectionSyms(ArrayRef<Defined *> syms) {
+ SymbolMapTy ret;
+ for (Defined *dr : syms)
+ ret[dr->section].push_back(dr);
// Sort symbols by address. We want to print out symbols in the
// order in the output file rather than the order they appeared
// in the input files.
- for (auto &It : Ret) {
- SmallVectorImpl<Defined *> &V = It.second;
- std::stable_sort(V.begin(), V.end(), [](Defined *A, Defined *B) {
- return A->getVA() < B->getVA();
+ for (auto &it : ret)
+ llvm::stable_sort(it.second, [](Defined *a, Defined *b) {
+ return a->getVA() < b->getVA();
});
- }
- return Ret;
+ return ret;
}
// Construct a map from symbols to their stringified representations.
// Demangling symbols (which is what toString() does) is slow, so
// we do that in batch using parallel-for.
static DenseMap<Symbol *, std::string>
-getSymbolStrings(ArrayRef<Defined *> Syms) {
- std::vector<std::string> Str(Syms.size());
- parallelForEachN(0, Syms.size(), [&](size_t I) {
- raw_string_ostream OS(Str[I]);
- OutputSection *OSec = Syms[I]->getOutputSection();
- uint64_t VMA = Syms[I]->getVA();
- uint64_t LMA = OSec ? OSec->getLMA() + VMA - OSec->getVA(0) : 0;
- writeHeader(OS, VMA, LMA, Syms[I]->getSize(), 1);
- OS << Indent16 << toString(*Syms[I]);
+getSymbolStrings(ArrayRef<Defined *> syms) {
+ std::vector<std::string> str(syms.size());
+ parallelForEachN(0, syms.size(), [&](size_t i) {
+ raw_string_ostream os(str[i]);
+ OutputSection *osec = syms[i]->getOutputSection();
+ uint64_t vma = syms[i]->getVA();
+ uint64_t lma = osec ? osec->getLMA() + vma - osec->getVA(0) : 0;
+ writeHeader(os, vma, lma, syms[i]->getSize(), 1);
+ os << indent16 << toString(*syms[i]);
});
- DenseMap<Symbol *, std::string> Ret;
- for (size_t I = 0, E = Syms.size(); I < E; ++I)
- Ret[Syms[I]] = std::move(Str[I]);
- return Ret;
+ DenseMap<Symbol *, std::string> ret;
+ for (size_t i = 0, e = syms.size(); i < e; ++i)
+ ret[syms[i]] = std::move(str[i]);
+ return ret;
}
// Print .eh_frame contents. Since the section consists of EhSectionPieces,
@@ -109,114 +106,115 @@ getSymbolStrings(ArrayRef<Defined *> Syms) {
// .eh_frame tend to contain a lot of section pieces that are contiguous
// both in input file and output file. Such pieces are squashed before
// being displayed to make output compact.
-static void printEhFrame(raw_ostream &OS, OutputSection *OSec) {
- std::vector<EhSectionPiece> Pieces;
+static void printEhFrame(raw_ostream &os, const EhFrameSection *sec) {
+ std::vector<EhSectionPiece> pieces;
- auto Add = [&](const EhSectionPiece &P) {
+ auto add = [&](const EhSectionPiece &p) {
// If P is adjacent to Last, squash the two.
- if (!Pieces.empty()) {
- EhSectionPiece &Last = Pieces.back();
- if (Last.Sec == P.Sec && Last.InputOff + Last.Size == P.InputOff &&
- Last.OutputOff + Last.Size == P.OutputOff) {
- Last.Size += P.Size;
+ if (!pieces.empty()) {
+ EhSectionPiece &last = pieces.back();
+ if (last.sec == p.sec && last.inputOff + last.size == p.inputOff &&
+ last.outputOff + last.size == p.outputOff) {
+ last.size += p.size;
return;
}
}
- Pieces.push_back(P);
+ pieces.push_back(p);
};
// Gather section pieces.
- for (const CieRecord *Rec : In.EhFrame->getCieRecords()) {
- Add(*Rec->Cie);
- for (const EhSectionPiece *Fde : Rec->Fdes)
- Add(*Fde);
+ for (const CieRecord *rec : sec->getCieRecords()) {
+ add(*rec->cie);
+ for (const EhSectionPiece *fde : rec->fdes)
+ add(*fde);
}
// Print out section pieces.
- for (EhSectionPiece &P : Pieces) {
- writeHeader(OS, OSec->Addr + P.OutputOff, OSec->getLMA() + P.OutputOff,
- P.Size, 1);
- OS << Indent8 << toString(P.Sec->File) << ":(" << P.Sec->Name << "+0x"
- << Twine::utohexstr(P.InputOff) + ")\n";
+ const OutputSection *osec = sec->getOutputSection();
+ for (EhSectionPiece &p : pieces) {
+ writeHeader(os, osec->addr + p.outputOff, osec->getLMA() + p.outputOff,
+ p.size, 1);
+ os << indent8 << toString(p.sec->file) << ":(" << p.sec->name << "+0x"
+ << Twine::utohexstr(p.inputOff) + ")\n";
}
}
void elf::writeMapFile() {
- if (Config->MapFile.empty())
+ if (config->mapFile.empty())
return;
// Open a map file for writing.
- std::error_code EC;
- raw_fd_ostream OS(Config->MapFile, EC, sys::fs::F_None);
- if (EC) {
- error("cannot open " + Config->MapFile + ": " + EC.message());
+ std::error_code ec;
+ raw_fd_ostream os(config->mapFile, ec, sys::fs::F_None);
+ if (ec) {
+ error("cannot open " + config->mapFile + ": " + ec.message());
return;
}
// Collect symbol info that we want to print out.
- std::vector<Defined *> Syms = getSymbols();
- SymbolMapTy SectionSyms = getSectionSyms(Syms);
- DenseMap<Symbol *, std::string> SymStr = getSymbolStrings(Syms);
+ std::vector<Defined *> syms = getSymbols();
+ SymbolMapTy sectionSyms = getSectionSyms(syms);
+ DenseMap<Symbol *, std::string> symStr = getSymbolStrings(syms);
// Print out the header line.
- int W = Config->Is64 ? 16 : 8;
- OS << right_justify("VMA", W) << ' ' << right_justify("LMA", W)
+ int w = config->is64 ? 16 : 8;
+ os << right_justify("VMA", w) << ' ' << right_justify("LMA", w)
<< " 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)
+ OutputSection* osec = nullptr;
+ for (BaseCommand *base : script->sectionCommands) {
+ if (auto *cmd = dyn_cast<SymbolAssignment>(base)) {
+ if (cmd->provide && !cmd->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() + cmd->addr - osec->getVA(0) : 0;
+ writeHeader(os, cmd->addr, lma, cmd->size, 1);
+ os << cmd->commandString << '\n';
continue;
}
- OSec = cast<OutputSection>(Base);
- writeHeader(OS, OSec->Addr, OSec->getLMA(), OSec->Size, OSec->Alignment);
- OS << OSec->Name << '\n';
+ osec = cast<OutputSection>(base);
+ 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 (InputSection *IS : ISD->Sections) {
- if (IS == In.EhFrame) {
- printEhFrame(OS, OSec);
+ for (BaseCommand *base : osec->sectionCommands) {
+ if (auto *isd = dyn_cast<InputSectionDescription>(base)) {
+ for (InputSection *isec : isd->sections) {
+ if (auto *ehSec = dyn_cast<EhFrameSection>(isec)) {
+ printEhFrame(os, ehSec);
continue;
}
- writeHeader(OS, IS->getVA(0), OSec->getLMA() + IS->getOffset(0),
- IS->getSize(), IS->Alignment);
- OS << Indent8 << toString(IS) << '\n';
- for (Symbol *Sym : SectionSyms[IS])
- OS << SymStr[Sym] << '\n';
+ writeHeader(os, isec->getVA(0), osec->getLMA() + isec->getOffset(0),
+ isec->getSize(), isec->alignment);
+ os << indent8 << toString(isec) << '\n';
+ for (Symbol *sym : sectionSyms[isec])
+ os << symStr[sym] << '\n';
}
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 *cmd = dyn_cast<ByteCommand>(base)) {
+ writeHeader(os, osec->addr + cmd->offset, osec->getLMA() + cmd->offset,
+ cmd->size, 1);
+ os << indent8 << cmd->commandString << '\n';
continue;
}
- if (auto *Cmd = dyn_cast<SymbolAssignment>(Base)) {
- if (Cmd->Provide && !Cmd->Sym)
+ if (auto *cmd = dyn_cast<SymbolAssignment>(base)) {
+ if (cmd->provide && !cmd->sym)
continue;
- writeHeader(OS, Cmd->Addr, OSec->getLMA() + Cmd->Addr - OSec->getVA(0),
- Cmd->Size, 1);
- OS << Indent8 << Cmd->CommandString << '\n';
+ writeHeader(os, cmd->addr, osec->getLMA() + cmd->addr - osec->getVA(0),
+ cmd->size, 1);
+ os << indent8 << cmd->commandString << '\n';
continue;
}
}
}
}
-static void print(StringRef A, StringRef B) {
- outs() << left_justify(A, 49) << " " << B << "\n";
+static void print(StringRef a, StringRef b) {
+ outs() << left_justify(a, 49) << " " << b << "\n";
}
// Output a cross reference table to stdout. This is for --cref.
@@ -231,18 +229,18 @@ 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)
+ if (!config->cref)
return;
// Collect symbols and files.
- MapVector<Symbol *, SetVector<InputFile *>> Map;
- for (InputFile *File : ObjectFiles) {
- for (Symbol *Sym : File->getSymbols()) {
- if (isa<SharedSymbol>(Sym))
- Map[Sym].insert(File);
- if (auto *D = dyn_cast<Defined>(Sym))
- if (!D->isLocal() && (!D->Section || D->Section->Live))
- Map[D].insert(File);
+ MapVector<Symbol *, SetVector<InputFile *>> map;
+ for (InputFile *file : objectFiles) {
+ for (Symbol *sym : file->getSymbols()) {
+ if (isa<SharedSymbol>(sym))
+ map[sym].insert(file);
+ if (auto *d = dyn_cast<Defined>(sym))
+ if (!d->isLocal() && (!d->section || d->section->isLive()))
+ map[d].insert(file);
}
}
@@ -251,13 +249,13 @@ void elf::writeCrossReferenceTable() {
print("Symbol", "File");
// Print out a table.
- for (auto KV : Map) {
- Symbol *Sym = KV.first;
- SetVector<InputFile *> &Files = KV.second;
+ for (auto kv : map) {
+ Symbol *sym = kv.first;
+ SetVector<InputFile *> &files = kv.second;
- print(toString(*Sym), toString(Sym->File));
- for (InputFile *File : Files)
- if (File != Sym->File)
- print("", toString(File));
+ print(toString(*sym), toString(sym->file));
+ for (InputFile *file : files)
+ if (file != sym->file)
+ print("", toString(file));
}
}