Skip to content

Instantly share code, notes, and snippets.

@pablogsal
Created January 2, 2024 20:15
Show Gist options
  • Save pablogsal/a55e1ea40b867af68deeeb26d3762e2b to your computer and use it in GitHub Desktop.
Save pablogsal/a55e1ea40b867af68deeeb26d3762e2b to your computer and use it in GitHub Desktop.
diff --git a/bfd/elf.c b/bfd/elf.c
index 84a5d94281..a0bd5203f5 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5943,6 +5943,11 @@ assign_file_positions_for_load_sections (bfd *abfd,
link_info->callbacks->info ("%X");
}
+ /* If we have a PT_LOAD segment with no sections that is empty,
+ then we need to drop it or some loaders will complain. */
+ if (m->count == 0 && p->p_type == PT_LOAD && p->p_filesz == 0 && p->p_memsz == 0) {
+ p->p_type = PT_NULL;
+ }
/* Check that all sections are in a PT_LOAD segment.
Don't check funky gdb generated core files. */
if (p->p_type == PT_LOAD && bfd_get_format (abfd) != bfd_core)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment