Add chdr_size, Chdr, Chdr_write and Chdr_data
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 8 Apr 2015 17:29:23 +0000 (10:29 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 8 Apr 2015 17:29:40 +0000 (10:29 -0700)
* elfcpp.h (Elf_sizes): Add chdr_size.
(Chdr): New.
(Chdr_write): Likewise.
* elfcpp_internal.h (Chdr_data): Likewise.

elfcpp/ChangeLog
elfcpp/elfcpp.h
elfcpp/elfcpp_internal.h

index 75681b1cdf5d1ead38afaa1e8a5e4585fb2004b5..3342ac945432f7ba4e986820b1088db0505a2e7b 100644 (file)
@@ -1,3 +1,10 @@
+2015-04-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elfcpp.h (Elf_sizes): Add chdr_size.
+       (Chdr): New.
+       (Chdr_write): Likewise.
+       * elfcpp_internal.h (Chdr_data): Likewise.
+
 2015-04-08  H.J. Lu  <hongjiu.lu@intel.com>
 
        * elfcpp.h (SHF): Add SHF_COMPRESSED.
index f5a3efcbb66980ffc4917a1ce78571831acbf6a4..722984e5452bbec8b64d446e99a74bcac5d43342 100644 (file)
@@ -1009,6 +1009,8 @@ struct Elf_sizes
   static const int phdr_size = sizeof(internal::Phdr_data<size>);
   // Size of ELF section header.
   static const int shdr_size = sizeof(internal::Shdr_data<size>);
+  // Size of ELF compression header.
+  static const int chdr_size = sizeof(internal::Chdr_data<size>);
   // Size of ELF symbol table entry.
   static const int sym_size = sizeof(internal::Sym_data<size>);
   // Sizes of ELF reloc entries.
@@ -1284,6 +1286,65 @@ class Shdr_write
   internal::Shdr_data<size>* p_;
 };
 
+// Accessor class for an ELF compression header.
+
+template<int size, bool big_endian>
+class Chdr
+{
+ public:
+  Chdr(const unsigned char* p)
+    : p_(reinterpret_cast<const internal::Chdr_data<size>*>(p))
+  { }
+
+  template<typename File>
+  Chdr(File* file, typename File::Location loc)
+    : p_(reinterpret_cast<const internal::Chdr_data<size>*>(
+          file->view(loc.file_offset, loc.data_size).data()))
+  { }
+
+  typename Elf_types<size>::Elf_WXword
+  get_ch_type() const
+  { return Convert<size, big_endian>::convert_host(this->p_->ch_type); }
+
+  typename Elf_types<size>::Elf_WXword
+  get_ch_size() const
+  { return Convert<size, big_endian>::convert_host(this->p_->ch_size); }
+
+  typename Elf_types<size>::Elf_WXword
+  get_ch_addralign() const
+  { return
+      Convert<size, big_endian>::convert_host(this->p_->ch_addralign); }
+
+ private:
+  const internal::Chdr_data<size>* p_;
+};
+
+// Write class for an ELF compression header.
+
+template<int size, bool big_endian>
+class Chdr_write
+{
+ public:
+  Chdr_write(unsigned char* p)
+    : p_(reinterpret_cast<internal::Chdr_data<size>*>(p))
+  { }
+
+  void
+  put_ch_type(typename Elf_types<size>::Elf_WXword v)
+  { this->p_->ch_type = Convert<size, big_endian>::convert_host(v); }
+
+  void
+  put_ch_size(typename Elf_types<size>::Elf_WXword v)
+  { this->p_->ch_size = Convert<size, big_endian>::convert_host(v); }
+
+  void
+  put_ch_addralign(typename Elf_types<size>::Elf_WXword v)
+  { this->p_->ch_addralign = Convert<size, big_endian>::convert_host(v); }
+
+ private:
+  internal::Chdr_data<size>* p_;
+};
+
 // Accessor class for an ELF segment header.
 
 template<int size, bool big_endian>
index d800f7a071316b058614d8867681718e673f40ac..424a1f6f713f173aaaf8e7b911b17d1cd2c46cad 100644 (file)
@@ -79,6 +79,16 @@ struct Shdr_data
   typename Elf_types<size>::Elf_WXword sh_entsize;
 };
 
+// An ELF compression header.
+
+template<int size>
+struct Chdr_data
+{
+  typename Elf_types<size>::Elf_WXword ch_type;
+  typename Elf_types<size>::Elf_WXword ch_size;
+  typename Elf_types<size>::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.
This page took 0.026999 seconds and 4 git commands to generate.