From ce538c783448d6b8d848212286b5a4e500bc9956 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Thu, 29 May 2014 11:05:31 +0000 Subject: [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 --- tools/obj2yaml/elf2yaml.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'tools/obj2yaml') diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp index 7642921b48..5d19f9c7e6 100644 --- a/tools/obj2yaml/elf2yaml.cpp +++ b/tools/obj2yaml/elf2yaml.cpp @@ -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 error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel, ELFYAML::Relocation &R); @@ -84,6 +86,7 @@ ErrorOr ELFDumper::dump() { Y->Sections.push_back(std::unique_ptr(S.get())); break; } + // FIXME: Support SHT_GROUP section format. default: { ErrorOr S = dumpContentSection(&Sec); if (error_code EC = S.getError()) @@ -190,14 +193,24 @@ error_code ELFDumper::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 +error_code +ELFDumper::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 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::dumpRelSection(const Elf_Shdr *Shdr) { assert(Shdr->sh_type == ELF::SHT_REL && "Section type is not SHT_REL"); auto S = make_unique(); - 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::dumpRelaSection(const Elf_Shdr *Shdr) { assert(Shdr->sh_type == ELF::SHT_RELA && "Section type is not SHT_RELA"); auto S = make_unique(); - 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; -- cgit v1.2.3