This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] gold: PR gold/21857: Add clear_ch_reserved to 64-bit Chdr_write


On Fri, Jul 28, 2017 at 11:20 AM, Cary Coutant <ccoutant@gmail.com> wrote:
>>         PR gold/21857
>>         * elfcpp.h (Chdr_write): Add clear_ch_reserved.
>
> I'd prefer an API that just sets the field to a given value (and a
> corresponding one to read it). Let's treat it like st_other.

Like this?

-- 
H.J.
From 53959882cbd46bad9df83ec309d39cc23f1f2797 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 28 Jul 2017 11:01:14 -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.

gold/

	PR gold/21857
	* compressed_output.cc (Chdr_write<64, true>::put_ch_reserved):
	New.
	(Chdr_write<64, false>::put_ch_reserved): Likewise.
	(Output_compressed_section::set_final_data_size): Call
	put_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..38be4209bf 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
+  put_ch_reserved(Elf_Word);
+
  private:
   internal::Chdr_data<size>* p_;
 };
diff --git a/gold/compressed_output.cc b/gold/compressed_output.cc
index 4374ba1bb7..3acb9f460c 100644
--- a/gold/compressed_output.cc
+++ b/gold/compressed_output.cc
@@ -26,6 +26,20 @@
 #include "options.h"
 #include "compressed_output.h"
 
+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;
+}
+
 namespace gold
 {
 
@@ -286,6 +300,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 +309,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.13.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]