[PATCH] gold: PR gold/21857: Add clear_ch_reserved to 64-bit Chdr_write
H.J. Lu
hongjiu.lu@intel.com
Fri Jul 28 18:07:00 GMT 2017
The 64-bit ELF compression header has a reserved field. It should be
cleared to avoid random bits in it.
OK for master and 2.29 branches?
H.J.
--
elfcpp/
PR gold/21857
* elfcpp.h (Chdr_write): Add clear_ch_reserved.
gold/
PR gold/21857
* compressed_output.cc (Chdr_write<64, true>::clear_ch_reserved):
New.
(Chdr_write<64, false>::clear_ch_reserved): Likewise.
(Output_compressed_section::set_final_data_size): Call
clear_ch_reserved to clear the reserved field for 64-bit ELF..
---
elfcpp/elfcpp.h | 3 +++
gold/compressed_output.cc | 18 ++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/elfcpp/elfcpp.h b/elfcpp/elfcpp.h
index a57f5476f1..0209a48059 100644
--- a/elfcpp/elfcpp.h
+++ b/elfcpp/elfcpp.h
@@ -1351,6 +1351,9 @@ class Chdr_write
put_ch_addralign(typename Elf_types<size>::Elf_WXword v)
{ this->p_->ch_addralign = Convert<size, big_endian>::convert_host(v); }
+ void
+ clear_ch_reserved ();
+
private:
internal::Chdr_data<size>* p_;
};
diff --git a/gold/compressed_output.cc b/gold/compressed_output.cc
index 4374ba1bb7..d34db9bfe6 100644
--- a/gold/compressed_output.cc
+++ b/gold/compressed_output.cc
@@ -26,6 +26,22 @@
#include "options.h"
#include "compressed_output.h"
+template<>
+inline void
+elfcpp::Chdr_write<64, true>::clear_ch_reserved()
+{
+ // Clear the reserved field.
+ this->p_->ch_reserved = 0;
+}
+
+template<>
+inline void
+elfcpp::Chdr_write<64, false>::clear_ch_reserved()
+{
+ // Clear the reserved field.
+ this->p_->ch_reserved = 0;
+}
+
namespace gold
{
@@ -286,6 +302,7 @@ 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);
+ chdr.clear_ch_reserved();
}
else
{
@@ -293,6 +310,7 @@ 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);
+ chdr.clear_ch_reserved();
}
}
else
--
2.13.3
More information about the Binutils
mailing list