From e5163ebf8d9e4262c8adc1309f70e8cabef10f3a Mon Sep 17 00:00:00 2001 From: George Rimar Date: Tue, 1 Oct 2019 09:45:59 +0000 Subject: [yaml2obj/obj2yaml] - Add support for SHT_HASH sections. SHT_HASH specification is: http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#hash In short the format is the following: it has 2 uint32 fields in its header: nbucket and nchain followed by (nbucket + nchain) uint32 values. This patch allows dumping and parsing such sections. Differential revision: https://reviews.llvm.org/D68085 llvm-svn: 373315 --- llvm/lib/ObjectYAML/ELFEmitter.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'llvm/lib/ObjectYAML/ELFEmitter.cpp') diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp index 6edc3c8e763..5acb02a5a57 100644 --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -171,6 +171,9 @@ template class ELFState { void writeSectionContent(Elf_Shdr &SHeader, const ELFYAML::StackSizesSection &Section, ContiguousBlobAccumulator &CBA); + void writeSectionContent(Elf_Shdr &SHeader, + const ELFYAML::HashSection &Section, + ContiguousBlobAccumulator &CBA); ELFState(ELFYAML::Object &D, yaml::ErrorHandler EH); public: @@ -417,7 +420,9 @@ void ELFState::initSectionHeaders(std::vector &SHeaders, } else if (auto S = dyn_cast(Sec)) { writeSectionContent(SHeader, *S, CBA); } else if (auto S = dyn_cast(Sec)) { - writeSectionContent(SHeader, *S, CBA); + writeSectionContent(SHeader, *S, CBA); + } else if (auto S = dyn_cast(Sec)) { + writeSectionContent(SHeader, *S, CBA); } else { llvm_unreachable("Unknown section type"); } @@ -808,6 +813,34 @@ void ELFState::writeSectionContent( } } +template +void ELFState::writeSectionContent(Elf_Shdr &SHeader, + const ELFYAML::HashSection &Section, + ContiguousBlobAccumulator &CBA) { + raw_ostream &OS = + CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign); + + unsigned Link = 0; + if (SN2I.lookup(".dynsym", Link)) + SHeader.sh_link = Link; + + if (Section.Content) { + SHeader.sh_size = writeContent(OS, Section.Content, None); + return; + } + + support::endian::write(OS, Section.Bucket->size(), + ELFT::TargetEndianness); + support::endian::write(OS, Section.Chain->size(), + ELFT::TargetEndianness); + for (uint32_t Val : *Section.Bucket) + support::endian::write(OS, Val, ELFT::TargetEndianness); + for (uint32_t Val : *Section.Chain) + support::endian::write(OS, Val, ELFT::TargetEndianness); + + SHeader.sh_size = (2 + Section.Bucket->size() + Section.Chain->size()) * 4; +} + template void ELFState::writeSectionContent(Elf_Shdr &SHeader, const ELFYAML::VerdefSection &Section, -- cgit v1.2.3