aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bfd/elf.c2
-rw-r--r--ld/testsuite/ld-elf/pr30508.d13
-rw-r--r--ld/testsuite/ld-elf/pr30508.s14
3 files changed, 29 insertions, 0 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index 94954a8..81eb3ef 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7210,10 +7210,12 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd, bfd_vma maxpagesize)
no sections, but ordinary, loadable segments should contain
something. They are allowed by the ELF spec however, so only
a warning is produced.
+ Don't warn if an empty PT_LOAD contains the program headers.
There is however the valid use case of embedded systems which
have segments with p_filesz of 0 and a p_memsz > 0 to initialize
flash memory with zeros. No warning is shown for that case. */
if (segment->p_type == PT_LOAD
+ && !map->includes_phdrs
&& (segment->p_filesz > 0 || segment->p_memsz == 0))
/* xgettext:c-format */
_bfd_error_handler
diff --git a/ld/testsuite/ld-elf/pr30508.d b/ld/testsuite/ld-elf/pr30508.d
new file mode 100644
index 0000000..35f6615
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr30508.d
@@ -0,0 +1,13 @@
+#ld: -z separate-code
+#objcopy_linked_file: -R .foo
+#readelf: -lW
+#target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
+#xfail: h8300-*-* mips*-*-* rx-*-linux*
+
+#...
+ Section to Segment mapping:
+ Segment Sections...
+#...
+ 0.
+#...
+ 0. .text
diff --git a/ld/testsuite/ld-elf/pr30508.s b/ld/testsuite/ld-elf/pr30508.s
new file mode 100644
index 0000000..5a2778c
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr30508.s
@@ -0,0 +1,14 @@
+ .text
+ .global start /* Used by SH targets. */
+start:
+ .global _start
+_start:
+ .global __start
+__start:
+ .global main /* Used by HPPA targets. */
+main:
+ .globl _main /* Used by LynxOS targets. */
+_main:
+ .dc.a 0
+ .section .foo,"ax",%progbits
+ .dc.a 0