Add output_type to bfd_link_info
[deliverable/binutils-gdb.git] / ld / emultempl / ppc32elf.em
CommitLineData
f9e6bfa8 1# This shell script emits a C file. -*- C -*-
b90efa5b 2# Copyright (C) 2003-2015 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 25fragment <<EOF
f9e6bfa8
AM
26
27#include "libbfd.h"
28#include "elf32-ppc.h"
f05eb3b7 29#include "ldlex.h"
b4ab4364 30#include "ldlang.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
795bc6b3
AM
42static bfd_vma pagesize = 0;
43
d3e454b9 44static struct ppc_elf_params params = { PLT_UNSET, -1, 0, 0, 0, 0, 0 };
5446cbdf
AM
45
46static void
47ppc_after_open_output (void)
48{
49 if (params.emit_stub_syms < 0)
0e1862bb
L
50 params.emit_stub_syms = (link_info.emitrelocations
51 || bfd_link_pic (&link_info));
795bc6b3
AM
52 if (pagesize == 0)
53 pagesize = config.commonpagesize;
54 params.pagesize_p2 = bfd_log2 (pagesize);
5446cbdf
AM
55 ppc_elf_link_params (&link_info, &params);
56}
57
db434ba0
AM
58EOF
59
60# No --secure-plt, --bss-plt, or --sdata-got for vxworks.
61if test -z "$VXWORKS_BASE_EM_FILE" ; then
62 fragment <<EOF
0cf7d72c
AM
63static void
64ppc_after_open (void)
65{
5503fea1 66 if (is_ppc_elf (link_info.output_bfd))
0cf7d72c
AM
67 {
68 int new_plt;
69 int keep_new;
70 unsigned int num_plt;
71 unsigned int num_got;
72 lang_output_section_statement_type *os;
73 lang_output_section_statement_type *plt_os[2];
74 lang_output_section_statement_type *got_os[2];
75
5446cbdf 76 new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info);
0cf7d72c
AM
77 if (new_plt < 0)
78 einfo ("%X%P: select_plt_layout problem %E\n");
79
80 num_got = 0;
81 num_plt = 0;
82 for (os = &lang_output_section_statement.head->output_section_statement;
83 os != NULL;
84 os = os->next)
85 {
86 if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
87 {
88 if (num_plt < 2)
89 plt_os[num_plt] = os;
90 ++num_plt;
91 }
92 if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
93 {
94 if (num_got < 2)
95 got_os[num_got] = os;
96 ++num_got;
97 }
98 }
99
100 keep_new = new_plt == 1 ? 0 : -1;
101 if (num_plt == 2)
102 {
103 plt_os[0]->constraint = keep_new;
104 plt_os[1]->constraint = ~keep_new;
105 }
106 if (num_got == 2)
107 {
108 if (old_got)
109 keep_new = -1;
110 got_os[0]->constraint = keep_new;
111 got_os[1]->constraint = ~keep_new;
112 }
113 }
114
115 gld${EMULATION_NAME}_after_open ();
116}
117
db434ba0
AM
118EOF
119fi
120fragment <<EOF
f9e6bfa8 121static void
7e5d8d48 122ppc_before_allocation (void)
f9e6bfa8 123{
5503fea1 124 if (is_ppc_elf (link_info.output_bfd))
f9e6bfa8 125 {
5446cbdf 126 if (ppc_elf_tls_setup (link_info.output_bfd, &link_info)
a7f2871e 127 && !notlsopt)
f9e6bfa8 128 {
f13a99db 129 if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info))
f9e6bfa8
AM
130 {
131 einfo ("%X%P: TLS problem %E\n");
132 return;
133 }
134 }
135 }
4135c73b 136
f9e6bfa8 137 gld${EMULATION_NAME}_before_allocation ();
4135c73b 138
93d1b056
AM
139 ppc_elf_maybe_strip_sdata_syms (&link_info);
140
5446cbdf
AM
141 if (RELAXATION_ENABLED)
142 params.branch_trampolines = 1;
143
4135c73b
AM
144 /* Turn on relaxation if executable sections have addresses that
145 might make branches overflow. */
5446cbdf 146 else if (!RELAXATION_DISABLED_BY_USER)
4135c73b
AM
147 {
148 bfd_vma low = (bfd_vma) -1;
149 bfd_vma high = 0;
150 asection *o;
151
152 /* Run lang_size_sections (if not already done). */
153 if (expld.phase != lang_mark_phase_enum)
154 {
155 expld.phase = lang_mark_phase_enum;
156 expld.dataseg.phase = exp_dataseg_none;
157 one_lang_size_sections_pass (NULL, FALSE);
158 lang_reset_memory_regions ();
159 }
160
161 for (o = link_info.output_bfd->sections; o != NULL; o = o->next)
162 {
163 if ((o->flags & (SEC_ALLOC | SEC_CODE)) != (SEC_ALLOC | SEC_CODE))
164 continue;
07088e95 165 if (o->rawsize == 0)
4135c73b
AM
166 continue;
167 if (low > o->vma)
168 low = o->vma;
07088e95
AM
169 if (high < o->vma + o->rawsize - 1)
170 high = o->vma + o->rawsize - 1;
4135c73b
AM
171 }
172 if (high > low && high - low > (1 << 25) - 1)
5446cbdf 173 params.branch_trampolines = 1;
4135c73b 174 }
5446cbdf 175
d3e454b9
AM
176 if (params.branch_trampolines
177 || params.ppc476_workaround
178 || params.pic_fixup > 0)
5446cbdf 179 ENABLE_RELAXATION;
f9e6bfa8
AM
180}
181
b4ab4364
AM
182/* Replaces default zero fill padding in executable sections with
183 "ba 0" instructions. This works around the ppc476 icache bug if we
184 have a function pointer tail call near the end of a page, some
185 small amount of padding, then the function called at the beginning
186 of the next page. If the "ba 0" is ever executed we should hit a
187 segv, so it's almost as good as an illegal instruction (zero). */
188
189static void
190no_zero_padding (lang_statement_union_type *l)
191{
192 if (l->header.type == lang_padding_statement_enum
193 && l->padding_statement.size != 0
194 && l->padding_statement.output_section != NULL
195 && (l->padding_statement.output_section->flags & SEC_CODE) != 0
196 && l->padding_statement.fill->size == 0)
197 {
198 struct _ppc_fill_type
199 {
200 size_t size;
201 unsigned char data[4];
202 };
203 static struct _ppc_fill_type fill_be = { 4, {0x48, 0, 0, 2} };
204 static struct _ppc_fill_type fill_le = { 4, {2, 0, 0, 0x48} };
205
206 if (bfd_big_endian (link_info.output_bfd))
207 l->padding_statement.fill = (struct _fill_type *) &fill_be;
208 else
209 l->padding_statement.fill = (struct _fill_type *) &fill_le;
210 }
211}
212
213static void
214ppc_finish (void)
215{
216 if (params.ppc476_workaround)
217 lang_for_each_statement (no_zero_padding);
218 finish_default ();
219}
220
f9e6bfa8
AM
221EOF
222
dc27aea4 223if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
92b93329 224 fragment <<EOF
dc27aea4
AM
225/* Special handling for embedded SPU executables. */
226extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
227static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
228
229static bfd_boolean
230ppc_recognized_file (lang_input_statement_type *entry)
231{
232 if (embedded_spu_file (entry, "-m32"))
233 return TRUE;
234
235 return gld${EMULATION_NAME}_load_symbols (entry);
236}
237
238EOF
239LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
240fi
241
f9e6bfa8
AM
242# Define some shell vars to insert bits of code into the standard elf
243# parse_args and list_options functions.
244#
58d180e8
AM
245PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
246#define OPTION_NO_TLS_OPT 321
a7f2871e
AM
247#define OPTION_NO_TLS_GET_ADDR_OPT (OPTION_NO_TLS_OPT + 1)
248#define OPTION_NEW_PLT (OPTION_NO_TLS_GET_ADDR_OPT + 1)
249#define OPTION_OLD_PLT (OPTION_NEW_PLT + 1)
250#define OPTION_OLD_GOT (OPTION_OLD_PLT + 1)
251#define OPTION_STUBSYMS (OPTION_OLD_GOT + 1)
b02c4cfa 252#define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1)
5446cbdf
AM
253#define OPTION_PPC476_WORKAROUND (OPTION_NO_STUBSYMS + 1)
254#define OPTION_NO_PPC476_WORKAROUND (OPTION_PPC476_WORKAROUND + 1)
d3e454b9 255#define OPTION_NO_PICFIXUP (OPTION_NO_PPC476_WORKAROUND + 1)
f9e6bfa8
AM
256'
257
58d180e8 258PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
0ba07910 259 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
b02c4cfa 260 { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
f9e6bfa8 261 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
db434ba0
AM
262 { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },'
263if test -z "$VXWORKS_BASE_EM_FILE" ; then
264 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
016687f8 265 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
0cf7d72c 266 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
db434ba0
AM
267 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },'
268fi
269PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
5446cbdf
AM
270 { "ppc476-workaround", optional_argument, NULL, OPTION_PPC476_WORKAROUND },
271 { "no-ppc476-workaround", no_argument, NULL, OPTION_NO_PPC476_WORKAROUND },
d3e454b9 272 { "no-pic-fixup", no_argument, NULL, OPTION_NO_PICFIXUP },
f9e6bfa8
AM
273'
274
58d180e8 275PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
f9e6bfa8 276 fprintf (file, _("\
442996ee 277 --emit-stub-syms Label linker stubs with a symbol.\n\
b02c4cfa 278 --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\
442996ee 279 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
db434ba0
AM
280 --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n'
281if test -z "$VXWORKS_BASE_EM_FILE" ; then
282 PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'\
442996ee
AM
283 --secure-plt Use new-style PLT if possible.\n\
284 --bss-plt Force old-style BSS PLT.\n\
db434ba0
AM
285 --sdata-got Force GOT location just before .sdata.\n'
286fi
287PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'\
5446cbdf
AM
288 --ppc476-workaround [=pagesize]\n\
289 Avoid a cache bug on ppc476.\n\
d3e454b9
AM
290 --no-ppc476-workaround Disable workaround.\n\
291 --no-pic-fixup Don'\''t edit non-pic to pic.\n"
f9e6bfa8
AM
292 ));
293'
294
58d180e8 295PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
0ba07910 296 case OPTION_STUBSYMS:
5446cbdf 297 params.emit_stub_syms = 1;
0ba07910
AM
298 break;
299
b02c4cfa 300 case OPTION_NO_STUBSYMS:
5446cbdf 301 params.emit_stub_syms = 0;
b02c4cfa
AM
302 break;
303
f9e6bfa8
AM
304 case OPTION_NO_TLS_OPT:
305 notlsopt = 1;
306 break;
0cf7d72c 307
a7f2871e 308 case OPTION_NO_TLS_GET_ADDR_OPT:
5446cbdf 309 params.no_tls_get_addr_opt = 1;
a7f2871e
AM
310 break;
311
016687f8 312 case OPTION_NEW_PLT:
5446cbdf 313 params.plt_style = PLT_NEW;
016687f8
AM
314 break;
315
0cf7d72c 316 case OPTION_OLD_PLT:
5446cbdf 317 params.plt_style = PLT_OLD;
0cf7d72c
AM
318 break;
319
320 case OPTION_OLD_GOT:
321 old_got = 1;
322 break;
f05eb3b7
AM
323
324 case OPTION_TRADITIONAL_FORMAT:
325 notlsopt = 1;
5446cbdf 326 params.no_tls_get_addr_opt = 1;
f05eb3b7 327 return FALSE;
5446cbdf
AM
328
329 case OPTION_PPC476_WORKAROUND:
330 params.ppc476_workaround = 1;
331 if (optarg != NULL)
332 {
333 char *end;
795bc6b3 334 pagesize = strtoul (optarg, &end, 0);
5446cbdf 335 if (*end
795bc6b3
AM
336 || (pagesize < 4096 && pagesize != 0)
337 || pagesize != (pagesize & -pagesize))
5446cbdf
AM
338 einfo (_("%P%F: invalid pagesize `%s'\''\n"), optarg);
339 }
340 break;
341
342 case OPTION_NO_PPC476_WORKAROUND:
343 params.ppc476_workaround = 0;
344 break;
d3e454b9
AM
345
346 case OPTION_NO_PICFIXUP:
347 params.pic_fixup = -1;
348 break;
f9e6bfa8
AM
349'
350
c9a2f333 351# Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
f9e6bfa8 352#
5446cbdf 353LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_after_open_output
db434ba0
AM
354if test -z "$VXWORKS_BASE_EM_FILE" ; then
355 LDEMUL_AFTER_OPEN=ppc_after_open
356fi
f9e6bfa8 357LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
b4ab4364 358LDEMUL_FINISH=ppc_finish
This page took 0.634711 seconds and 4 git commands to generate.