This is the mail archive of the
mailing list for the binutils project.
[PATCH] elf: Try not pointing empty PT_LOAD segment's offset past EOF
- From: Bálint Réczey <balint at balintreczey dot hu>
- To: binutils at sourceware dot org
- Date: Sat, 7 Dec 2019 17:22:13 +0100
- Subject: [PATCH] elf: Try not pointing empty PT_LOAD segment's offset past EOF
- Reply-to: balint at balintreczey dot hu
Strip sometimes leaves file offset of empty PT_LOAD segment pointing
past end of file as observed on Ubuntu 19.10's gzip binary. This is
traditionally considered a non-issue as loaders tolerated that, but
WSL1's ELF loader does not run the gzip binary  due to this offset.
I have opened a bug  in bugzilla, but I was advised to send the
patch here, too.
Please consider accepting the patch. I believe this does not cause any
regression and it fixes ELF loading on WSL.
From 547345d59b5a1e682c0cb7dc7f3f29ec8c113122 Mon Sep 17 00:00:00 2001
From: Balint Reczey <email@example.com>
Date: Fri, 29 Nov 2019 23:58:00 +0100
Subject: [PATCH] elf: Try not pointing empty PT_LOAD segment's offset past EOF
While this did not cause problems in the past, it crashes WSL's ELF loader.
bfd/elf.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/bfd/elf.c b/bfd/elf.c
index 1aa2603ee8..e1a9a02eec 100644
@@ -5752,7 +5752,12 @@ 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;
+ if (no_contents)
+ /* Try avoiding pointing past the EOF with this empty segment's
+ p_offset. */
+ p->p_offset = p->p_offset % maxpagesize;
+ p->p_offset = off;