summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-11-24 15:47:10 -0800
committerH.J. Lu <hjl.tools@gmail.com>2017-11-25 06:14:09 -0800
commit5876dfdf1bfb7cb605bd47397d63fcd3cbb58592 (patch)
treef2fb2e67642e6dc50317b979e88ea00835d0bb8c
parent685de8c2990a04fba5e2954b7ff089a2c641071f (diff)
downloadbinutils-gdb-users/hjl/pr22492.tar.gz
as: Align note section to 4 bytesusers/hjl/pr22492
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.
-rw-r--r--binutils/readelf.c14
-rw-r--r--gas/config/obj-elf.c2
2 files changed, 14 insertions, 2 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 739367d899b..f44fa20c06f 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 3f641f4394b..768812748e8 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 */