summaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-11-24 06:41:40 -0800
committerH.J. Lu <hjl.tools@gmail.com>2017-11-24 06:41:52 -0800
commit650444eb540f9fd85e821567a3f943b4bc41b8be (patch)
tree2c5e0bf7934a74df34cfd3a0c9377d62903717bb /binutils
parenta63f2d2feedcfce401ae1d7d03d119bfa5e4d8bc (diff)
elf: Properly compute offsets of note descriptor and next note
According to gABI, in a note entry, the note name field, not note name size, is padded for the note descriptor. And the note descriptor field, not note descriptor size, is padded for the next note entry. Also notes are aligned to 4 bytes in 32-bit objects and 8 bytes in 64-bit objects. Since on Linux, .note.ABI-tag and .note.gnu.build-id notes are always aligned to 4 bytes, we need to use alignment of note section or note segment, instead of assuming alignment based on ELF file class. Tested on i686 and x86-64. bfd/ PR binutils/22444 * elf.c (elf_read_notes): Add an argument for note aligment. (elf_parse_notes): Likewise. (_bfd_elf_make_section_from_shdr): Pass section aligment to elf_parse_notes. (bfd_section_from_phdr): Pass segment aligment to elf_read_notes. (elf_parse_notes): Add an argument for note aligment. Use ELF_NOTE_DESC_OFFSET to get the offset of the note descriptor. Use ELF_NOTE_NEXT_OFFSET to get the offset of the next note entry. (elf_read_notes): Add an argument for note aligment and pass it to elf_parse_notes. binutils/ PR binutils/22444 * readelf.c (process_notes_at): Use ELF_NOTE_DESC_OFFSET to get the offset of the note descriptor. Use ELF_NOTE_NEXT_OFFSET to get the offset of the next note entry. include/ PR binutils/22444 * elf/external.h (ELF_ALIGN_UP): New. (ELF_NOTE_DESC_OFFSET): Likewise. (ELF_NOTE_NEXT_OFFSET): Likewise.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog7
-rw-r--r--binutils/readelf.c8
2 files changed, 13 insertions, 2 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 32df4b98f7..eab683047e 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,10 @@
+2017-11-24 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR binutils/22444
+ * readelf.c (process_notes_at): Use ELF_NOTE_DESC_OFFSET to get
+ the offset of the note descriptor. Use ELF_NOTE_NEXT_OFFSET to
+ get the offset of the next note entry.
+
2017-11-23 Pavel I. Kryukov <kryukov@frtk.ru>
PR 22485
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 5944ebee96..739367d899 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -17969,9 +17969,13 @@ process_notes_at (Filedata * filedata,
inote.namesz = BYTE_GET (external->namesz);
inote.namedata = external->name;
inote.descsz = BYTE_GET (external->descsz);
- inote.descdata = inote.namedata + align_power (inote.namesz, 2);
+ inote.descdata = ((char *) external
+ + ELF_NOTE_DESC_OFFSET (inote.namesz,
+ section->sh_addralign));
inote.descpos = offset + (inote.descdata - (char *) pnotes);
- next = inote.descdata + align_power (inote.descsz, 2);
+ next = ((char *) external
+ + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz,
+ section->sh_addralign));
}
else
{