ld/
[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;
a7f2871e 38static int no_tls_get_addr_opt = 0;
f9e6bfa8 39
0ba07910 40/* Whether to emit symbols for stubs. */
b02c4cfa 41static int emit_stub_syms = -1;
0ba07910 42
0cf7d72c 43/* Chooses the correct place for .plt and .got. */
016687f8 44static enum ppc_elf_plt_type plt_style = PLT_UNSET;
0cf7d72c
AM
45static int old_got = 0;
46
47static void
48ppc_after_open (void)
49{
5503fea1 50 if (is_ppc_elf (link_info.output_bfd))
0cf7d72c
AM
51 {
52 int new_plt;
53 int keep_new;
54 unsigned int num_plt;
55 unsigned int num_got;
56 lang_output_section_statement_type *os;
57 lang_output_section_statement_type *plt_os[2];
58 lang_output_section_statement_type *got_os[2];
59
b02c4cfa
AM
60 if (emit_stub_syms < 0)
61 emit_stub_syms = link_info.emitrelocations || link_info.shared;
f13a99db
AM
62 new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info,
63 plt_style, emit_stub_syms);
0cf7d72c
AM
64 if (new_plt < 0)
65 einfo ("%X%P: select_plt_layout problem %E\n");
66
67 num_got = 0;
68 num_plt = 0;
69 for (os = &lang_output_section_statement.head->output_section_statement;
70 os != NULL;
71 os = os->next)
72 {
73 if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
74 {
75 if (num_plt < 2)
76 plt_os[num_plt] = os;
77 ++num_plt;
78 }
79 if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
80 {
81 if (num_got < 2)
82 got_os[num_got] = os;
83 ++num_got;
84 }
85 }
86
87 keep_new = new_plt == 1 ? 0 : -1;
88 if (num_plt == 2)
89 {
90 plt_os[0]->constraint = keep_new;
91 plt_os[1]->constraint = ~keep_new;
92 }
93 if (num_got == 2)
94 {
95 if (old_got)
96 keep_new = -1;
97 got_os[0]->constraint = keep_new;
98 got_os[1]->constraint = ~keep_new;
99 }
100 }
101
102 gld${EMULATION_NAME}_after_open ();
103}
104
f9e6bfa8 105static void
7e5d8d48 106ppc_before_allocation (void)
f9e6bfa8 107{
5503fea1 108 if (is_ppc_elf (link_info.output_bfd))
f9e6bfa8 109 {
a7f2871e
AM
110 if (ppc_elf_tls_setup (link_info.output_bfd, &link_info,
111 no_tls_get_addr_opt)
112 && !notlsopt)
f9e6bfa8 113 {
f13a99db 114 if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info))
f9e6bfa8
AM
115 {
116 einfo ("%X%P: TLS problem %E\n");
117 return;
118 }
119 }
120 }
4135c73b 121
f9e6bfa8 122 gld${EMULATION_NAME}_before_allocation ();
4135c73b
AM
123
124 /* Turn on relaxation if executable sections have addresses that
125 might make branches overflow. */
28d5f677 126 if (RELAXATION_DISABLED_BY_DEFAULT)
4135c73b
AM
127 {
128 bfd_vma low = (bfd_vma) -1;
129 bfd_vma high = 0;
130 asection *o;
131
132 /* Run lang_size_sections (if not already done). */
133 if (expld.phase != lang_mark_phase_enum)
134 {
135 expld.phase = lang_mark_phase_enum;
136 expld.dataseg.phase = exp_dataseg_none;
137 one_lang_size_sections_pass (NULL, FALSE);
138 lang_reset_memory_regions ();
139 }
140
141 for (o = link_info.output_bfd->sections; o != NULL; o = o->next)
142 {
143 if ((o->flags & (SEC_ALLOC | SEC_CODE)) != (SEC_ALLOC | SEC_CODE))
144 continue;
07088e95 145 if (o->rawsize == 0)
4135c73b
AM
146 continue;
147 if (low > o->vma)
148 low = o->vma;
07088e95
AM
149 if (high < o->vma + o->rawsize - 1)
150 high = o->vma + o->rawsize - 1;
4135c73b
AM
151 }
152 if (high > low && high - low > (1 << 25) - 1)
28d5f677 153 ENABLE_RELAXATION;
4135c73b 154 }
f9e6bfa8
AM
155}
156
157EOF
158
dc27aea4 159if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
92b93329 160 fragment <<EOF
dc27aea4
AM
161/* Special handling for embedded SPU executables. */
162extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
163static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
164
165static bfd_boolean
166ppc_recognized_file (lang_input_statement_type *entry)
167{
168 if (embedded_spu_file (entry, "-m32"))
169 return TRUE;
170
171 return gld${EMULATION_NAME}_load_symbols (entry);
172}
173
174EOF
175LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
176fi
177
f9e6bfa8
AM
178# Define some shell vars to insert bits of code into the standard elf
179# parse_args and list_options functions.
180#
58d180e8
AM
181PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
182#define OPTION_NO_TLS_OPT 321
a7f2871e
AM
183#define OPTION_NO_TLS_GET_ADDR_OPT (OPTION_NO_TLS_OPT + 1)
184#define OPTION_NEW_PLT (OPTION_NO_TLS_GET_ADDR_OPT + 1)
185#define OPTION_OLD_PLT (OPTION_NEW_PLT + 1)
186#define OPTION_OLD_GOT (OPTION_OLD_PLT + 1)
187#define OPTION_STUBSYMS (OPTION_OLD_GOT + 1)
b02c4cfa 188#define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1)
f9e6bfa8
AM
189'
190
58d180e8 191PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
0ba07910 192 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
b02c4cfa 193 { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
f9e6bfa8 194 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
a7f2871e 195 { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },
016687f8 196 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
0cf7d72c
AM
197 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
198 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
f9e6bfa8
AM
199'
200
58d180e8 201PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
f9e6bfa8 202 fprintf (file, _("\
442996ee 203 --emit-stub-syms Label linker stubs with a symbol.\n\
b02c4cfa 204 --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\
442996ee 205 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
a7f2871e 206 --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n\
442996ee
AM
207 --secure-plt Use new-style PLT if possible.\n\
208 --bss-plt Force old-style BSS PLT.\n\
209 --sdata-got Force GOT location just before .sdata.\n"
f9e6bfa8
AM
210 ));
211'
212
58d180e8 213PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
0ba07910
AM
214 case OPTION_STUBSYMS:
215 emit_stub_syms = 1;
216 break;
217
b02c4cfa
AM
218 case OPTION_NO_STUBSYMS:
219 emit_stub_syms = 0;
220 break;
221
f9e6bfa8
AM
222 case OPTION_NO_TLS_OPT:
223 notlsopt = 1;
224 break;
0cf7d72c 225
a7f2871e
AM
226 case OPTION_NO_TLS_GET_ADDR_OPT:
227 no_tls_get_addr_opt = 1;
228 break;
229
016687f8
AM
230 case OPTION_NEW_PLT:
231 plt_style = PLT_NEW;
232 break;
233
0cf7d72c 234 case OPTION_OLD_PLT:
016687f8 235 plt_style = PLT_OLD;
0cf7d72c
AM
236 break;
237
238 case OPTION_OLD_GOT:
239 old_got = 1;
240 break;
f05eb3b7
AM
241
242 case OPTION_TRADITIONAL_FORMAT:
243 notlsopt = 1;
244 no_tls_get_addr_opt = 1;
245 return FALSE;
f9e6bfa8
AM
246'
247
c9a2f333 248# Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
f9e6bfa8 249#
0cf7d72c 250LDEMUL_AFTER_OPEN=ppc_after_open
f9e6bfa8 251LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
This page took 0.384831 seconds and 4 git commands to generate.