From: Alan Modra Date: Fri, 13 Dec 2019 05:44:57 +0000 (+1030) Subject: Set no file contents PT_LOAD p_offset to first page X-Git-Url: http://git.efficios.com/?p=deliverable%2Fbinutils-gdb.git;a=commitdiff_plain;h=0bc3450e220a4fb29f931ada84b546ce8993e85e Set no file contents PT_LOAD p_offset to first page PR 25237 * elf.c (assign_file_positions_for_load_sections): Attempt to keep meaningless p_offset for PT_LOAD segments without file contents within file size. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 7c3cf2906f..f1a707d373 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2019-12-13 Alan Modra + + PR 25237 + * elf.c: (assign_file_positions_for_load_sections): Attempt to + keep meaningless p_offset for PT_LOAD segments without file + contents within file size. + 2019-12-12 Alan Modra * libbfd.c (bfd_get): Don't cast result of bfd_get_8. diff --git a/bfd/elf.c b/bfd/elf.c index 1aa2603ee8..fd447fdb28 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5752,7 +5752,15 @@ assign_file_positions_for_load_sections (bfd *abfd, || (p->p_type == PT_NOTE && bfd_get_format (abfd) == bfd_core)) { if (!m->includes_filehdr && !m->includes_phdrs) - p->p_offset = off; + { + p->p_offset = off; + if (no_contents) + /* Put meaningless p_offset for PT_LOAD segments + without file contents somewhere within the first + page, in an attempt to not point past EOF. */ + p->p_offset = off % (p->p_align > maxpagesize + ? p->p_align : maxpagesize); + } else { file_ptr adjust;