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