From febdfe65a81629bc2a764820c94f9d2912a90e38 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 8 Apr 2015 10:29:23 -0700 Subject: Add chdr_size, Chdr, Chdr_write and Chdr_data * elfcpp.h (Elf_sizes): Add chdr_size. (Chdr): New. (Chdr_write): Likewise. * elfcpp_internal.h (Chdr_data): Likewise. --- elfcpp/ChangeLog | 7 ++++++ elfcpp/elfcpp.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ elfcpp/elfcpp_internal.h | 10 ++++++++ 3 files changed, 78 insertions(+) (limited to 'elfcpp') diff --git a/elfcpp/ChangeLog b/elfcpp/ChangeLog index 75681b1..3342ac9 100644 --- a/elfcpp/ChangeLog +++ b/elfcpp/ChangeLog @@ -1,5 +1,12 @@ 2015-04-08 H.J. Lu + * elfcpp.h (Elf_sizes): Add chdr_size. + (Chdr): New. + (Chdr_write): Likewise. + * elfcpp_internal.h (Chdr_data): Likewise. + +2015-04-08 H.J. Lu + * elfcpp.h (SHF): Add SHF_COMPRESSED. (ELFCOMPRESS_ZLIB): New. (ELFCOMPRESS_LOOS): Likewise. diff --git a/elfcpp/elfcpp.h b/elfcpp/elfcpp.h index f5a3efc..722984e 100644 --- a/elfcpp/elfcpp.h +++ b/elfcpp/elfcpp.h @@ -1009,6 +1009,8 @@ struct Elf_sizes static const int phdr_size = sizeof(internal::Phdr_data); // Size of ELF section header. static const int shdr_size = sizeof(internal::Shdr_data); + // Size of ELF compression header. + static const int chdr_size = sizeof(internal::Chdr_data); // Size of ELF symbol table entry. static const int sym_size = sizeof(internal::Sym_data); // Sizes of ELF reloc entries. @@ -1284,6 +1286,65 @@ class Shdr_write internal::Shdr_data* p_; }; +// Accessor class for an ELF compression header. + +template +class Chdr +{ + public: + Chdr(const unsigned char* p) + : p_(reinterpret_cast*>(p)) + { } + + template + Chdr(File* file, typename File::Location loc) + : p_(reinterpret_cast*>( + file->view(loc.file_offset, loc.data_size).data())) + { } + + typename Elf_types::Elf_WXword + get_ch_type() const + { return Convert::convert_host(this->p_->ch_type); } + + typename Elf_types::Elf_WXword + get_ch_size() const + { return Convert::convert_host(this->p_->ch_size); } + + typename Elf_types::Elf_WXword + get_ch_addralign() const + { return + Convert::convert_host(this->p_->ch_addralign); } + + private: + const internal::Chdr_data* p_; +}; + +// Write class for an ELF compression header. + +template +class Chdr_write +{ + public: + Chdr_write(unsigned char* p) + : p_(reinterpret_cast*>(p)) + { } + + void + put_ch_type(typename Elf_types::Elf_WXword v) + { this->p_->ch_type = Convert::convert_host(v); } + + void + put_ch_size(typename Elf_types::Elf_WXword v) + { this->p_->ch_size = Convert::convert_host(v); } + + void + put_ch_addralign(typename Elf_types::Elf_WXword v) + { this->p_->ch_addralign = Convert::convert_host(v); } + + private: + internal::Chdr_data* p_; +}; + // Accessor class for an ELF segment header. template diff --git a/elfcpp/elfcpp_internal.h b/elfcpp/elfcpp_internal.h index d800f7a..424a1f6 100644 --- a/elfcpp/elfcpp_internal.h +++ b/elfcpp/elfcpp_internal.h @@ -79,6 +79,16 @@ struct Shdr_data typename Elf_types::Elf_WXword sh_entsize; }; +// An ELF compression header. + +template +struct Chdr_data +{ + typename Elf_types::Elf_WXword ch_type; + typename Elf_types::Elf_WXword ch_size; + typename Elf_types::Elf_WXword ch_addralign; +}; + // An ELF segment header. We use template specialization for the // 32-bit and 64-bit versions because the fields are in a different // order. -- cgit v1.1