This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] elf: Try not pointing empty PT_LOAD segment's offset past EOF


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 [1] due to this offset.

I have opened a bug [2] 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 <>
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
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -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;
+	    else
+	      p->p_offset = off;
 	      file_ptr adjust;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]