summary refs log tree commit diff
path: root/pkgs/development/tools/misc/binutils/elf-check-orphan-input.patch
blob: 2ec90128347e78bf6466ccad3c4d6f034265b108 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
From a388b7afeffad6411686d39dc1c62294da48a814 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 2 Aug 2017 05:10:29 -0700
Subject: [PATCH] Check ELF section header only for ELF output

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.

(cherry picked from commit db99ecc08f5b66fbe9cb72e90352c7f77ec71a6e)
---
 ld/ChangeLog                   | 10 ++++++++++
 ld/emultempl/elf32.em          |  3 ++-
 ld/testsuite/ld-elf/pr21884.d  | 11 +++++++++++
 ld/testsuite/ld-elf/pr21884.t  |  7 +++++++
 ld/testsuite/ld-elf/pr21884a.s |  5 +++++
 ld/testsuite/ld-elf/pr21884b.s |  5 +++++
 6 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-elf/pr21884.d
 create mode 100644 ld/testsuite/ld-elf/pr21884.t
 create mode 100644 ld/testsuite/ld-elf/pr21884a.s
 create mode 100644 ld/testsuite/ld-elf/pr21884b.s

diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index d2551b6..75ded12 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -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
index 0000000..52cd2c1
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21884.d
@@ -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
index 0000000..d483911
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21884.t
@@ -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
index 0000000..a3361b2
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21884a.s
@@ -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
index 0000000..e533837
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21884b.s
@@ -0,0 +1,5 @@
+	.text
+	.globl	bar
+	.type bar,%function
+bar:
+	.byte 0
-- 
2.9.3