]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/emultempl/ppc32elf.em
ppc476 icache bug workaround
[thirdparty/binutils-gdb.git] / ld / emultempl / ppc32elf.em
1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2003, 2005, 2007, 2008, 2009, 2010, 2011, 2012
3 # Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU Binutils.
6 #
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.
11 #
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.
16 #
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,
20 # MA 02110-1301, USA.
21 #
22
23 # This file is sourced from elf32.em, and defines extra powerpc32-elf
24 # specific routines.
25 #
26 fragment <<EOF
27
28 #include "libbfd.h"
29 #include "elf32-ppc.h"
30 #include "ldlex.h"
31
32 #define is_ppc_elf(bfd) \
33 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
34 && elf_object_id (bfd) == PPC32_ELF_DATA)
35
36 /* Whether to run tls optimization. */
37 static int notlsopt = 0;
38
39 /* Choose the correct place for .got. */
40 static int old_got = 0;
41
42 static struct ppc_elf_params params = { PLT_UNSET, -1, 0, 0, 0, 0 };
43
44 static void
45 ppc_after_open_output (void)
46 {
47 if (params.emit_stub_syms < 0)
48 params.emit_stub_syms = link_info.emitrelocations || link_info.shared;
49 if (params.pagesize == 0)
50 params.pagesize = config.commonpagesize;
51 if (link_info.relocatable)
52 params.ppc476_workaround = 0;
53 ppc_elf_link_params (&link_info, &params);
54 }
55
56 static void
57 ppc_after_open (void)
58 {
59 if (is_ppc_elf (link_info.output_bfd))
60 {
61 int new_plt;
62 int keep_new;
63 unsigned int num_plt;
64 unsigned int num_got;
65 lang_output_section_statement_type *os;
66 lang_output_section_statement_type *plt_os[2];
67 lang_output_section_statement_type *got_os[2];
68
69 new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info);
70 if (new_plt < 0)
71 einfo ("%X%P: select_plt_layout problem %E\n");
72
73 num_got = 0;
74 num_plt = 0;
75 for (os = &lang_output_section_statement.head->output_section_statement;
76 os != NULL;
77 os = os->next)
78 {
79 if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
80 {
81 if (num_plt < 2)
82 plt_os[num_plt] = os;
83 ++num_plt;
84 }
85 if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
86 {
87 if (num_got < 2)
88 got_os[num_got] = os;
89 ++num_got;
90 }
91 }
92
93 keep_new = new_plt == 1 ? 0 : -1;
94 if (num_plt == 2)
95 {
96 plt_os[0]->constraint = keep_new;
97 plt_os[1]->constraint = ~keep_new;
98 }
99 if (num_got == 2)
100 {
101 if (old_got)
102 keep_new = -1;
103 got_os[0]->constraint = keep_new;
104 got_os[1]->constraint = ~keep_new;
105 }
106 }
107
108 gld${EMULATION_NAME}_after_open ();
109 }
110
111 static void
112 ppc_before_allocation (void)
113 {
114 if (is_ppc_elf (link_info.output_bfd))
115 {
116 if (ppc_elf_tls_setup (link_info.output_bfd, &link_info)
117 && !notlsopt)
118 {
119 if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info))
120 {
121 einfo ("%X%P: TLS problem %E\n");
122 return;
123 }
124 }
125 }
126
127 gld${EMULATION_NAME}_before_allocation ();
128
129 if (RELAXATION_ENABLED)
130 params.branch_trampolines = 1;
131
132 /* Turn on relaxation if executable sections have addresses that
133 might make branches overflow. */
134 else if (!RELAXATION_DISABLED_BY_USER)
135 {
136 bfd_vma low = (bfd_vma) -1;
137 bfd_vma high = 0;
138 asection *o;
139
140 /* Run lang_size_sections (if not already done). */
141 if (expld.phase != lang_mark_phase_enum)
142 {
143 expld.phase = lang_mark_phase_enum;
144 expld.dataseg.phase = exp_dataseg_none;
145 one_lang_size_sections_pass (NULL, FALSE);
146 lang_reset_memory_regions ();
147 }
148
149 for (o = link_info.output_bfd->sections; o != NULL; o = o->next)
150 {
151 if ((o->flags & (SEC_ALLOC | SEC_CODE)) != (SEC_ALLOC | SEC_CODE))
152 continue;
153 if (o->rawsize == 0)
154 continue;
155 if (low > o->vma)
156 low = o->vma;
157 if (high < o->vma + o->rawsize - 1)
158 high = o->vma + o->rawsize - 1;
159 }
160 if (high > low && high - low > (1 << 25) - 1)
161 params.branch_trampolines = 1;
162 }
163
164 if (params.ppc476_workaround || params.branch_trampolines)
165 ENABLE_RELAXATION;
166 }
167
168 EOF
169
170 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
171 fragment <<EOF
172 /* Special handling for embedded SPU executables. */
173 extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
174 static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
175
176 static bfd_boolean
177 ppc_recognized_file (lang_input_statement_type *entry)
178 {
179 if (embedded_spu_file (entry, "-m32"))
180 return TRUE;
181
182 return gld${EMULATION_NAME}_load_symbols (entry);
183 }
184
185 EOF
186 LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
187 fi
188
189 # Define some shell vars to insert bits of code into the standard elf
190 # parse_args and list_options functions.
191 #
192 PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
193 #define OPTION_NO_TLS_OPT 321
194 #define OPTION_NO_TLS_GET_ADDR_OPT (OPTION_NO_TLS_OPT + 1)
195 #define OPTION_NEW_PLT (OPTION_NO_TLS_GET_ADDR_OPT + 1)
196 #define OPTION_OLD_PLT (OPTION_NEW_PLT + 1)
197 #define OPTION_OLD_GOT (OPTION_OLD_PLT + 1)
198 #define OPTION_STUBSYMS (OPTION_OLD_GOT + 1)
199 #define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1)
200 #define OPTION_PPC476_WORKAROUND (OPTION_NO_STUBSYMS + 1)
201 #define OPTION_NO_PPC476_WORKAROUND (OPTION_PPC476_WORKAROUND + 1)
202 '
203
204 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
205 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
206 { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
207 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
208 { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },
209 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
210 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
211 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
212 { "ppc476-workaround", optional_argument, NULL, OPTION_PPC476_WORKAROUND },
213 { "no-ppc476-workaround", no_argument, NULL, OPTION_NO_PPC476_WORKAROUND },
214 '
215
216 PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
217 fprintf (file, _("\
218 --emit-stub-syms Label linker stubs with a symbol.\n\
219 --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\
220 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
221 --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n\
222 --secure-plt Use new-style PLT if possible.\n\
223 --bss-plt Force old-style BSS PLT.\n\
224 --sdata-got Force GOT location just before .sdata.\n\
225 --ppc476-workaround [=pagesize]\n\
226 Avoid a cache bug on ppc476.\n\
227 --no-ppc476-workaround Disable workaround.\n"
228 ));
229 '
230
231 PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
232 case OPTION_STUBSYMS:
233 params.emit_stub_syms = 1;
234 break;
235
236 case OPTION_NO_STUBSYMS:
237 params.emit_stub_syms = 0;
238 break;
239
240 case OPTION_NO_TLS_OPT:
241 notlsopt = 1;
242 break;
243
244 case OPTION_NO_TLS_GET_ADDR_OPT:
245 params.no_tls_get_addr_opt = 1;
246 break;
247
248 case OPTION_NEW_PLT:
249 params.plt_style = PLT_NEW;
250 break;
251
252 case OPTION_OLD_PLT:
253 params.plt_style = PLT_OLD;
254 break;
255
256 case OPTION_OLD_GOT:
257 old_got = 1;
258 break;
259
260 case OPTION_TRADITIONAL_FORMAT:
261 notlsopt = 1;
262 params.no_tls_get_addr_opt = 1;
263 return FALSE;
264
265 case OPTION_PPC476_WORKAROUND:
266 params.ppc476_workaround = 1;
267 if (optarg != NULL)
268 {
269 char *end;
270 params.pagesize = strtoul (optarg, &end, 0);
271 if (*end
272 || (params.pagesize < 4096 && params.pagesize != 0)
273 || params.pagesize != (params.pagesize & -params.pagesize))
274 einfo (_("%P%F: invalid pagesize `%s'\''\n"), optarg);
275 }
276 break;
277
278 case OPTION_NO_PPC476_WORKAROUND:
279 params.ppc476_workaround = 0;
280 break;
281 '
282
283 # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
284 #
285 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_after_open_output
286 LDEMUL_AFTER_OPEN=ppc_after_open
287 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation