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