Set no file contents PT_LOAD p_offset to first page
[deliverable/binutils-gdb.git] / bfd / elf.c
index 1aa2603ee8ce010377c7db66dd81118cc1dda28c..fd447fdb281e5de1cd3cbb5917a57ac80ffd1f0e 100644 (file)
--- 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;
This page took 0.023483 seconds and 4 git commands to generate.