Check ELF section header only for ELF output
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 2 Aug 2017 12:10:29 +0000 (05:10 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 2 Aug 2017 12:10:48 +0000 (05:10 -0700)
When placing an orphan input section, check ELF section header only for
ELF output.

PR ld/21884
* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Check
ELF section header only for ELF output.
* testsuite/ld-elf/pr21884.d: New test.
* testsuite/ld-elf/pr21884.t: Likewise.
* testsuite/ld-elf/pr21884a.s: Likewise.
* testsuite/ld-elf/pr21884b.s: Likewise.

ld/ChangeLog
ld/emultempl/elf32.em
ld/testsuite/ld-elf/pr21884.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21884.t [new file with mode: 0644]
ld/testsuite/ld-elf/pr21884a.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr21884b.s [new file with mode: 0644]

index 14c6edd5d1e3366bc931bb6ae7d633228f7bba6f..3b9162df46a1243612198a1f6ef50316fe3fdeb2 100644 (file)
@@ -1,3 +1,13 @@
+2017-08-02  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/21884
+       * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Check
+       ELF section header only for ELF output.
+       * testsuite/ld-elf/pr21884.d: New test.
+       * testsuite/ld-elf/pr21884.t: Likewise.
+       * testsuite/ld-elf/pr21884a.s: Likewise.
+       * testsuite/ld-elf/pr21884b.s: Likewise.
+
 2017-08-02  H.J. Lu  <hongjiu.lu@intel.com>
 
        * emultempl/elf32.em (_place_orphan): Revert the last change.
index d2551b6f2c01b7f9bb4c9bc73842c9142926f289..75ded127f3a13c6c10c53bc235d635394f3e45d0 100644 (file)
@@ -2136,7 +2136,8 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
     }
 
   /* Look through the script to see where to place this section.  */
-  if (constraint == 0)
+  if (constraint == 0
+      && link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour)
     for (os = lang_output_section_find (secname);
         os != NULL;
         os = next_matching_output_section_statement (os, 0))
diff --git a/ld/testsuite/ld-elf/pr21884.d b/ld/testsuite/ld-elf/pr21884.d
new file mode 100644 (file)
index 0000000..52cd2c1
--- /dev/null
@@ -0,0 +1,11 @@
+#source: pr21884a.s
+#source: pr21884b.s
+#ld: -T pr21884.t
+#objdump: -b binary -s
+#notarget: aarch64*-*-* arm*-*-* nds32*-*-*
+# Skip targets which can't change output format to binary.
+
+.*:     file format binary
+
+Contents of section .data:
+#pass
diff --git a/ld/testsuite/ld-elf/pr21884.t b/ld/testsuite/ld-elf/pr21884.t
new file mode 100644 (file)
index 0000000..d483911
--- /dev/null
@@ -0,0 +1,7 @@
+OUTPUT_FORMAT("binary")
+
+ENTRY(_main);
+SECTIONS {
+       . = 0;
+       .setup : { *(.setup) }
+}
diff --git a/ld/testsuite/ld-elf/pr21884a.s b/ld/testsuite/ld-elf/pr21884a.s
new file mode 100644 (file)
index 0000000..a3361b2
--- /dev/null
@@ -0,0 +1,5 @@
+       .text
+       .globl  _main
+       .type _main,%function
+_main:
+       .dc.a bar
diff --git a/ld/testsuite/ld-elf/pr21884b.s b/ld/testsuite/ld-elf/pr21884b.s
new file mode 100644 (file)
index 0000000..e533837
--- /dev/null
@@ -0,0 +1,5 @@
+       .text
+       .globl  bar
+       .type bar,%function
+bar:
+       .byte 0
This page took 0.034933 seconds and 4 git commands to generate.