]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
meaningless p_offset for zero p_filesz PT_LOAD
authorAlan Modra <amodra@gmail.com>
Mon, 10 Mar 2025 12:32:19 +0000 (23:02 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 10 Mar 2025 12:32:19 +0000 (23:02 +1030)
This patch avoids generating PT_LOAD segments that trip a bug in
glibc's loader.

PR 25237
PR 32763
* elf.c (assign_file_positions_for_load_sections): Don't put
p_offset zero for empty PT_LOAD.

bfd/elf.c

index 20f96e689ce49288db0df79d5b90a5f5ea21a8fb..ee89dd909dafb4d70a0a781a769d139fc926f6ce 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -6170,7 +6170,10 @@ assign_file_positions_for_load_sections (bfd *abfd,
                    align = p->p_align;
                  if (align < 1)
                    align = 1;
-                 p->p_offset = off % align;
+                 /* Avoid p_offset of zero, which might be wrongly
+                    interpreted as the segment being the first one,
+                    containing the file header.  PR32763.  */
+                 p->p_offset = (off + align - 1) % align + 1;
                }
            }
          else