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: [committed, PATCH] Change ch_type in Elf64_External_Chdr to 4 bytes


On Mon, Sep 21, 2015 at 3:51 PM, Alan Modra <amodra@gmail.com> wrote:
> On Mon, Sep 21, 2015 at 10:23:09AM -0700, H.J. Lu wrote:
>> The ch_type field in Elf64_External_Chdr is 4 bytes, followed by a
>> 4-byte padding.  This change doesn't introduce any functional change
>> since only the lower 32 bits of the ch_type field are used.
>>
>>       * external.h (Elf64_External_Chdr): Change ch_type to 4 bytes
>>       and add ch_reserved.
>
> Since you are still writing the field using bfd_put_64, big-endian
> targets of course will continue to write their low 32-bits into
> ch_type[4..7].  You can't change this struct without making changes to
> the code.  Which means breaking backwards compatibility, but I guess
> we'll need to live with that.
>

Oops.  I checked in this patch to fix it.

Sorry for that.

-- 
H.J.
From c8b187ea07f534bac147cbbc44dd08925f5734b0 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Mon, 21 Sep 2015 19:38:40 -0700
Subject: [PATCH] Use bfd_get_32 and bfd_put_32 to access ch_type

The ch_type field in Elf64_External_Chdr is 4 bytes.  We should use
bfd_get_32 and bfd_put_32 to access it.

	* bfd.c (bfd_update_compression_header): Use bfd_put_32 on
	ch_type.
	(bfd_check_compression_header): Use bfd_get_32 on ch_type.
	(bfd_convert_section_contents): Use bfd_get_32 and bfd_put_32
	on ch_type.
---
 bfd/ChangeLog | 8 ++++++++
 bfd/bfd.c     | 8 ++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 37ba69f..d63d55b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,11 @@
+2015-09-21  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* bfd.c (bfd_update_compression_header): Use bfd_put_32 on
+	ch_type.
+	(bfd_check_compression_header): Use bfd_get_32 on ch_type.
+	(bfd_convert_section_contents): Use bfd_get_32 and bfd_put_32
+	on ch_type.
+
 2015-09-20  Rich Felker  <dalias@libc.org>
 
 	* elflink.c (_bfd_elf_link_create_dynamic_sections): Don't create
diff --git a/bfd/bfd.c b/bfd/bfd.c
index c02edbe..449dfe6 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2000,7 +2000,7 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
 		{
 		  Elf64_External_Chdr *echdr
 		    = (Elf64_External_Chdr *) contents;
-		  bfd_put_64 (abfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
+		  bfd_put_32 (abfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
 		  bfd_put_64 (abfd, sec->size, &echdr->ch_size);
 		  bfd_put_64 (abfd, 1 << sec->alignment_power,
 			      &echdr->ch_addralign);
@@ -2061,7 +2061,7 @@ bfd_check_compression_header (bfd *abfd, bfd_byte *contents,
       else
 	{
 	  Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) contents;
-	  chdr.ch_type = bfd_get_64 (abfd, &echdr->ch_type);
+	  chdr.ch_type = bfd_get_32 (abfd, &echdr->ch_type);
 	  chdr.ch_size = bfd_get_64 (abfd, &echdr->ch_size);
 	  chdr.ch_addralign = bfd_get_64 (abfd, &echdr->ch_addralign);
 	}
@@ -2222,7 +2222,7 @@ bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd,
   else
     {
       Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) contents;
-      chdr.ch_type = bfd_get_64 (ibfd, &echdr->ch_type);
+      chdr.ch_type = bfd_get_32 (ibfd, &echdr->ch_type);
       chdr.ch_size = bfd_get_64 (ibfd, &echdr->ch_size);
       chdr.ch_addralign = bfd_get_64 (ibfd, &echdr->ch_addralign);
 
@@ -2249,7 +2249,7 @@ bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd,
   else
     {
       Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) contents;
-      bfd_put_64 (obfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
+      bfd_put_32 (obfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
       bfd_put_64 (obfd, chdr.ch_size, &echdr->ch_size);
       bfd_put_64 (obfd, chdr.ch_addralign, &echdr->ch_addralign);
     }
-- 
2.4.3


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