summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 */