]> git.pld-linux.org Git - packages/binutils.git/blame - pr14052.patch
- rel 4
[packages/binutils.git] / pr14052.patch
CommitLineData
34457ba3
JR
1--- a/bfd/bfd-in.h
2+++ a/bfd/bfd-in.h
3@@ -703,6 +703,9 @@ _bfd_nearby_section (bfd *, struct bfd_section *, bfd_vma);
4 extern void _bfd_fix_excluded_sec_syms
5 (bfd *, struct bfd_link_info *);
6
7+extern void _bfd_keep_sections_with_sym
8+ (bfd *, struct bfd_link_info *);
9+
10 extern unsigned bfd_m68k_mach_to_features (int);
11
12 extern int bfd_m68k_features_to_mach (unsigned);
13--- a/bfd/bfd-in2.h
14+++ a/bfd/bfd-in2.h
15@@ -710,6 +710,9 @@ _bfd_nearby_section (bfd *, struct bfd_section *, bfd_vma);
16 extern void _bfd_fix_excluded_sec_syms
17 (bfd *, struct bfd_link_info *);
18
19+extern void _bfd_keep_sections_with_sym
20+ (bfd *, struct bfd_link_info *);
21+
22 extern unsigned bfd_m68k_mach_to_features (int);
23
24 extern int bfd_m68k_features_to_mach (unsigned);
25--- a/bfd/linker.c
26+++ a/bfd/linker.c
27@@ -3198,11 +3198,6 @@ _bfd_nearby_section (bfd *obfd, asection *s, bfd_vma addr)
28 best = prev;
29 }
30
31- /* Refuse to choose a section for which we are out of bounds. */
32- /* ??? This may make most of the above moot. */
33- if (addr < best->vma || addr > best->vma + best->size)
34- best = bfd_abs_section_ptr;
35-
36 return best;
37 }
38
39@@ -3240,6 +3235,36 @@ _bfd_fix_excluded_sec_syms (bfd *obfd, struct bfd_link_info *info)
40 bfd_link_hash_traverse (info->hash, fix_syms, obfd);
41 }
42
43+/* Keep sections with symbols. */
44+
45+static bfd_boolean
46+keep_sections_with_sym (struct bfd_link_hash_entry *h, void *data)
47+{
48+ bfd *obfd = (bfd *) data;
49+
50+ if (h->type == bfd_link_hash_defined
51+ || h->type == bfd_link_hash_defweak)
52+ {
53+ asection *s = h->u.def.section;
54+ if (s != NULL
55+ && (s->flags
56+ & (SEC_LINKER_CREATED | SEC_EXCLUDE | SEC_KEEP)) == 0
57+ && s->output_section != NULL
58+ && (s->output_section->flags
59+ & (SEC_LINKER_CREATED | SEC_EXCLUDE | SEC_KEEP)) == 0
60+ && !bfd_section_removed_from_list (obfd, s->output_section))
61+ s->output_section->flags |= SEC_KEEP;
62+ }
63+
64+ return TRUE;
65+}
66+
67+void
68+_bfd_keep_sections_with_sym (bfd *obfd, struct bfd_link_info *info)
69+{
70+ bfd_link_hash_traverse (info->hash, keep_sections_with_sym, obfd);
71+}
72+
73 /*
74 FUNCTION
75 bfd_generic_define_common_symbol
76--- a/ld/ldlang.c
77+++ a/ld/ldlang.c
78@@ -3858,6 +3858,9 @@ strip_excluded_output_sections (void)
79 lang_reset_memory_regions ();
80 }
81
82+ if (!link_info.relocatable)
83+ _bfd_keep_sections_with_sym (link_info.output_bfd, &link_info);
84+
85 for (os = &lang_output_section_statement.head->output_section_statement;
86 os != NULL;
87 os = os->next)
88--- a/ld/testsuite/ld-elf/pr14052.d
89+++ a/ld/testsuite/ld-elf/pr14052.d
90@@ -0,0 +1,8 @@
91+#source: start.s
92+#ld: -T pr14052.t
93+#readelf: -s
94+
95+#failif
96+#...
97+ +[0-9]+: +[0-9a-f]+ +0 +(OBJECT|NOTYPE) +GLOBAL +DEFAULT +ABS _data_start
98+#...
99--- a/ld/testsuite/ld-elf/pr14052.t
100+++ a/ld/testsuite/ld-elf/pr14052.t
101@@ -0,0 +1,11 @@
102+SECTIONS {
103+ .text : {
104+ *(.text)
105+ }
106+ . = ALIGN (0x1000);
107+ .data : {
108+ _data_start = .;
109+ *(.data)
110+ }
111+ /DISCARD/ : { *(.*) }
112+}
113--- a/ld/testsuite/ld-elf/warn2.d
114+++ a/ld/testsuite/ld-elf/warn2.d
115@@ -13,5 +13,5 @@
116 # construct and that the symbol still appears as expected.
117
118 #...
119- +[0-9]+: +[0-9a-f]+ +20 +OBJECT +GLOBAL +DEFAULT +ABS Foo
120+ +[0-9]+: +[0-9a-f]+ +20 +OBJECT +GLOBAL +DEFAULT +[1-9] Foo
121 #pass
122--- a/ld/testsuite/ld-elf/zerosize1.d
123+++ a/ld/testsuite/ld-elf/zerosize1.d
124@@ -1,10 +1,12 @@
125 #source: start.s
126 #source: zerosize1.s
127-#ld:
128-#readelf: -s
129+#ld: -T zerosize1.t
130+#readelf: -sS --wide
131
132 # Check that xyzzy is not placed in the .text section.
133
134 #...
135- +[0-9]+: +[0-9a-f]+ +0 +(OBJECT|NOTYPE) +GLOBAL +DEFAULT +ABS xyzzy
136+ \[[ 2]+\] zerosize[ \t]+PROGBITS[ \t0-9a-f]+WA.*
137+#...
138+ +[0-9]+: +[0-9a-f]+ +0 +(OBJECT|NOTYPE) +GLOBAL +DEFAULT +2 xyzzy
139 #pass
140--- a/ld/testsuite/ld-elf/zerosize1.t
141+++ a/ld/testsuite/ld-elf/zerosize1.t
142@@ -0,0 +1,5 @@
143+SECTIONS {
144+ .text : { *(.text) }
145+ .zerosize : { *(.zerosize) }
146+ /DISCARD/ : { *(.*) }
147+}
This page took 0.092515 seconds and 4 git commands to generate.