summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Atanasyan <simon@atanasyan.com>2014-05-29 11:05:31 +0000
committerSimon Atanasyan <simon@atanasyan.com>2014-05-29 11:05:31 +0000
commitce538c783448d6b8d848212286b5a4e500bc9956 (patch)
tree8641ee93da3673cd9aa59f295665bd10e77e7cdf
parent086a708135db02636c15e8cecb53ba757b487c18 (diff)
downloadllvm-ce538c783448d6b8d848212286b5a4e500bc9956.tar.gz
llvm-ce538c783448d6b8d848212286b5a4e500bc9956.tar.bz2
llvm-ce538c783448d6b8d848212286b5a4e500bc9956.tar.xz
[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
-rw-r--r--include/llvm/Object/ELFYAML.h2
-rw-r--r--lib/Object/ELFYAML.cpp2
-rw-r--r--test/Object/obj2yaml.test6
-rw-r--r--tools/obj2yaml/elf2yaml.cpp31
4 files changed, 27 insertions, 14 deletions
diff --git a/include/llvm/Object/ELFYAML.h b/include/llvm/Object/ELFYAML.h
index 524e55b07e..699a38671b 100644
--- a/include/llvm/Object/ELFYAML.h
+++ b/include/llvm/Object/ELFYAML.h
@@ -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) {
diff --git a/lib/Object/ELFYAML.cpp b/lib/Object/ELFYAML.cpp
index 7d50f23417..4c52f9c0be 100644
--- a/lib/Object/ELFYAML.cpp
+++ b/lib/Object/ELFYAML.cpp
@@ -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);
}
diff --git a/test/Object/obj2yaml.test b/test/Object/obj2yaml.test
index 1c1526349f..98b40d5cda 100644
--- a/test/Object/obj2yaml.test
+++ b/test/Object/obj2yaml.test
@@ -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
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 <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;