1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2003, 2005, 2007, 2008, 2009, 2010, 2011, 2012
3 # Free Software Foundation, Inc.
5 # This file is part of the GNU Binutils.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 # This file is sourced from elf32.em, and defines extra powerpc32-elf
29 #include "elf32-ppc.h"
32 #define is_ppc_elf(bfd) \
33 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
34 && elf_object_id (bfd) == PPC32_ELF_DATA)
36 /* Whether to run tls optimization. */
37 static int notlsopt = 0;
39 /* Choose the correct place for .got. */
40 static int old_got = 0;
42 static bfd_vma pagesize = 0;
44 static struct ppc_elf_params params = { PLT_UNSET, -1, 0, 0, 0, 0 };
47 ppc_after_open_output (void)
49 if (params.emit_stub_syms < 0)
50 params.emit_stub_syms = link_info.emitrelocations || link_info.shared;
52 pagesize = config.commonpagesize;
53 params.pagesize_p2 = bfd_log2 (pagesize);
54 ppc_elf_link_params (&link_info, ¶ms);
60 if (is_ppc_elf (link_info.output_bfd))
66 lang_output_section_statement_type *os;
67 lang_output_section_statement_type *plt_os[2];
68 lang_output_section_statement_type *got_os[2];
70 new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info);
72 einfo ("%X%P: select_plt_layout problem %E\n");
76 for (os = &lang_output_section_statement.head->output_section_statement;
80 if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
86 if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
94 keep_new = new_plt == 1 ? 0 : -1;
97 plt_os[0]->constraint = keep_new;
98 plt_os[1]->constraint = ~keep_new;
104 got_os[0]->constraint = keep_new;
105 got_os[1]->constraint = ~keep_new;
109 gld${EMULATION_NAME}_after_open ();
113 ppc_before_allocation (void)
115 if (is_ppc_elf (link_info.output_bfd))
117 if (ppc_elf_tls_setup (link_info.output_bfd, &link_info)
120 if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info))
122 einfo ("%X%P: TLS problem %E\n");
128 gld${EMULATION_NAME}_before_allocation ();
130 if (RELAXATION_ENABLED)
131 params.branch_trampolines = 1;
133 /* Turn on relaxation if executable sections have addresses that
134 might make branches overflow. */
135 else if (!RELAXATION_DISABLED_BY_USER)
137 bfd_vma low = (bfd_vma) -1;
141 /* Run lang_size_sections (if not already done). */
142 if (expld.phase != lang_mark_phase_enum)
144 expld.phase = lang_mark_phase_enum;
145 expld.dataseg.phase = exp_dataseg_none;
146 one_lang_size_sections_pass (NULL, FALSE);
147 lang_reset_memory_regions ();
150 for (o = link_info.output_bfd->sections; o != NULL; o = o->next)
152 if ((o->flags & (SEC_ALLOC | SEC_CODE)) != (SEC_ALLOC | SEC_CODE))
158 if (high < o->vma + o->rawsize - 1)
159 high = o->vma + o->rawsize - 1;
161 if (high > low && high - low > (1 << 25) - 1)
162 params.branch_trampolines = 1;
165 if (params.ppc476_workaround || params.branch_trampolines)
171 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
173 /* Special handling for embedded SPU executables. */
174 extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
175 static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
178 ppc_recognized_file (lang_input_statement_type *entry)
180 if (embedded_spu_file (entry, "-m32"))
183 return gld${EMULATION_NAME}_load_symbols (entry);
187 LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
190 # Define some shell vars to insert bits of code into the standard elf
191 # parse_args and list_options functions.
193 PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
194 #define OPTION_NO_TLS_OPT 321
195 #define OPTION_NO_TLS_GET_ADDR_OPT (OPTION_NO_TLS_OPT + 1)
196 #define OPTION_NEW_PLT (OPTION_NO_TLS_GET_ADDR_OPT + 1)
197 #define OPTION_OLD_PLT (OPTION_NEW_PLT + 1)
198 #define OPTION_OLD_GOT (OPTION_OLD_PLT + 1)
199 #define OPTION_STUBSYMS (OPTION_OLD_GOT + 1)
200 #define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1)
201 #define OPTION_PPC476_WORKAROUND (OPTION_NO_STUBSYMS + 1)
202 #define OPTION_NO_PPC476_WORKAROUND (OPTION_PPC476_WORKAROUND + 1)
205 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
206 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
207 { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
208 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
209 { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },
210 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
211 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
212 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
213 { "ppc476-workaround", optional_argument, NULL, OPTION_PPC476_WORKAROUND },
214 { "no-ppc476-workaround", no_argument, NULL, OPTION_NO_PPC476_WORKAROUND },
217 PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
219 --emit-stub-syms Label linker stubs with a symbol.\n\
220 --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\
221 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
222 --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n\
223 --secure-plt Use new-style PLT if possible.\n\
224 --bss-plt Force old-style BSS PLT.\n\
225 --sdata-got Force GOT location just before .sdata.\n\
226 --ppc476-workaround [=pagesize]\n\
227 Avoid a cache bug on ppc476.\n\
228 --no-ppc476-workaround Disable workaround.\n"
232 PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
233 case OPTION_STUBSYMS:
234 params.emit_stub_syms = 1;
237 case OPTION_NO_STUBSYMS:
238 params.emit_stub_syms = 0;
241 case OPTION_NO_TLS_OPT:
245 case OPTION_NO_TLS_GET_ADDR_OPT:
246 params.no_tls_get_addr_opt = 1;
250 params.plt_style = PLT_NEW;
254 params.plt_style = PLT_OLD;
261 case OPTION_TRADITIONAL_FORMAT:
263 params.no_tls_get_addr_opt = 1;
266 case OPTION_PPC476_WORKAROUND:
267 params.ppc476_workaround = 1;
271 pagesize = strtoul (optarg, &end, 0);
273 || (pagesize < 4096 && pagesize != 0)
274 || pagesize != (pagesize & -pagesize))
275 einfo (_("%P%F: invalid pagesize `%s'\''\n"), optarg);
279 case OPTION_NO_PPC476_WORKAROUND:
280 params.ppc476_workaround = 0;
284 # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
286 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_after_open_output
287 LDEMUL_AFTER_OPEN=ppc_after_open
288 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation