This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] gold: PR gold/21857: Add clear_ch_reserved to 64-bit Chdr_write
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Cary Coutant <ccoutant at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Fri, 28 Jul 2017 11:48:56 -0700
- Subject: Re: [PATCH] gold: PR gold/21857: Add clear_ch_reserved to 64-bit Chdr_write
- Authentication-results: sourceware.org; auth=none
- References: <20170728180729.GA3502@gmail.com> <CAJimCsFghvnKjmPkH9SmkDPm7HhY=1uQ2U0LYs3HJc-_HHPpFg@mail.gmail.com> <CAMe9rOpEhZxbqo3AiYxU7ViKuCvj7PB1_FjL_xzwbxnzFpSUvQ@mail.gmail.com>
On Fri, Jul 28, 2017 at 11:29 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> 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?
>
Move put_ch_reserved to elfcpp.h.
--
H.J.
From 8139cae005efb47a7c2fecd3160458fe33ccccf2 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.
(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/elfcpp.h | 17 +++++++++++++++++
gold/compressed_output.cc | 4 ++++
2 files changed, 21 insertions(+)
diff --git a/elfcpp/elfcpp.h b/elfcpp/elfcpp.h
index a57f5476f1..cccec4c256 100644
--- a/elfcpp/elfcpp.h
+++ b/elfcpp/elfcpp.h
@@ -1351,10 +1351,27 @@ 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_;
};
+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<int size, bool big_endian>
diff --git a/gold/compressed_output.cc b/gold/compressed_output.cc
index 4374ba1bb7..45077f7020 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.13.3