This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] elf: Try not pointing empty PT_LOAD segment's offset past EOF
On Fri, Dec 13, 2019 at 10:32:19AM +0100, Bálint Réczey wrote:
> Hi Alan,
>
> Bálint Réczey <balint@balintreczey.hu> ezt írta (időpont: 2019. dec.
> 11., Sze, 12:44):
> >
> > Alan Modra <amodra@gmail.com> ezt írta (időpont: 2019. dec. 11., Sze, 12:02):
> > >
> ...
> > > "p->p_offset = off % maxpagesize" might be OK, I think.
> >
> > That's perfect, thanks. Attaching the updated patch.
>
> I have attached the updated patch to to bug, too.
> Would you like me to perform any specific additional testing?
I've run the binutils testsuite over multiple targets without seeing
any problems so will commit the following variant.
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/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;
--
Alan Modra
Australia Development Lab, IBM