llvm.org GIT mirror llvm / 07cbb7b
. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357856 91177308-0d34-0410-b5e6-96231b3b80d8 Fangrui Song 7 months ago
1 changed file(s) with 8 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
2222
2323 template
2424 Expected getDynamicStrTab(const ELFFile *Elf) {
25 typedef ELFFile ELFO;
26
2725 auto DynamicEntriesOrError = Elf->dynamicEntries();
2826 if (!DynamicEntriesOrError)
2927 return DynamicEntriesOrError.takeError();
3028
31 for (const typename ELFO::Elf_Dyn &Dyn : *DynamicEntriesOrError) {
29 for (const typename ELFT::Dyn &Dyn : *DynamicEntriesOrError) {
3230 if (Dyn.d_tag == ELF::DT_STRTAB) {
3331 auto MappedAddrOrError = Elf->toMappedAddr(Dyn.getPtr());
3432 if (!MappedAddrOrError)
4240 if (!SectionsOrError)
4341 return SectionsOrError.takeError();
4442
45 for (const typename ELFO::Elf_Shdr &Sec : *SectionsOrError) {
43 for (const typename ELFT::Shdr &Sec : *SectionsOrError) {
4644 if (Sec.sh_type == ELF::SHT_DYNSYM)
4745 return Elf->getStringTableForSymtab(Sec);
4846 }
5452 static std::error_code getRelocationValueString(const ELFObjectFile *Obj,
5553 const RelocationRef &RelRef,
5654 SmallVectorImpl &Result) {
57 typedef typename ELFObjectFile::Elf_Sym Elf_Sym;
58 typedef typename ELFObjectFile::Elf_Shdr Elf_Shdr;
5955 typedef typename ELFObjectFile::Elf_Rela Elf_Rela;
6056
6157 const ELFFile &EF = *Obj->getELFFile();
8783
8884 if (!Undef) {
8985 symbol_iterator SI = RelRef.getSymbol();
90 const Elf_Sym *Sym = Obj->getSymbol(SI->getRawDataRefImpl());
86 const typename ELFT::Sym *Sym = Obj->getSymbol(SI->getRawDataRefImpl());
9187 if (Sym->getType() == ELF::STT_SECTION) {
9288 Expected SymSI = SI->getSection();
9389 if (!SymSI)
9490 return errorToErrorCode(SymSI.takeError());
95 const Elf_Shdr *SymSec = Obj->getSection((*SymSI)->getRawDataRefImpl());
91 const typename ELFT::Shdr *SymSec =
92 Obj->getSection((*SymSI)->getRawDataRefImpl());
9693 auto SecName = EF.getSectionName(SymSec);
9794 if (!SecName)
9895 return errorToErrorCode(SecName.takeError());
191188 }
192189
193190 template void printProgramHeaders(const ELFFile *o) {
194 typedef ELFFile ELFO;
195191 outs() << "Program Header:\n";
196192 auto ProgramHeaderOrError = o->program_headers();
197193 if (!ProgramHeaderOrError)
198194 report_fatal_error(
199195 errorToErrorCode(ProgramHeaderOrError.takeError()).message());
200 for (const typename ELFO::Elf_Phdr &Phdr : *ProgramHeaderOrError) {
196 for (const typename ELFT::Phdr &Phdr : *ProgramHeaderOrError) {
201197 switch (Phdr.p_type) {
202198 case ELF::PT_DYNAMIC:
203199 outs() << " DYNAMIC ";
258254 template
259255 void printSymbolVersionDependency(ArrayRef Contents,
260256 StringRef StrTab) {
261 typedef ELFFile ELFO;
262 typedef typename ELFO::Elf_Verneed Elf_Verneed;
263 typedef typename ELFO::Elf_Vernaux Elf_Vernaux;
264
265257 outs() << "Version References:\n";
266258
267259 const uint8_t *Buf = Contents.data();
268260 while (Buf) {
269 const Elf_Verneed *Verneed = reinterpret_castVerneed *>(Buf);
261 auto *Verneed = reinterpret_castVerneed *>(Buf);
270262 outs() << " required from "
271263 << StringRef(StrTab.drop_front(Verneed->vn_file).data()) << ":\n";
272264
273265 const uint8_t *BufAux = Buf + Verneed->vn_aux;
274266 while (BufAux) {
275 const Elf_Vernaux *Vernaux =
276 reinterpret_castVernaux *>(BufAux);
267 auto *Vernaux = reinterpret_castVernaux *>(BufAux);
277268 outs() << " "
278269 << format("0x%08" PRIx32 " ", (uint32_t)Vernaux->vna_hash)
279270 << format("0x%02" PRIx16 " ", (uint16_t)Vernaux->vna_flags)