[lld] r291984 - Split writeMapFile2 to reduce indentation level.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 13 16:37:28 PST 2017
Author: ruiu
Date: Fri Jan 13 18:37:28 2017
New Revision: 291984
URL: http://llvm.org/viewvc/llvm-project?rev=291984&view=rev
Log:
Split writeMapFile2 to reduce indentation level.
Modified:
lld/trunk/ELF/MapFile.cpp
Modified: lld/trunk/ELF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.cpp?rev=291984&r1=291983&r2=291984&view=diff
==============================================================================
--- lld/trunk/ELF/MapFile.cpp (original)
+++ lld/trunk/ELF/MapFile.cpp Fri Jan 13 18:37:28 2017
@@ -62,49 +62,57 @@ static void writeSymbolLine(raw_fd_ostre
}
template <class ELFT>
+static void writeInputSection(raw_fd_ostream &OS, const InputSection<ELFT> *IS,
+ StringRef &PrevName) {
+ int Width = ELFT::Is64Bits ? 16 : 8;
+ StringRef Name = IS->Name;
+ if (Name != PrevName) {
+ writeInSecLine(OS, Width, IS->OutSec->Addr + IS->OutSecOff, IS->getSize(),
+ IS->Alignment, Name);
+ OS << '\n';
+ PrevName = Name;
+ }
+
+ elf::ObjectFile<ELFT> *File = IS->getFile();
+ if (!File)
+ return;
+ writeFileLine(OS, Width, IS->OutSec->Addr + IS->OutSecOff, IS->getSize(),
+ IS->Alignment, toString(File));
+ OS << '\n';
+
+ for (SymbolBody *Sym : File->getSymbols()) {
+ auto *DR = dyn_cast<DefinedRegular<ELFT>>(Sym);
+ if (!DR)
+ continue;
+ if (DR->Section != IS)
+ continue;
+ if (DR->isSection())
+ continue;
+ writeSymbolLine(OS, Width, Sym->getVA<ELFT>(), Sym->getSize<ELFT>(),
+ toString(*Sym));
+ OS << '\n';
+ }
+}
+
+template <class ELFT>
static void writeMapFile2(int FD,
ArrayRef<OutputSectionBase *> OutputSections) {
- typedef typename ELFT::uint uintX_t;
raw_fd_ostream OS(FD, true);
int Width = ELFT::Is64Bits ? 16 : 8;
+
OS << left_justify("Address", Width) << ' ' << left_justify("Size", Width)
<< ' ' << left_justify("Align", 5) << ' ' << left_justify("Out", 7) << ' '
<< left_justify("In", 7) << ' ' << left_justify("File", 7) << " Symbol\n";
+
for (OutputSectionBase *Sec : OutputSections) {
- uintX_t VA = Sec->Addr;
- writeOutSecLine(OS, Width, VA, Sec->Size, Sec->Addralign, Sec->getName());
+ writeOutSecLine(OS, Width, Sec->Addr, Sec->Size, Sec->Addralign,
+ Sec->getName());
OS << '\n';
+
StringRef PrevName = "";
Sec->forEachInputSection([&](InputSectionData *S) {
- const auto *IS = dyn_cast<InputSection<ELFT>>(S);
- if (!IS)
- return;
- StringRef Name = IS->Name;
- if (Name != PrevName) {
- writeInSecLine(OS, Width, VA + IS->OutSecOff, IS->getSize(),
- IS->Alignment, Name);
- OS << '\n';
- PrevName = Name;
- }
- elf::ObjectFile<ELFT> *File = IS->getFile();
- if (!File)
- return;
- writeFileLine(OS, Width, VA + IS->OutSecOff, IS->getSize(), IS->Alignment,
- toString(File));
- OS << '\n';
- ArrayRef<SymbolBody *> Syms = File->getSymbols();
- for (SymbolBody *Sym : Syms) {
- auto *DR = dyn_cast<DefinedRegular<ELFT>>(Sym);
- if (!DR)
- continue;
- if (DR->Section != IS)
- continue;
- if (DR->isSection())
- continue;
- writeSymbolLine(OS, Width, Sym->getVA<ELFT>(), Sym->getSize<ELFT>(),
- toString(*Sym));
- OS << '\n';
- }
+ if (const auto *IS = dyn_cast<InputSection<ELFT>>(S))
+ writeInputSection(OS, IS, PrevName);
});
}
}
More information about the llvm-commits
mailing list