]>
Commit | Line | Data |
---|---|---|
f9e6bfa8 | 1 | # This shell script emits a C file. -*- C -*- |
219d1afa | 2 | # Copyright (C) 2003-2018 Free Software Foundation, Inc. |
f9e6bfa8 | 3 | # |
f96b4a7b | 4 | # This file is part of the GNU Binutils. |
f9e6bfa8 AM |
5 | # |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
f96b4a7b | 8 | # the Free Software Foundation; either version 3 of the License, or |
f9e6bfa8 AM |
9 | # (at your option) any later version. |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
f96b4a7b NC |
18 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | # MA 02110-1301, USA. | |
f9e6bfa8 AM |
20 | # |
21 | ||
c9a2f333 | 22 | # This file is sourced from elf32.em, and defines extra powerpc32-elf |
f9e6bfa8 AM |
23 | # specific routines. |
24 | # | |
92b93329 | 25 | fragment <<EOF |
f9e6bfa8 | 26 | |
f9e6bfa8 | 27 | #include "elf32-ppc.h" |
f05eb3b7 | 28 | #include "ldlex.h" |
b4ab4364 | 29 | #include "ldlang.h" |
f9e6bfa8 | 30 | |
5503fea1 AM |
31 | #define is_ppc_elf(bfd) \ |
32 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
4dfe6ac6 | 33 | && elf_object_id (bfd) == PPC32_ELF_DATA) |
c9a2f333 | 34 | |
f9e6bfa8 AM |
35 | /* Whether to run tls optimization. */ |
36 | static int notlsopt = 0; | |
37 | ||
5446cbdf | 38 | /* Choose the correct place for .got. */ |
0cf7d72c AM |
39 | static int old_got = 0; |
40 | ||
407aa07c | 41 | static struct ppc_elf_params params = { PLT_UNSET, 0, -1, |
9e390558 | 42 | 0, 0, 0, 0, 0, 0, 0 }; |
5446cbdf AM |
43 | |
44 | static void | |
45 | ppc_after_open_output (void) | |
46 | { | |
47 | if (params.emit_stub_syms < 0) | |
0e1862bb L |
48 | params.emit_stub_syms = (link_info.emitrelocations |
49 | || bfd_link_pic (&link_info)); | |
76e7a751 AM |
50 | if (params.pagesize == 0) |
51 | params.pagesize = config.commonpagesize; | |
5446cbdf AM |
52 | ppc_elf_link_params (&link_info, ¶ms); |
53 | } | |
54 | ||
db434ba0 AM |
55 | EOF |
56 | ||
57 | # No --secure-plt, --bss-plt, or --sdata-got for vxworks. | |
58 | if test -z "$VXWORKS_BASE_EM_FILE" ; then | |
59 | fragment <<EOF | |
0cf7d72c | 60 | static void |
5c3261b0 | 61 | ppc_after_check_relocs (void) |
0cf7d72c | 62 | { |
5503fea1 | 63 | if (is_ppc_elf (link_info.output_bfd)) |
0cf7d72c AM |
64 | { |
65 | int new_plt; | |
66 | int keep_new; | |
67 | unsigned int num_plt; | |
68 | unsigned int num_got; | |
69 | lang_output_section_statement_type *os; | |
70 | lang_output_section_statement_type *plt_os[2]; | |
71 | lang_output_section_statement_type *got_os[2]; | |
72 | ||
5446cbdf | 73 | new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info); |
0cf7d72c | 74 | if (new_plt < 0) |
d003af55 | 75 | einfo (_("%X%P: select_plt_layout problem %E\n")); |
0cf7d72c AM |
76 | |
77 | num_got = 0; | |
78 | num_plt = 0; | |
79 | for (os = &lang_output_section_statement.head->output_section_statement; | |
80 | os != NULL; | |
81 | os = os->next) | |
82 | { | |
83 | if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0) | |
84 | { | |
85 | if (num_plt < 2) | |
86 | plt_os[num_plt] = os; | |
87 | ++num_plt; | |
88 | } | |
89 | if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0) | |
90 | { | |
91 | if (num_got < 2) | |
92 | got_os[num_got] = os; | |
93 | ++num_got; | |
94 | } | |
95 | } | |
96 | ||
97 | keep_new = new_plt == 1 ? 0 : -1; | |
98 | if (num_plt == 2) | |
99 | { | |
100 | plt_os[0]->constraint = keep_new; | |
101 | plt_os[1]->constraint = ~keep_new; | |
102 | } | |
103 | if (num_got == 2) | |
104 | { | |
105 | if (old_got) | |
106 | keep_new = -1; | |
107 | got_os[0]->constraint = keep_new; | |
108 | got_os[1]->constraint = ~keep_new; | |
109 | } | |
110 | } | |
111 | ||
5c3261b0 | 112 | after_check_relocs_default (); |
0cf7d72c AM |
113 | } |
114 | ||
db434ba0 AM |
115 | EOF |
116 | fi | |
117 | fragment <<EOF | |
f9e6bfa8 | 118 | static void |
7e5d8d48 | 119 | ppc_before_allocation (void) |
f9e6bfa8 | 120 | { |
5503fea1 | 121 | if (is_ppc_elf (link_info.output_bfd)) |
f9e6bfa8 | 122 | { |
5446cbdf | 123 | if (ppc_elf_tls_setup (link_info.output_bfd, &link_info) |
a7f2871e | 124 | && !notlsopt) |
f9e6bfa8 | 125 | { |
f13a99db | 126 | if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info)) |
f9e6bfa8 | 127 | { |
d003af55 | 128 | einfo (_("%X%P: TLS problem %E\n")); |
f9e6bfa8 AM |
129 | return; |
130 | } | |
131 | } | |
132 | } | |
4135c73b | 133 | |
f9e6bfa8 | 134 | gld${EMULATION_NAME}_before_allocation (); |
4135c73b | 135 | |
93d1b056 AM |
136 | ppc_elf_maybe_strip_sdata_syms (&link_info); |
137 | ||
5446cbdf AM |
138 | if (RELAXATION_ENABLED) |
139 | params.branch_trampolines = 1; | |
140 | ||
4135c73b AM |
141 | /* Turn on relaxation if executable sections have addresses that |
142 | might make branches overflow. */ | |
5446cbdf | 143 | else if (!RELAXATION_DISABLED_BY_USER) |
4135c73b AM |
144 | { |
145 | bfd_vma low = (bfd_vma) -1; | |
146 | bfd_vma high = 0; | |
147 | asection *o; | |
148 | ||
149 | /* Run lang_size_sections (if not already done). */ | |
150 | if (expld.phase != lang_mark_phase_enum) | |
151 | { | |
152 | expld.phase = lang_mark_phase_enum; | |
58e6cc77 | 153 | expld.dataseg.phase = exp_seg_none; |
4135c73b AM |
154 | one_lang_size_sections_pass (NULL, FALSE); |
155 | lang_reset_memory_regions (); | |
156 | } | |
157 | ||
158 | for (o = link_info.output_bfd->sections; o != NULL; o = o->next) | |
159 | { | |
160 | if ((o->flags & (SEC_ALLOC | SEC_CODE)) != (SEC_ALLOC | SEC_CODE)) | |
161 | continue; | |
07088e95 | 162 | if (o->rawsize == 0) |
4135c73b AM |
163 | continue; |
164 | if (low > o->vma) | |
165 | low = o->vma; | |
07088e95 AM |
166 | if (high < o->vma + o->rawsize - 1) |
167 | high = o->vma + o->rawsize - 1; | |
4135c73b AM |
168 | } |
169 | if (high > low && high - low > (1 << 25) - 1) | |
5446cbdf | 170 | params.branch_trampolines = 1; |
4135c73b | 171 | } |
5446cbdf | 172 | |
d3e454b9 AM |
173 | if (params.branch_trampolines |
174 | || params.ppc476_workaround | |
175 | || params.pic_fixup > 0) | |
5446cbdf | 176 | ENABLE_RELAXATION; |
f9e6bfa8 AM |
177 | } |
178 | ||
b4ab4364 AM |
179 | /* Replaces default zero fill padding in executable sections with |
180 | "ba 0" instructions. This works around the ppc476 icache bug if we | |
181 | have a function pointer tail call near the end of a page, some | |
182 | small amount of padding, then the function called at the beginning | |
183 | of the next page. If the "ba 0" is ever executed we should hit a | |
184 | segv, so it's almost as good as an illegal instruction (zero). */ | |
185 | ||
186 | static void | |
187 | no_zero_padding (lang_statement_union_type *l) | |
188 | { | |
189 | if (l->header.type == lang_padding_statement_enum | |
190 | && l->padding_statement.size != 0 | |
191 | && l->padding_statement.output_section != NULL | |
192 | && (l->padding_statement.output_section->flags & SEC_CODE) != 0 | |
193 | && l->padding_statement.fill->size == 0) | |
194 | { | |
195 | struct _ppc_fill_type | |
196 | { | |
197 | size_t size; | |
198 | unsigned char data[4]; | |
199 | }; | |
200 | static struct _ppc_fill_type fill_be = { 4, {0x48, 0, 0, 2} }; | |
201 | static struct _ppc_fill_type fill_le = { 4, {2, 0, 0, 0x48} }; | |
202 | ||
203 | if (bfd_big_endian (link_info.output_bfd)) | |
204 | l->padding_statement.fill = (struct _fill_type *) &fill_be; | |
205 | else | |
206 | l->padding_statement.fill = (struct _fill_type *) &fill_le; | |
207 | } | |
208 | } | |
209 | ||
210 | static void | |
211 | ppc_finish (void) | |
212 | { | |
213 | if (params.ppc476_workaround) | |
214 | lang_for_each_statement (no_zero_padding); | |
215 | finish_default (); | |
216 | } | |
217 | ||
f9e6bfa8 AM |
218 | EOF |
219 | ||
dc27aea4 | 220 | if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then |
92b93329 | 221 | fragment <<EOF |
dc27aea4 AM |
222 | /* Special handling for embedded SPU executables. */ |
223 | extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *); | |
224 | static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *); | |
225 | ||
226 | static bfd_boolean | |
227 | ppc_recognized_file (lang_input_statement_type *entry) | |
228 | { | |
229 | if (embedded_spu_file (entry, "-m32")) | |
230 | return TRUE; | |
231 | ||
232 | return gld${EMULATION_NAME}_load_symbols (entry); | |
233 | } | |
234 | ||
235 | EOF | |
236 | LDEMUL_RECOGNIZED_FILE=ppc_recognized_file | |
237 | fi | |
238 | ||
f9e6bfa8 AM |
239 | # Define some shell vars to insert bits of code into the standard elf |
240 | # parse_args and list_options functions. | |
241 | # | |
58d180e8 | 242 | PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}' |
9e390558 AM |
243 | enum ppc32_opt |
244 | { | |
245 | OPTION_NO_TLS_OPT = 321, | |
246 | OPTION_NO_TLS_GET_ADDR_OPT, | |
247 | OPTION_NEW_PLT, | |
248 | OPTION_OLD_PLT, | |
249 | OPTION_PLT_ALIGN, | |
250 | OPTION_NO_PLT_ALIGN, | |
251 | OPTION_OLD_GOT, | |
252 | OPTION_STUBSYMS, | |
253 | OPTION_NO_STUBSYMS, | |
254 | OPTION_PPC476_WORKAROUND, | |
255 | OPTION_NO_PPC476_WORKAROUND, | |
256 | OPTION_NO_PICFIXUP, | |
257 | OPTION_VLE_RELOC_FIXUP | |
258 | }; | |
f9e6bfa8 AM |
259 | ' |
260 | ||
58d180e8 | 261 | PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' |
0ba07910 | 262 | { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS }, |
b02c4cfa | 263 | { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS }, |
f9e6bfa8 | 264 | { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT }, |
db434ba0 AM |
265 | { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },' |
266 | if test -z "$VXWORKS_BASE_EM_FILE" ; then | |
267 | PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' | |
016687f8 | 268 | { "secure-plt", no_argument, NULL, OPTION_NEW_PLT }, |
0cf7d72c | 269 | { "bss-plt", no_argument, NULL, OPTION_OLD_PLT }, |
691d2e9a | 270 | { "plt-align", optional_argument, NULL, OPTION_PLT_ALIGN }, |
9e390558 | 271 | { "no-plt-align", no_argument, NULL, OPTION_NO_PLT_ALIGN }, |
db434ba0 AM |
272 | { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },' |
273 | fi | |
274 | PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' | |
5446cbdf AM |
275 | { "ppc476-workaround", optional_argument, NULL, OPTION_PPC476_WORKAROUND }, |
276 | { "no-ppc476-workaround", no_argument, NULL, OPTION_NO_PPC476_WORKAROUND }, | |
d3e454b9 | 277 | { "no-pic-fixup", no_argument, NULL, OPTION_NO_PICFIXUP }, |
08dc996f | 278 | { "vle-reloc-fixup", no_argument, NULL, OPTION_VLE_RELOC_FIXUP }, |
f9e6bfa8 AM |
279 | ' |
280 | ||
58d180e8 | 281 | PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}' |
f9e6bfa8 | 282 | fprintf (file, _("\ |
df5f2391 | 283 | --emit-stub-syms Label linker stubs with a symbol\n" |
9e390558 AM |
284 | )); |
285 | fprintf (file, _("\ | |
df5f2391 | 286 | --no-emit-stub-syms Don'\''t label linker stubs with a symbol\n" |
9e390558 AM |
287 | )); |
288 | fprintf (file, _("\ | |
df5f2391 | 289 | --no-tls-optimize Don'\''t try to optimize TLS accesses\n" |
9e390558 AM |
290 | )); |
291 | fprintf (file, _("\ | |
df5f2391 | 292 | --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call\n" |
9e390558 | 293 | ));' |
db434ba0 AM |
294 | if test -z "$VXWORKS_BASE_EM_FILE" ; then |
295 | PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'\ | |
9e390558 | 296 | fprintf (file, _("\ |
df5f2391 | 297 | --secure-plt Use new-style PLT if possible\n" |
9e390558 AM |
298 | )); |
299 | fprintf (file, _("\ | |
df5f2391 | 300 | --bss-plt Force old-style BSS PLT\n" |
9e390558 AM |
301 | )); |
302 | fprintf (file, _("\ | |
df5f2391 | 303 | --plt-align Align PLT call stubs to fit cache lines\n" |
9e390558 AM |
304 | )); |
305 | fprintf (file, _("\ | |
df5f2391 | 306 | --no-plt-align Dont'\''t align individual PLT call stubs\n" |
9e390558 AM |
307 | )); |
308 | fprintf (file, _("\ | |
df5f2391 | 309 | --sdata-got Force GOT location just before .sdata\n" |
9e390558 | 310 | ));' |
db434ba0 AM |
311 | fi |
312 | PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'\ | |
9e390558 | 313 | fprintf (file, _("\ |
5446cbdf | 314 | --ppc476-workaround [=pagesize]\n\ |
df5f2391 | 315 | Avoid a cache bug on ppc476\n" |
9e390558 AM |
316 | )); |
317 | fprintf (file, _("\ | |
df5f2391 | 318 | --no-ppc476-workaround Disable workaround\n" |
9e390558 AM |
319 | )); |
320 | fprintf (file, _("\ | |
df5f2391 | 321 | --no-pic-fixup Don'\''t edit non-pic to pic\n" |
9e390558 AM |
322 | )); |
323 | fprintf (file, _("\ | |
df5f2391 | 324 | --vle-reloc-fixup Correct old object file 16A/16D relocation\n" |
f9e6bfa8 AM |
325 | )); |
326 | ' | |
327 | ||
58d180e8 | 328 | PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' |
0ba07910 | 329 | case OPTION_STUBSYMS: |
5446cbdf | 330 | params.emit_stub_syms = 1; |
0ba07910 AM |
331 | break; |
332 | ||
b02c4cfa | 333 | case OPTION_NO_STUBSYMS: |
5446cbdf | 334 | params.emit_stub_syms = 0; |
b02c4cfa AM |
335 | break; |
336 | ||
f9e6bfa8 AM |
337 | case OPTION_NO_TLS_OPT: |
338 | notlsopt = 1; | |
339 | break; | |
0cf7d72c | 340 | |
a7f2871e | 341 | case OPTION_NO_TLS_GET_ADDR_OPT: |
5446cbdf | 342 | params.no_tls_get_addr_opt = 1; |
a7f2871e AM |
343 | break; |
344 | ||
016687f8 | 345 | case OPTION_NEW_PLT: |
5446cbdf | 346 | params.plt_style = PLT_NEW; |
016687f8 AM |
347 | break; |
348 | ||
0cf7d72c | 349 | case OPTION_OLD_PLT: |
5446cbdf | 350 | params.plt_style = PLT_OLD; |
0cf7d72c AM |
351 | break; |
352 | ||
9e390558 | 353 | case OPTION_PLT_ALIGN: |
691d2e9a AM |
354 | if (optarg != NULL) |
355 | { | |
356 | char *end; | |
357 | unsigned long val = strtoul (optarg, &end, 0); | |
358 | if (*end || val > 5) | |
df5f2391 | 359 | einfo (_("%F%P: invalid --plt-align `%s'\''\n"), optarg); |
691d2e9a AM |
360 | params.plt_stub_align = val; |
361 | } | |
362 | else | |
363 | params.plt_stub_align = 5; | |
9e390558 AM |
364 | break; |
365 | ||
366 | case OPTION_NO_PLT_ALIGN: | |
367 | params.plt_stub_align = 0; | |
368 | break; | |
369 | ||
0cf7d72c AM |
370 | case OPTION_OLD_GOT: |
371 | old_got = 1; | |
372 | break; | |
f05eb3b7 AM |
373 | |
374 | case OPTION_TRADITIONAL_FORMAT: | |
375 | notlsopt = 1; | |
5446cbdf | 376 | params.no_tls_get_addr_opt = 1; |
f05eb3b7 | 377 | return FALSE; |
5446cbdf AM |
378 | |
379 | case OPTION_PPC476_WORKAROUND: | |
380 | params.ppc476_workaround = 1; | |
381 | if (optarg != NULL) | |
382 | { | |
383 | char *end; | |
76e7a751 | 384 | params.pagesize = strtoul (optarg, &end, 0); |
5446cbdf | 385 | if (*end |
76e7a751 AM |
386 | || (params.pagesize < 4096 && params.pagesize != 0) |
387 | || params.pagesize != (params.pagesize & -params.pagesize)) | |
df5f2391 | 388 | einfo (_("%F%P: invalid pagesize `%s'\''\n"), optarg); |
5446cbdf AM |
389 | } |
390 | break; | |
391 | ||
392 | case OPTION_NO_PPC476_WORKAROUND: | |
393 | params.ppc476_workaround = 0; | |
394 | break; | |
d3e454b9 AM |
395 | |
396 | case OPTION_NO_PICFIXUP: | |
397 | params.pic_fixup = -1; | |
398 | break; | |
08dc996f AM |
399 | |
400 | case OPTION_VLE_RELOC_FIXUP: | |
401 | params.vle_reloc_fixup = 1; | |
402 | break; | |
f9e6bfa8 AM |
403 | ' |
404 | ||
c9a2f333 | 405 | # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation |
f9e6bfa8 | 406 | # |
5446cbdf | 407 | LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_after_open_output |
db434ba0 | 408 | if test -z "$VXWORKS_BASE_EM_FILE" ; then |
5c3261b0 | 409 | LDEMUL_AFTER_CHECK_RELOCS=ppc_after_check_relocs |
db434ba0 | 410 | fi |
f9e6bfa8 | 411 | LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation |
b4ab4364 | 412 | LDEMUL_FINISH=ppc_finish |