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