aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bfd/elf.c5
-rw-r--r--binutils/objcopy.c4
2 files changed, 9 insertions, 0 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index 2aa2337..45e19f4 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -6721,6 +6721,11 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd)
}
}
+ /* Remove the segment from output if all sections in input have
+ been removed. */
+ if (first_section != NULL && section_count == 0)
+ continue;
+
/* Allocate a segment map big enough to contain
all of the sections we have selected. */
amt = sizeof (struct elf_segment_map);
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 23a949d..33794a0 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -4206,6 +4206,8 @@ strip_main (int argc, char *argv[])
break;
case OPTION_ONLY_KEEP_DEBUG:
strip_symbols = STRIP_NONDEBUG;
+ /* Also remove invalid .dynamic section. */
+ handle_remove_section_option (".dynamic");
break;
case OPTION_KEEP_FILE_SYMBOLS:
keep_file_symbols = 1;
@@ -4582,6 +4584,8 @@ copy_main (int argc, char *argv[])
case OPTION_ONLY_KEEP_DEBUG:
strip_symbols = STRIP_NONDEBUG;
+ /* Also remove invalid .dynamic section. */
+ handle_remove_section_option (".dynamic");
break;
case OPTION_KEEP_FILE_SYMBOLS: