llvm.org GIT mirror llvm / ce538c7
[elf2yaml][ELF] Move Info field to the RelocationSection structure. This field represents ELF section header sh_info field and does not have any sense for regular sections. Its interpretation depends on section type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209801 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Atanasyan 6 years ago
4 changed file(s) with 28 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
7575 ELF_SHF Flags;
7676 llvm::yaml::Hex64 Address;
7777 StringRef Link;
78 StringRef Info;
7978 llvm::yaml::Hex64 AddressAlign;
8079 Section(SectionKind Kind) : Kind(Kind) {}
8180 virtual ~Section();
9594 StringRef Symbol;
9695 };
9796 struct RelocationSection : Section {
97 StringRef Info;
9898 std::vector Relocations;
9999 RelocationSection() : Section(SectionKind::Relocation) {}
100100 static bool classof(const Section *S) {
663663 IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
664664 IO.mapOptional("Address", Section.Address, Hex64(0));
665665 IO.mapOptional("Link", Section.Link, StringRef());
666 IO.mapOptional("Info", Section.Info, StringRef());
667666 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
668667 }
669668
675674
676675 static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
677676 commonSectionMapping(IO, Section);
677 IO.mapOptional("Info", Section.Info, StringRef());
678678 IO.mapOptional("Relocations", Section.Relocations);
679679 }
680680
200200 ELF-MIPSEL-NEXT: - Name: .rel.text
201201 ELF-MIPSEL-NEXT: Type: SHT_REL
202202 ELF-MIPSEL-NEXT: Link: .symtab
203 ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000004
203204 ELF-MIPSEL-NEXT: Info: .text
204 ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000004
205205 ELF-MIPSEL-NEXT: Relocations:
206206 ELF-MIPSEL-NEXT: - Offset: 0
207207 ELF-MIPSEL-NEXT: Symbol: _gp_disp
299299 ELF-MIPS64EL-NEXT: - Name: .rela.data
300300 ELF-MIPS64EL-NEXT: Type: SHT_RELA
301301 ELF-MIPS64EL-NEXT: Link: .symtab
302 ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000008
302303 ELF-MIPS64EL-NEXT: Info: .data
303 ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000008
304304 ELF-MIPS64EL-NEXT: Relocations:
305305 ELF-MIPS64EL-NEXT: - Offset: 0
306306 ELF-MIPS64EL-NEXT: Symbol: zed
369369 ELF-X86-64-NEXT: Type: SHT_RELA
370370 ELF-X86-64-NEXT: Address: 0x0000000000000038
371371 ELF-X86-64-NEXT: Link: .symtab
372 ELF-X86-64-NEXT: AddressAlign: 0x0000000000000008
372373 ELF-X86-64-NEXT: Info: .text
373 ELF-X86-64-NEXT: AddressAlign: 0x0000000000000008
374374 ELF-X86-64-NEXT: Relocations:
375375 ELF-X86-64-NEXT: - Offset: 0x000000000000000D
376376 ELF-X86-64-NEXT: Symbol: .rodata.str1.1
2727
2828 error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S);
2929 error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S);
30 error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr,
31 ELFYAML::RelocationSection &S);
3032 template
3133 error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel,
3234 ELFYAML::Relocation &R);
8385 Y->Sections.push_back(std::unique_ptr(S.get()));
8486 break;
8587 }
88 // FIXME: Support SHT_GROUP section format.
8689 default: {
8790 ErrorOr S = dumpContentSection(&Sec);
8891 if (error_code EC = S.getError())
189192 S.Link = NameOrErr.get();
190193 }
191194 }
192 if (Shdr->sh_info != ELF::SHN_UNDEF) {
193 if (const Elf_Shdr *InfoSection = Obj.getSection(Shdr->sh_info)) {
194 NameOrErr = Obj.getSectionName(InfoSection);
195 if (error_code EC = NameOrErr.getError())
196 return EC;
197 S.Info = NameOrErr.get();
198 }
199 }
195
196 return obj2yaml_error::success;
197 }
198
199 template
200 error_code
201 ELFDumper::dumpCommonRelocationSection(const Elf_Shdr *Shdr,
202 ELFYAML::RelocationSection &S) {
203 if (error_code EC = dumpCommonSection(Shdr, S))
204 return EC;
205
206 if (const Elf_Shdr *InfoSection = Obj.getSection(Shdr->sh_info)) {
207 ErrorOr NameOrErr = Obj.getSectionName(InfoSection);
208 if (error_code EC = NameOrErr.getError())
209 return EC;
210 S.Info = NameOrErr.get();
211 }
212
200213 return obj2yaml_error::success;
201214 }
202215
206219 assert(Shdr->sh_type == ELF::SHT_REL && "Section type is not SHT_REL");
207220 auto S = make_unique();
208221
209 if (error_code EC = dumpCommonSection(Shdr, *S))
222 if (error_code EC = dumpCommonRelocationSection(Shdr, *S))
210223 return EC;
211224
212225 for (auto RI = Obj.begin_rel(Shdr), RE = Obj.end_rel(Shdr); RI != RE;
226239 assert(Shdr->sh_type == ELF::SHT_RELA && "Section type is not SHT_RELA");
227240 auto S = make_unique();
228241
229 if (error_code EC = dumpCommonSection(Shdr, *S))
242 if (error_code EC = dumpCommonRelocationSection(Shdr, *S))
230243 return EC;
231244
232245 for (auto RI = Obj.begin_rela(Shdr), RE = Obj.end_rela(Shdr); RI != RE;