[obj2yaml/yaml2obj] Add SHT_MIPS_ABIFLAGS section support

This change adds support for the SHT_MIPS_ABIFLAGS section
reading/writing to the obj2yaml and yaml2obj tools.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236738 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Simon Atanasyan
2015-05-07 15:40:48 +00:00
parent ef7c2568fa
commit bd58bdb7a6
6 changed files with 320 additions and 2 deletions
+37
View File
@@ -133,6 +133,9 @@ class ELFState {
ContiguousBlobAccumulator &CBA);
bool writeSectionContent(Elf_Shdr &SHeader, const ELFYAML::Group &Group,
ContiguousBlobAccumulator &CBA);
bool writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::MipsABIFlags &Section,
ContiguousBlobAccumulator &CBA);
// - SHT_NULL entry (placed first, i.e. 0'th entry)
// - symbol table (.symtab) (placed third to last)
@@ -235,6 +238,9 @@ bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
SHeader.sh_info = SymIdx;
if (!writeSectionContent(SHeader, *S, CBA))
return false;
} else if (auto S = dyn_cast<ELFYAML::MipsABIFlags>(Sec.get())) {
if (!writeSectionContent(SHeader, *S, CBA))
return false;
} else
llvm_unreachable("Unknown section type");
@@ -413,6 +419,37 @@ bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
return true;
}
template <class ELFT>
bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::MipsABIFlags &Section,
ContiguousBlobAccumulator &CBA) {
if (Section.Type != llvm::ELF::SHT_MIPS_ABIFLAGS) {
errs() << "error: Invalid section type.\n";
return false;
}
object::Elf_Mips_ABIFlags<ELFT> Flags;
zero(Flags);
SHeader.sh_entsize = sizeof(Flags);
SHeader.sh_size = SHeader.sh_entsize;
auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset);
Flags.version = Section.Version;
Flags.isa_level = Section.ISALevel;
Flags.isa_rev = Section.ISARevision;
Flags.gpr_size = Section.GPRSize;
Flags.cpr1_size = Section.CPR1Size;
Flags.cpr2_size = Section.CPR2Size;
Flags.fp_abi = Section.FpABI;
Flags.isa_ext = Section.ISAExtension;
Flags.ases = Section.ASEs;
Flags.flags1 = Section.Flags1;
Flags.flags2 = Section.Flags2;
OS.write((const char *)&Flags, sizeof(Flags));
return true;
}
template <class ELFT> bool ELFState<ELFT>::buildSectionIndex() {
SN2I.addName(".symtab", getDotSymTabSecNo());
SN2I.addName(".strtab", getDotStrTabSecNo());