llvm.org GIT mirror llvm / fc73847
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 Rafael Espindola 7 years ago
2 changed file(s) with 94 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
5252 ELF: _edata ? {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} global,absolute
5353 ELF: Total: {{[0-9a-f]+}}
5454
55 ELF:Sections:
56 ELF: Name Address Size Align Flags
57 ELF: {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata
58 ELF: .hash {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required,rodata
59 ELF: .dynsym {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required,rodata
60 ELF: .dynstr {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required,rodata
61 ELF: .text {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} text,{{(data,)?}}required
62 ELF: .eh_frame {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required,rodata
63 ELF: .tdata {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required
64 ELF: .dynamic {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} required
65 ELF: .got.plt {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required
66 ELF: .data {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} data,required
67 ELF: .bss {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} {{[a-z,]*}}
68 ELF: .shstrtab {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata
69 ELF: .symtab {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata
70 ELF: .strtab {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} rodata
71 ELF: Total: 14
72
5573 ELF:Libraries needed:
5674 ELF: libc.so.6
5775 ELF: libm.so.6
3838 << format(" %-16s", (const char*)"Address")
3939 << format(" %-16s", (const char*)"Size")
4040 << format(" %-16s", (const char*)"FileOffset")
41 << format(" %-26s", (const char*)"Flags")
42 << "\n";
43 }
44
45 static void dumpSectionHeader() {
46 outs() << format(" %-24s", (const char*)"Name")
47 << format(" %-16s", (const char*)"Address")
48 << format(" %-16s", (const char*)"Size")
49 << format(" %-8s", (const char*)"Align")
4150 << format(" %-26s", (const char*)"Flags")
4251 << "\n";
4352 }
8392 report_fatal_error(std::string(msg) + ": " + ec.message());
8493 }
8594
95 static std::string getSectionFlagStr(const SectionRef &Section) {
96 const struct {
97 error_code (SectionRef::*MemF)(bool &) const;
98 const char *FlagStr, *ErrorStr;
99 } Work[] =
100 {{ &SectionRef::isText, "text,", "Section.isText() failed" },
101 { &SectionRef::isData, "data,", "Section.isData() failed" },
102 { &SectionRef::isBSS, "bss,", "Section.isBSS() failed" },
103 { &SectionRef::isRequiredForExecution, "required,",
104 "Section.isRequiredForExecution() failed" },
105 { &SectionRef::isVirtual, "virtual,", "Section.isVirtual() failed" },
106 { &SectionRef::isZeroInit, "zeroinit,", "Section.isZeroInit() failed" },
107 { &SectionRef::isReadOnlyData, "rodata,",
108 "Section.isReadOnlyData() failed" }};
109
110 std::string result;
111 for (uint32_t I = 0; I < sizeof(Work)/sizeof(*Work); ++I) {
112 bool B;
113 checkError((Section.*Work[I].MemF)(B), Work[I].ErrorStr);
114 if (B)
115 result += Work[I].FlagStr;
116 }
117
118 // Remove trailing comma
119 if (result.size() > 0) {
120 result.erase(result.size() - 1);
121 }
122 return result;
123 }
124
86125 static void
87126 dumpSymbol(const SymbolRef &Sym, const ObjectFile *obj, bool IsDynamic) {
88127 StringRef Name;
158197 outs() << " Total: " << count << "\n\n";
159198 }
160199
200 static void dumpSection(const SectionRef &Section, const ObjectFile *obj) {
201 StringRef Name;
202 checkError(Section.getName(Name), "SectionRef::getName() failed");
203 uint64_t Addr, Size, Align;
204 checkError(Section.getAddress(Addr), "SectionRef::getAddress() failed");
205 checkError(Section.getSize(Size), "SectionRef::getSize() failed");
206 checkError(Section.getAlignment(Align), "SectionRef::getAlignment() failed");
207 outs() << format(" %-24s", std::string(Name).c_str())
208 << format(" %16" PRIx64, Addr)
209 << format(" %16" PRIx64, Size)
210 << format(" %8" PRIx64, Align)
211 << " " << getSectionFlagStr(Section)
212 << "\n";
213 }
214
161215 static void dumpLibrary(const LibraryRef &lib) {
162216 StringRef path;
163217 lib.getPath(path);
164218 outs() << " " << path << "\n";
219 }
220
221 template
222 static void dump(const ObjectFile *obj, Func f, Iterator begin, Iterator end,
223 const char *errStr) {
224 error_code ec;
225 uint32_t count = 0;
226 Iterator it = begin, ie = end;
227 while (it != ie) {
228 f(*it, obj);
229 it.increment(ec);
230 if (ec)
231 report_fatal_error(errStr);
232 ++count;
233 }
234 outs() << " Total: " << count << "\n\n";
165235 }
166236
167237 // Iterate through needed libraries
219289 dumpHeaders(obj);
220290 dumpSymbols(obj);
221291 dumpDynamicSymbols(obj);
292
293 outs() << "Sections:\n";
294 dumpSectionHeader();
295 dump(obj, &dumpSection, obj->begin_sections(), obj->end_sections(),
296 "Section iteration failed");
297
222298 dumpLibrariesNeeded(obj);
223299 return 0;
224300 }