mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-11 05:24:16 +00:00
[obj2yaml] - Merge dumpRelSection and dumpRelaSection. NFC.
These methods are very similar, patch merge them into one. Differential revision: https://reviews.llvm.org/D57461 llvm-svn: 352840
This commit is contained in:
parent
93a3601da5
commit
3da9f8c04c
@ -51,8 +51,7 @@ class ELFDumper {
|
||||
std::error_code dumpRelocation(const RelT *Rel, const Elf_Shdr *SymTab,
|
||||
ELFYAML::Relocation &R);
|
||||
|
||||
ErrorOr<ELFYAML::RelocationSection *> dumpRelSection(const Elf_Shdr *Shdr);
|
||||
ErrorOr<ELFYAML::RelocationSection *> dumpRelaSection(const Elf_Shdr *Shdr);
|
||||
ErrorOr<ELFYAML::RelocationSection *> dumpRelocSection(const Elf_Shdr *Shdr);
|
||||
ErrorOr<ELFYAML::RawContentSection *>
|
||||
dumpContentSection(const Elf_Shdr *Shdr);
|
||||
ErrorOr<ELFYAML::NoBitsSection *> dumpNoBitsSection(const Elf_Shdr *Shdr);
|
||||
@ -147,15 +146,9 @@ template <class ELFT> ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
|
||||
ShndxTable = *TableOrErr;
|
||||
break;
|
||||
}
|
||||
case ELF::SHT_REL:
|
||||
case ELF::SHT_RELA: {
|
||||
ErrorOr<ELFYAML::RelocationSection *> S = dumpRelaSection(&Sec);
|
||||
if (std::error_code EC = S.getError())
|
||||
return EC;
|
||||
Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
|
||||
break;
|
||||
}
|
||||
case ELF::SHT_REL: {
|
||||
ErrorOr<ELFYAML::RelocationSection *> S = dumpRelSection(&Sec);
|
||||
ErrorOr<ELFYAML::RelocationSection *> S = dumpRelocSection(&Sec);
|
||||
if (std::error_code EC = S.getError())
|
||||
return EC;
|
||||
Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
|
||||
@ -359,10 +352,8 @@ ELFDumper<ELFT>::dumpCommonRelocationSection(const Elf_Shdr *Shdr,
|
||||
|
||||
template <class ELFT>
|
||||
ErrorOr<ELFYAML::RelocationSection *>
|
||||
ELFDumper<ELFT>::dumpRelSection(const Elf_Shdr *Shdr) {
|
||||
assert(Shdr->sh_type == ELF::SHT_REL && "Section type is not SHT_REL");
|
||||
ELFDumper<ELFT>::dumpRelocSection(const Elf_Shdr *Shdr) {
|
||||
auto S = make_unique<ELFYAML::RelocationSection>();
|
||||
|
||||
if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
|
||||
return EC;
|
||||
|
||||
@ -371,42 +362,27 @@ ELFDumper<ELFT>::dumpRelSection(const Elf_Shdr *Shdr) {
|
||||
return errorToErrorCode(SymTabOrErr.takeError());
|
||||
const Elf_Shdr *SymTab = *SymTabOrErr;
|
||||
|
||||
auto Rels = Obj.rels(Shdr);
|
||||
if (!Rels)
|
||||
return errorToErrorCode(Rels.takeError());
|
||||
for (const Elf_Rel &Rel : *Rels) {
|
||||
ELFYAML::Relocation R;
|
||||
if (std::error_code EC = dumpRelocation(&Rel, SymTab, R))
|
||||
return EC;
|
||||
S->Relocations.push_back(R);
|
||||
}
|
||||
|
||||
return S.release();
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
ErrorOr<ELFYAML::RelocationSection *>
|
||||
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 (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
|
||||
return EC;
|
||||
|
||||
auto SymTabOrErr = Obj.getSection(Shdr->sh_link);
|
||||
if (!SymTabOrErr)
|
||||
return errorToErrorCode(SymTabOrErr.takeError());
|
||||
const Elf_Shdr *SymTab = *SymTabOrErr;
|
||||
|
||||
auto Rels = Obj.relas(Shdr);
|
||||
if (!Rels)
|
||||
return errorToErrorCode(Rels.takeError());
|
||||
for (const Elf_Rela &Rel : *Rels) {
|
||||
ELFYAML::Relocation R;
|
||||
if (std::error_code EC = dumpRelocation(&Rel, SymTab, R))
|
||||
return EC;
|
||||
R.Addend = Rel.r_addend;
|
||||
S->Relocations.push_back(R);
|
||||
if (Shdr->sh_type == ELF::SHT_REL) {
|
||||
auto Rels = Obj.rels(Shdr);
|
||||
if (!Rels)
|
||||
return errorToErrorCode(Rels.takeError());
|
||||
for (const Elf_Rel &Rel : *Rels) {
|
||||
ELFYAML::Relocation R;
|
||||
if (std::error_code EC = dumpRelocation(&Rel, SymTab, R))
|
||||
return EC;
|
||||
S->Relocations.push_back(R);
|
||||
}
|
||||
} else {
|
||||
auto Rels = Obj.relas(Shdr);
|
||||
if (!Rels)
|
||||
return errorToErrorCode(Rels.takeError());
|
||||
for (const Elf_Rela &Rel : *Rels) {
|
||||
ELFYAML::Relocation R;
|
||||
if (std::error_code EC = dumpRelocation(&Rel, SymTab, R))
|
||||
return EC;
|
||||
R.Addend = Rel.r_addend;
|
||||
S->Relocations.push_back(R);
|
||||
}
|
||||
}
|
||||
|
||||
return S.release();
|
||||
|
Loading…
Reference in New Issue
Block a user