From 49ba15a23a9d3d8a109ce2fd5053822eee7f1fdf Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 28 Jul 2017 13:39:42 -0700 Subject: [PATCH] gold: Add put_ch_reserved to 64-bit Chdr_write The 64-bit ELF compression header has a reserved field. It should be cleared to avoid random bits in it. elfcpp/ PR gold/21857 * elfcpp.h (Chdr_write): Add put_ch_reserved. (Chdr_write<64, true>::put_ch_reserved): New. (Chdr_write<64, false>::put_ch_reserved): Likewise. gold/ PR gold/21857 * compressed_output.cc (Output_compressed_section::set_final_data_size): Call put_ch_reserved to clear the reserved field for 64-bit ELF. --- elfcpp/ChangeLog | 7 +++++++ elfcpp/elfcpp.h | 17 +++++++++++++++++ gold/ChangeLog | 6 ++++++ gold/compressed_output.cc | 4 ++++ 4 files changed, 34 insertions(+) diff --git a/elfcpp/ChangeLog b/elfcpp/ChangeLog index fc864bf6fad..f6692486268 100644 --- a/elfcpp/ChangeLog +++ b/elfcpp/ChangeLog @@ -1,3 +1,10 @@ +2017-07-28 H.J. Lu + + PR gold/21857 + * elfcpp.h (Chdr_write): Add put_ch_reserved. + (Chdr_write<64, true>::put_ch_reserved): New. + (Chdr_write<64, false>::put_ch_reserved): Likewise. + 2017-07-03 Alan Modra * dwarf.h (DW_FIRST_IDX, DW_IDX, DW_IDX_DUP, DW_END_IDX): Define, diff --git a/elfcpp/elfcpp.h b/elfcpp/elfcpp.h index a57f5476f12..cccec4c2560 100644 --- a/elfcpp/elfcpp.h +++ b/elfcpp/elfcpp.h @@ -1351,10 +1351,27 @@ class Chdr_write put_ch_addralign(typename Elf_types::Elf_WXword v) { this->p_->ch_addralign = Convert::convert_host(v); } + void + put_ch_reserved(Elf_Word); + private: internal::Chdr_data* p_; }; +template<> +inline void +elfcpp::Chdr_write<64, true>::put_ch_reserved(Elf_Word v) +{ + this->p_->ch_reserved = v; +} + +template<> +inline void +elfcpp::Chdr_write<64, false>::put_ch_reserved(Elf_Word v) +{ + this->p_->ch_reserved = v; +} + // Accessor class for an ELF segment header. template diff --git a/gold/ChangeLog b/gold/ChangeLog index 502af851c55..fdac9313c3c 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,9 @@ +2017-07-28 H.J. Lu + + PR gold/21857 + * compressed_output.cc (Output_compressed_section::set_final_data_size): + Call put_ch_reserved to clear the reserved field for 64-bit ELF. + 2017-07-26 H.J. Lu * mips.cc (Mips_relocate_functions): Add "llu" suffix to diff --git a/gold/compressed_output.cc b/gold/compressed_output.cc index 4374ba1bb74..45077f70203 100644 --- a/gold/compressed_output.cc +++ b/gold/compressed_output.cc @@ -286,6 +286,8 @@ Output_compressed_section::set_final_data_size() chdr.put_ch_type(elfcpp::ELFCOMPRESS_ZLIB); chdr.put_ch_size(uncompressed_size); chdr.put_ch_addralign(addralign); + // Clear the reserved field. + chdr.put_ch_reserved(0); } else { @@ -293,6 +295,8 @@ Output_compressed_section::set_final_data_size() chdr.put_ch_type(elfcpp::ELFCOMPRESS_ZLIB); chdr.put_ch_size(uncompressed_size); chdr.put_ch_addralign(addralign); + // Clear the reserved field. + chdr.put_ch_reserved(0); } } else -- 2.30.2