forked from OSchip/llvm-project
[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. llvm-svn: 209801
This commit is contained in:
parent
01a7598561
commit
8745993ec4
|
@ -76,7 +76,6 @@ struct Section {
|
|||
ELF_SHF Flags;
|
||||
llvm::yaml::Hex64 Address;
|
||||
StringRef Link;
|
||||
StringRef Info;
|
||||
llvm::yaml::Hex64 AddressAlign;
|
||||
Section(SectionKind Kind) : Kind(Kind) {}
|
||||
virtual ~Section();
|
||||
|
@ -96,6 +95,7 @@ struct Relocation {
|
|||
StringRef Symbol;
|
||||
};
|
||||
struct RelocationSection : Section {
|
||||
StringRef Info;
|
||||
std::vector<Relocation> Relocations;
|
||||
RelocationSection() : Section(SectionKind::Relocation) {}
|
||||
static bool classof(const Section *S) {
|
||||
|
|
|
@ -664,7 +664,6 @@ static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
|
|||
IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
|
||||
IO.mapOptional("Address", Section.Address, Hex64(0));
|
||||
IO.mapOptional("Link", Section.Link, StringRef());
|
||||
IO.mapOptional("Info", Section.Info, StringRef());
|
||||
IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
|
||||
}
|
||||
|
||||
|
@ -676,6 +675,7 @@ static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
|
|||
|
||||
static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapOptional("Info", Section.Info, StringRef());
|
||||
IO.mapOptional("Relocations", Section.Relocations);
|
||||
}
|
||||
|
||||
|
|
|
@ -201,8 +201,8 @@ ELF-MIPSEL-NEXT: Content: 0000023C00004224E8FFBD271400BFAF1000B0AF21
|
|||
ELF-MIPSEL-NEXT: - Name: .rel.text
|
||||
ELF-MIPSEL-NEXT: Type: SHT_REL
|
||||
ELF-MIPSEL-NEXT: Link: .symtab
|
||||
ELF-MIPSEL-NEXT: Info: .text
|
||||
ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000004
|
||||
ELF-MIPSEL-NEXT: Info: .text
|
||||
ELF-MIPSEL-NEXT: Relocations:
|
||||
ELF-MIPSEL-NEXT: - Offset: 0
|
||||
ELF-MIPSEL-NEXT: Symbol: _gp_disp
|
||||
|
@ -300,8 +300,8 @@ ELF-MIPS64EL-NEXT: Content: '00000000000000000000000000000000'
|
|||
ELF-MIPS64EL-NEXT: - Name: .rela.data
|
||||
ELF-MIPS64EL-NEXT: Type: SHT_RELA
|
||||
ELF-MIPS64EL-NEXT: Link: .symtab
|
||||
ELF-MIPS64EL-NEXT: Info: .data
|
||||
ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000008
|
||||
ELF-MIPS64EL-NEXT: Info: .data
|
||||
ELF-MIPS64EL-NEXT: Relocations:
|
||||
ELF-MIPS64EL-NEXT: - Offset: 0
|
||||
ELF-MIPS64EL-NEXT: Symbol: zed
|
||||
|
@ -370,8 +370,8 @@ ELF-X86-64-NEXT: - Name: .rela.text
|
|||
ELF-X86-64-NEXT: Type: SHT_RELA
|
||||
ELF-X86-64-NEXT: Address: 0x0000000000000038
|
||||
ELF-X86-64-NEXT: Link: .symtab
|
||||
ELF-X86-64-NEXT: Info: .text
|
||||
ELF-X86-64-NEXT: AddressAlign: 0x0000000000000008
|
||||
ELF-X86-64-NEXT: Info: .text
|
||||
ELF-X86-64-NEXT: Relocations:
|
||||
ELF-X86-64-NEXT: - Offset: 0x000000000000000D
|
||||
ELF-X86-64-NEXT: Symbol: .rodata.str1.1
|
||||
|
|
|
@ -28,6 +28,8 @@ class ELFDumper {
|
|||
|
||||
error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S);
|
||||
error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S);
|
||||
error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr,
|
||||
ELFYAML::RelocationSection &S);
|
||||
template <class RelT>
|
||||
error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel,
|
||||
ELFYAML::Relocation &R);
|
||||
|
@ -84,6 +86,7 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
|
|||
Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
|
||||
break;
|
||||
}
|
||||
// FIXME: Support SHT_GROUP section format.
|
||||
default: {
|
||||
ErrorOr<ELFYAML::RawContentSection *> S = dumpContentSection(&Sec);
|
||||
if (error_code EC = S.getError())
|
||||
|
@ -190,14 +193,24 @@ error_code ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
|
|||
S.Link = NameOrErr.get();
|
||||
}
|
||||
}
|
||||
if (Shdr->sh_info != ELF::SHN_UNDEF) {
|
||||
if (const Elf_Shdr *InfoSection = Obj.getSection(Shdr->sh_info)) {
|
||||
NameOrErr = Obj.getSectionName(InfoSection);
|
||||
if (error_code EC = NameOrErr.getError())
|
||||
return EC;
|
||||
S.Info = NameOrErr.get();
|
||||
}
|
||||
|
||||
return obj2yaml_error::success;
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
error_code
|
||||
ELFDumper<ELFT>::dumpCommonRelocationSection(const Elf_Shdr *Shdr,
|
||||
ELFYAML::RelocationSection &S) {
|
||||
if (error_code EC = dumpCommonSection(Shdr, S))
|
||||
return EC;
|
||||
|
||||
if (const Elf_Shdr *InfoSection = Obj.getSection(Shdr->sh_info)) {
|
||||
ErrorOr<StringRef> NameOrErr = Obj.getSectionName(InfoSection);
|
||||
if (error_code EC = NameOrErr.getError())
|
||||
return EC;
|
||||
S.Info = NameOrErr.get();
|
||||
}
|
||||
|
||||
return obj2yaml_error::success;
|
||||
}
|
||||
|
||||
|
@ -207,7 +220,7 @@ ELFDumper<ELFT>::dumpRelSection(const Elf_Shdr *Shdr) {
|
|||
assert(Shdr->sh_type == ELF::SHT_REL && "Section type is not SHT_REL");
|
||||
auto S = make_unique<ELFYAML::RelocationSection>();
|
||||
|
||||
if (error_code EC = dumpCommonSection(Shdr, *S))
|
||||
if (error_code EC = dumpCommonRelocationSection(Shdr, *S))
|
||||
return EC;
|
||||
|
||||
for (auto RI = Obj.begin_rel(Shdr), RE = Obj.end_rel(Shdr); RI != RE;
|
||||
|
@ -227,7 +240,7 @@ ELFDumper<ELFT>::dumpRelaSection(const Elf_Shdr *Shdr) {
|
|||
assert(Shdr->sh_type == ELF::SHT_RELA && "Section type is not SHT_RELA");
|
||||
auto S = make_unique<ELFYAML::RelocationSection>();
|
||||
|
||||
if (error_code EC = dumpCommonSection(Shdr, *S))
|
||||
if (error_code EC = dumpCommonRelocationSection(Shdr, *S))
|
||||
return EC;
|
||||
|
||||
for (auto RI = Obj.begin_rela(Shdr), RE = Obj.end_rela(Shdr); RI != RE;
|
||||
|
|
Loading…
Reference in New Issue