1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2003-2016 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
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.
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
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 # This file is sourced from elf32.em, and defines extra powerpc32-elf
27 #include "elf32-ppc.h"
31 #define is_ppc_elf(bfd) \
32 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
33 && elf_object_id (bfd) == PPC32_ELF_DATA)
35 /* Whether to run tls optimization. */
36 static int notlsopt = 0;
38 /* Choose the correct place for .got. */
39 static int old_got = 0;
41 static struct ppc_elf_params params = { PLT_UNSET, -1, 0, 0, 0, 0, 0, 0, 0 };
44 ppc_after_open_output (void)
46 if (params.emit_stub_syms < 0)
47 params.emit_stub_syms = (link_info.emitrelocations
48 || bfd_link_pic (&link_info));
49 if (params.pagesize == 0)
50 params.pagesize = config.commonpagesize;
51 ppc_elf_link_params (&link_info, ¶ms);
56 # No --secure-plt, --bss-plt, or --sdata-got for vxworks.
57 if test -z "$VXWORKS_BASE_EM_FILE" ; then
62 if (is_ppc_elf (link_info.output_bfd))
68 lang_output_section_statement_type *os;
69 lang_output_section_statement_type *plt_os[2];
70 lang_output_section_statement_type *got_os[2];
72 new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info);
74 einfo ("%X%P: select_plt_layout problem %E\n");
78 for (os = &lang_output_section_statement.head->output_section_statement;
82 if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
88 if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
96 keep_new = new_plt == 1 ? 0 : -1;
99 plt_os[0]->constraint = keep_new;
100 plt_os[1]->constraint = ~keep_new;
106 got_os[0]->constraint = keep_new;
107 got_os[1]->constraint = ~keep_new;
111 gld${EMULATION_NAME}_after_open ();
118 ppc_before_allocation (void)
120 if (is_ppc_elf (link_info.output_bfd))
122 if (ppc_elf_tls_setup (link_info.output_bfd, &link_info)
125 if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info))
127 einfo ("%X%P: TLS problem %E\n");
133 gld${EMULATION_NAME}_before_allocation ();
135 ppc_elf_maybe_strip_sdata_syms (&link_info);
137 if (RELAXATION_ENABLED)
138 params.branch_trampolines = 1;
140 /* Turn on relaxation if executable sections have addresses that
141 might make branches overflow. */
142 else if (!RELAXATION_DISABLED_BY_USER)
144 bfd_vma low = (bfd_vma) -1;
148 /* Run lang_size_sections (if not already done). */
149 if (expld.phase != lang_mark_phase_enum)
151 expld.phase = lang_mark_phase_enum;
152 expld.dataseg.phase = exp_dataseg_none;
153 one_lang_size_sections_pass (NULL, FALSE);
154 lang_reset_memory_regions ();
157 for (o = link_info.output_bfd->sections; o != NULL; o = o->next)
159 if ((o->flags & (SEC_ALLOC | SEC_CODE)) != (SEC_ALLOC | SEC_CODE))
165 if (high < o->vma + o->rawsize - 1)
166 high = o->vma + o->rawsize - 1;
168 if (high > low && high - low > (1 << 25) - 1)
169 params.branch_trampolines = 1;
172 if (params.branch_trampolines
173 || params.ppc476_workaround
174 || params.pic_fixup > 0)
178 /* Replaces default zero fill padding in executable sections with
179 "ba 0" instructions. This works around the ppc476 icache bug if we
180 have a function pointer tail call near the end of a page, some
181 small amount of padding, then the function called at the beginning
182 of the next page. If the "ba 0" is ever executed we should hit a
183 segv, so it's almost as good as an illegal instruction (zero). */
186 no_zero_padding (lang_statement_union_type *l)
188 if (l->header.type == lang_padding_statement_enum
189 && l->padding_statement.size != 0
190 && l->padding_statement.output_section != NULL
191 && (l->padding_statement.output_section->flags & SEC_CODE) != 0
192 && l->padding_statement.fill->size == 0)
194 struct _ppc_fill_type
197 unsigned char data[4];
199 static struct _ppc_fill_type fill_be = { 4, {0x48, 0, 0, 2} };
200 static struct _ppc_fill_type fill_le = { 4, {2, 0, 0, 0x48} };
202 if (bfd_big_endian (link_info.output_bfd))
203 l->padding_statement.fill = (struct _fill_type *) &fill_be;
205 l->padding_statement.fill = (struct _fill_type *) &fill_le;
212 if (params.ppc476_workaround)
213 lang_for_each_statement (no_zero_padding);
219 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
221 /* Special handling for embedded SPU executables. */
222 extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
223 static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
226 ppc_recognized_file (lang_input_statement_type *entry)
228 if (embedded_spu_file (entry, "-m32"))
231 return gld${EMULATION_NAME}_load_symbols (entry);
235 LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
238 # Define some shell vars to insert bits of code into the standard elf
239 # parse_args and list_options functions.
241 PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
242 #define OPTION_NO_TLS_OPT 321
243 #define OPTION_NO_TLS_GET_ADDR_OPT (OPTION_NO_TLS_OPT + 1)
244 #define OPTION_NEW_PLT (OPTION_NO_TLS_GET_ADDR_OPT + 1)
245 #define OPTION_OLD_PLT (OPTION_NEW_PLT + 1)
246 #define OPTION_OLD_GOT (OPTION_OLD_PLT + 1)
247 #define OPTION_STUBSYMS (OPTION_OLD_GOT + 1)
248 #define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1)
249 #define OPTION_PPC476_WORKAROUND (OPTION_NO_STUBSYMS + 1)
250 #define OPTION_NO_PPC476_WORKAROUND (OPTION_PPC476_WORKAROUND + 1)
251 #define OPTION_NO_PICFIXUP (OPTION_NO_PPC476_WORKAROUND + 1)
252 #define OPTION_VLE_RELOC_FIXUP (OPTION_NO_PICFIXUP + 1)
255 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
256 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
257 { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
258 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
259 { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },'
260 if test -z "$VXWORKS_BASE_EM_FILE" ; then
261 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
262 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
263 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
264 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },'
266 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
267 { "ppc476-workaround", optional_argument, NULL, OPTION_PPC476_WORKAROUND },
268 { "no-ppc476-workaround", no_argument, NULL, OPTION_NO_PPC476_WORKAROUND },
269 { "no-pic-fixup", no_argument, NULL, OPTION_NO_PICFIXUP },
270 { "vle-reloc-fixup", no_argument, NULL, OPTION_VLE_RELOC_FIXUP },
273 PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
275 --emit-stub-syms Label linker stubs with a symbol.\n\
276 --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\
277 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
278 --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n'
279 if test -z "$VXWORKS_BASE_EM_FILE" ; then
280 PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'\
281 --secure-plt Use new-style PLT if possible.\n\
282 --bss-plt Force old-style BSS PLT.\n\
283 --sdata-got Force GOT location just before .sdata.\n'
285 PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'\
286 --ppc476-workaround [=pagesize]\n\
287 Avoid a cache bug on ppc476.\n\
288 --no-ppc476-workaround Disable workaround.\n\
289 --no-pic-fixup Don'\''t edit non-pic to pic.\n\
290 --vle-reloc-fixup Correct old object file 16A/16D relocation.\n"
294 PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
295 case OPTION_STUBSYMS:
296 params.emit_stub_syms = 1;
299 case OPTION_NO_STUBSYMS:
300 params.emit_stub_syms = 0;
303 case OPTION_NO_TLS_OPT:
307 case OPTION_NO_TLS_GET_ADDR_OPT:
308 params.no_tls_get_addr_opt = 1;
312 params.plt_style = PLT_NEW;
316 params.plt_style = PLT_OLD;
323 case OPTION_TRADITIONAL_FORMAT:
325 params.no_tls_get_addr_opt = 1;
328 case OPTION_PPC476_WORKAROUND:
329 params.ppc476_workaround = 1;
333 params.pagesize = strtoul (optarg, &end, 0);
335 || (params.pagesize < 4096 && params.pagesize != 0)
336 || params.pagesize != (params.pagesize & -params.pagesize))
337 einfo (_("%P%F: invalid pagesize `%s'\''\n"), optarg);
341 case OPTION_NO_PPC476_WORKAROUND:
342 params.ppc476_workaround = 0;
345 case OPTION_NO_PICFIXUP:
346 params.pic_fixup = -1;
349 case OPTION_VLE_RELOC_FIXUP:
350 params.vle_reloc_fixup = 1;
354 # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
356 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_after_open_output
357 if test -z "$VXWORKS_BASE_EM_FILE" ; then
358 LDEMUL_AFTER_OPEN=ppc_after_open
360 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
361 LDEMUL_FINISH=ppc_finish