mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-14 17:34:41 +00:00
Dump sections. Extracted from a patch by Sami Liedes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171304 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
41be2fb1f9
commit
fc73847d8f
@ -53,6 +53,24 @@ ELF: global_func FUNC {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-
|
||||
ELF: _edata ? {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} global,absolute
|
||||
ELF: Total: {{[0-9a-f]+}}
|
||||
|
||||
ELF:Sections:
|
||||
ELF: Name Address Size Align Flags
|
||||
ELF: {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata
|
||||
ELF: .hash {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required,rodata
|
||||
ELF: .dynsym {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required,rodata
|
||||
ELF: .dynstr {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required,rodata
|
||||
ELF: .text {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} text,{{(data,)?}}required
|
||||
ELF: .eh_frame {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required,rodata
|
||||
ELF: .tdata {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required
|
||||
ELF: .dynamic {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required
|
||||
ELF: .got.plt {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required
|
||||
ELF: .data {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required
|
||||
ELF: .bss {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} {{[a-z,]*}}
|
||||
ELF: .shstrtab {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata
|
||||
ELF: .symtab {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata
|
||||
ELF: .strtab {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata
|
||||
ELF: Total: 14
|
||||
|
||||
ELF:Libraries needed:
|
||||
ELF: libc.so.6
|
||||
ELF: libm.so.6
|
||||
|
@ -43,6 +43,15 @@ static void dumpSymbolHeader() {
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
static void dumpSectionHeader() {
|
||||
outs() << format(" %-24s", (const char*)"Name")
|
||||
<< format(" %-16s", (const char*)"Address")
|
||||
<< format(" %-16s", (const char*)"Size")
|
||||
<< format(" %-8s", (const char*)"Align")
|
||||
<< format(" %-26s", (const char*)"Flags")
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
static const char *getTypeStr(SymbolRef::Type Type) {
|
||||
switch (Type) {
|
||||
case SymbolRef::ST_Unknown: return "?";
|
||||
@ -84,6 +93,36 @@ static void checkError(error_code ec, const char *msg) {
|
||||
report_fatal_error(std::string(msg) + ": " + ec.message());
|
||||
}
|
||||
|
||||
static std::string getSectionFlagStr(const SectionRef &Section) {
|
||||
const struct {
|
||||
error_code (SectionRef::*MemF)(bool &) const;
|
||||
const char *FlagStr, *ErrorStr;
|
||||
} Work[] =
|
||||
{{ &SectionRef::isText, "text,", "Section.isText() failed" },
|
||||
{ &SectionRef::isData, "data,", "Section.isData() failed" },
|
||||
{ &SectionRef::isBSS, "bss,", "Section.isBSS() failed" },
|
||||
{ &SectionRef::isRequiredForExecution, "required,",
|
||||
"Section.isRequiredForExecution() failed" },
|
||||
{ &SectionRef::isVirtual, "virtual,", "Section.isVirtual() failed" },
|
||||
{ &SectionRef::isZeroInit, "zeroinit,", "Section.isZeroInit() failed" },
|
||||
{ &SectionRef::isReadOnlyData, "rodata,",
|
||||
"Section.isReadOnlyData() failed" }};
|
||||
|
||||
std::string result;
|
||||
for (uint32_t I = 0; I < sizeof(Work)/sizeof(*Work); ++I) {
|
||||
bool B;
|
||||
checkError((Section.*Work[I].MemF)(B), Work[I].ErrorStr);
|
||||
if (B)
|
||||
result += Work[I].FlagStr;
|
||||
}
|
||||
|
||||
// Remove trailing comma
|
||||
if (result.size() > 0) {
|
||||
result.erase(result.size() - 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
dumpSymbol(const SymbolRef &Sym, const ObjectFile *obj, bool IsDynamic) {
|
||||
StringRef Name;
|
||||
@ -159,12 +198,43 @@ static void dumpDynamicSymbols(const ObjectFile *obj) {
|
||||
outs() << " Total: " << count << "\n\n";
|
||||
}
|
||||
|
||||
static void dumpSection(const SectionRef &Section, const ObjectFile *obj) {
|
||||
StringRef Name;
|
||||
checkError(Section.getName(Name), "SectionRef::getName() failed");
|
||||
uint64_t Addr, Size, Align;
|
||||
checkError(Section.getAddress(Addr), "SectionRef::getAddress() failed");
|
||||
checkError(Section.getSize(Size), "SectionRef::getSize() failed");
|
||||
checkError(Section.getAlignment(Align), "SectionRef::getAlignment() failed");
|
||||
outs() << format(" %-24s", std::string(Name).c_str())
|
||||
<< format(" %16" PRIx64, Addr)
|
||||
<< format(" %16" PRIx64, Size)
|
||||
<< format(" %8" PRIx64, Align)
|
||||
<< " " << getSectionFlagStr(Section)
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
static void dumpLibrary(const LibraryRef &lib) {
|
||||
StringRef path;
|
||||
lib.getPath(path);
|
||||
outs() << " " << path << "\n";
|
||||
}
|
||||
|
||||
template<typename Iterator, typename Func>
|
||||
static void dump(const ObjectFile *obj, Func f, Iterator begin, Iterator end,
|
||||
const char *errStr) {
|
||||
error_code ec;
|
||||
uint32_t count = 0;
|
||||
Iterator it = begin, ie = end;
|
||||
while (it != ie) {
|
||||
f(*it, obj);
|
||||
it.increment(ec);
|
||||
if (ec)
|
||||
report_fatal_error(errStr);
|
||||
++count;
|
||||
}
|
||||
outs() << " Total: " << count << "\n\n";
|
||||
}
|
||||
|
||||
// Iterate through needed libraries
|
||||
static void dumpLibrariesNeeded(const ObjectFile *obj) {
|
||||
error_code ec;
|
||||
@ -220,6 +290,12 @@ int main(int argc, char** argv) {
|
||||
dumpHeaders(obj);
|
||||
dumpSymbols(obj);
|
||||
dumpDynamicSymbols(obj);
|
||||
|
||||
outs() << "Sections:\n";
|
||||
dumpSectionHeader();
|
||||
dump(obj, &dumpSection, obj->begin_sections(), obj->end_sections(),
|
||||
"Section iteration failed");
|
||||
|
||||
dumpLibrariesNeeded(obj);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user