ppc476 icache bug workaround
[deliverable/binutils-gdb.git] / ld / emultempl / ppc32elf.em
CommitLineData
f9e6bfa8 1# This shell script emits a C file. -*- C -*-
f05eb3b7 2# Copyright 2003, 2005, 2007, 2008, 2009, 2010, 2011, 2012
58d180e8 3# Free Software Foundation, Inc.
f9e6bfa8 4#
f96b4a7b 5# This file is part of the GNU Binutils.
f9e6bfa8
AM
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
f96b4a7b 9# the Free Software Foundation; either version 3 of the License, or
f9e6bfa8
AM
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
f96b4a7b
NC
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
f9e6bfa8
AM
21#
22
c9a2f333 23# This file is sourced from elf32.em, and defines extra powerpc32-elf
f9e6bfa8
AM
24# specific routines.
25#
92b93329 26fragment <<EOF
f9e6bfa8
AM
27
28#include "libbfd.h"
29#include "elf32-ppc.h"
f05eb3b7 30#include "ldlex.h"
f9e6bfa8 31
5503fea1
AM
32#define is_ppc_elf(bfd) \
33 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
4dfe6ac6 34 && elf_object_id (bfd) == PPC32_ELF_DATA)
c9a2f333 35
f9e6bfa8
AM
36/* Whether to run tls optimization. */
37static int notlsopt = 0;
38
5446cbdf 39/* Choose the correct place for .got. */
0cf7d72c
AM
40static int old_got = 0;
41
5446cbdf
AM
42static struct ppc_elf_params params = { PLT_UNSET, -1, 0, 0, 0, 0 };
43
44static void
45ppc_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
0cf7d72c
AM
56static void
57ppc_after_open (void)
58{
5503fea1 59 if (is_ppc_elf (link_info.output_bfd))
0cf7d72c
AM
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
5446cbdf 69 new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info);
0cf7d72c
AM
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
f9e6bfa8 111static void
7e5d8d48 112ppc_before_allocation (void)
f9e6bfa8 113{
5503fea1 114 if (is_ppc_elf (link_info.output_bfd))
f9e6bfa8 115 {
5446cbdf 116 if (ppc_elf_tls_setup (link_info.output_bfd, &link_info)
a7f2871e 117 && !notlsopt)
f9e6bfa8 118 {
f13a99db 119 if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info))
f9e6bfa8
AM
120 {
121 einfo ("%X%P: TLS problem %E\n");
122 return;
123 }
124 }
125 }
4135c73b 126
f9e6bfa8 127 gld${EMULATION_NAME}_before_allocation ();
4135c73b 128
5446cbdf
AM
129 if (RELAXATION_ENABLED)
130 params.branch_trampolines = 1;
131
4135c73b
AM
132 /* Turn on relaxation if executable sections have addresses that
133 might make branches overflow. */
5446cbdf 134 else if (!RELAXATION_DISABLED_BY_USER)
4135c73b
AM
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;
07088e95 153 if (o->rawsize == 0)
4135c73b
AM
154 continue;
155 if (low > o->vma)
156 low = o->vma;
07088e95
AM
157 if (high < o->vma + o->rawsize - 1)
158 high = o->vma + o->rawsize - 1;
4135c73b
AM
159 }
160 if (high > low && high - low > (1 << 25) - 1)
5446cbdf 161 params.branch_trampolines = 1;
4135c73b 162 }
5446cbdf
AM
163
164 if (params.ppc476_workaround || params.branch_trampolines)
165 ENABLE_RELAXATION;
f9e6bfa8
AM
166}
167
168EOF
169
dc27aea4 170if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
92b93329 171 fragment <<EOF
dc27aea4
AM
172/* Special handling for embedded SPU executables. */
173extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
174static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
175
176static bfd_boolean
177ppc_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
185EOF
186LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
187fi
188
f9e6bfa8
AM
189# Define some shell vars to insert bits of code into the standard elf
190# parse_args and list_options functions.
191#
58d180e8
AM
192PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
193#define OPTION_NO_TLS_OPT 321
a7f2871e
AM
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)
b02c4cfa 199#define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1)
5446cbdf
AM
200#define OPTION_PPC476_WORKAROUND (OPTION_NO_STUBSYMS + 1)
201#define OPTION_NO_PPC476_WORKAROUND (OPTION_PPC476_WORKAROUND + 1)
f9e6bfa8
AM
202'
203
58d180e8 204PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
0ba07910 205 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
b02c4cfa 206 { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
f9e6bfa8 207 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
a7f2871e 208 { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },
016687f8 209 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
0cf7d72c
AM
210 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
211 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
5446cbdf
AM
212 { "ppc476-workaround", optional_argument, NULL, OPTION_PPC476_WORKAROUND },
213 { "no-ppc476-workaround", no_argument, NULL, OPTION_NO_PPC476_WORKAROUND },
f9e6bfa8
AM
214'
215
58d180e8 216PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
f9e6bfa8 217 fprintf (file, _("\
442996ee 218 --emit-stub-syms Label linker stubs with a symbol.\n\
b02c4cfa 219 --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\
442996ee 220 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
a7f2871e 221 --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n\
442996ee
AM
222 --secure-plt Use new-style PLT if possible.\n\
223 --bss-plt Force old-style BSS PLT.\n\
5446cbdf
AM
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"
f9e6bfa8
AM
228 ));
229'
230
58d180e8 231PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
0ba07910 232 case OPTION_STUBSYMS:
5446cbdf 233 params.emit_stub_syms = 1;
0ba07910
AM
234 break;
235
b02c4cfa 236 case OPTION_NO_STUBSYMS:
5446cbdf 237 params.emit_stub_syms = 0;
b02c4cfa
AM
238 break;
239
f9e6bfa8
AM
240 case OPTION_NO_TLS_OPT:
241 notlsopt = 1;
242 break;
0cf7d72c 243
a7f2871e 244 case OPTION_NO_TLS_GET_ADDR_OPT:
5446cbdf 245 params.no_tls_get_addr_opt = 1;
a7f2871e
AM
246 break;
247
016687f8 248 case OPTION_NEW_PLT:
5446cbdf 249 params.plt_style = PLT_NEW;
016687f8
AM
250 break;
251
0cf7d72c 252 case OPTION_OLD_PLT:
5446cbdf 253 params.plt_style = PLT_OLD;
0cf7d72c
AM
254 break;
255
256 case OPTION_OLD_GOT:
257 old_got = 1;
258 break;
f05eb3b7
AM
259
260 case OPTION_TRADITIONAL_FORMAT:
261 notlsopt = 1;
5446cbdf 262 params.no_tls_get_addr_opt = 1;
f05eb3b7 263 return FALSE;
5446cbdf
AM
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;
f9e6bfa8
AM
281'
282
c9a2f333 283# Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
f9e6bfa8 284#
5446cbdf 285LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_after_open_output
0cf7d72c 286LDEMUL_AFTER_OPEN=ppc_after_open
f9e6bfa8 287LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
This page took 0.633013 seconds and 4 git commands to generate.