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]

[PATCH] as: Align note section to 4 bytes


On Fri, Nov 24, 2017 at 3:49 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> gABI specifies that PT_NOTE alignment should be aligned to 4 bytes
> for 32-bit objects and to 8 bytes for 64-bit objects.  But on Linux,
> .note.ABI-tag and .note.gnu.build-id notes are always aligned to 4
> bytes.  We allow either 4 byte or 8 byte alignments.
>
> OK for master?
>
> H.J.
> ---
>         * readelf.c (process_notes_at): Return FALSE if alignment of
>         note section isn't 4 nor 8 bytes.

This patch is incorrect.  Here is the updated patch, which also fixes
incorrect note section alignment:

https://sourceware.org/bugzilla/show_bug.cgi?id=22492

-- 
H.J.
From 5876dfdf1bfb7cb605bd47397d63fcd3cbb58592 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 24 Nov 2017 15:47:10 -0800
Subject: [PATCH] as: Align note section to 4 bytes

gABI specifies that notes should be aligned to 4 bytes in 32-bit objects
and to 8 bytes in 64-bit objects.  As a Linux extension, we support 4
byte alignment in 64-bit objects.  obj_elf_version and sco_id pad note
section to 4 byte alignment:

frag_align (2, 0, 0);

They should set section alignment to 4 bytes.  When dumping note sections,
if section alignment is less than 4, we treate alignment as 4 bytes to
handle note sections with incorrect section alignment.

binutils/

	PR gas/22492
	* readelf.c (process_notes_at): If section alignment is less
	than 4, use 4 byte alignment.

gas/

	PR gas/22492
	* config/obj-elf.c (obj_elf_version): Align note section to 4
	bytes.
	(sco_id): Likewise.
---
 binutils/readelf.c   | 14 ++++++++++++--
 gas/config/obj-elf.c |  2 ++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 739367d899..f44fa20c06 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -17910,6 +17910,7 @@ process_notes_at (Filedata *           filedata,
   Elf_External_Note * external;
   char * end;
   bfd_boolean res = TRUE;
+  bfd_vma align;
 
   if (length <= 0)
     return FALSE;
@@ -17937,6 +17938,15 @@ process_notes_at (Filedata *           filedata,
     printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
 	    (unsigned long) offset, (unsigned long) length);
 
+  /* NB: Some note sections may have alignment value of 0 or 1.  gABI
+     specifies that notes should be aligned to 4 bytes in 32-bit
+     objects and to 8 bytes in 64-bit objects.  As a Linux extension,
+     we also support 4 byte alignment in 64-bit objects.  If section
+     alignment is less than 4, we treate alignment as 4 bytes.   */
+  align = section->sh_addralign;
+  if (align < 4)
+    align = 4;
+
   printf (_("  %-20s %10s\tDescription\n"), _("Owner"), _("Data size"));
 
   end = (char *) pnotes + length;
@@ -17971,11 +17981,11 @@ process_notes_at (Filedata *           filedata,
 	  inote.descsz   = BYTE_GET (external->descsz);
 	  inote.descdata = ((char *) external
 			    + ELF_NOTE_DESC_OFFSET (inote.namesz,
-						    section->sh_addralign));
+						    align));
 	  inote.descpos  = offset + (inote.descdata - (char *) pnotes);
 	  next = ((char *) external
 		  + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz,
-					  section->sh_addralign));
+					  align));
 	}
       else
 	{
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 3f641f4394..768812748e 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -1829,6 +1829,7 @@ obj_elf_version (int ignore ATTRIBUTE_UNUSED)
       bfd_set_section_flags (stdoutput,
 			     note_secp,
 			     SEC_HAS_CONTENTS | SEC_READONLY);
+      bfd_set_section_alignment (stdoutput, note_secp, 2);
 
       /* Process the version string.  */
       len = strlen (name) + 1;
@@ -2684,6 +2685,7 @@ sco_id (void)
   bfd_set_section_flags (stdoutput,
 			 note_secp,
 			 SEC_HAS_CONTENTS | SEC_READONLY);
+  bfd_set_section_alignment (stdoutput, note_secp, 2);
 
   /* process the version string */
 
-- 
2.14.3


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