* emultempl/ppc64elf.em (ppc_create_output_section_statements): Add
[deliverable/binutils-gdb.git] / ld / emultempl / ppc32elf.em
1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2003, 2005, 2007, 2008, 2009, 2010, 2011
3 # Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU Binutils.
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
9 # the Free Software Foundation; either version 3 of the License, or
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
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21 #
22
23 # This file is sourced from elf32.em, and defines extra powerpc32-elf
24 # specific routines.
25 #
26 fragment <<EOF
27
28 #include "libbfd.h"
29 #include "elf32-ppc.h"
30
31 #define is_ppc_elf(bfd) \
32 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
33 && elf_object_id (bfd) == PPC32_ELF_DATA)
34
35 /* Whether to run tls optimization. */
36 static int notlsopt = 0;
37 static int no_tls_get_addr_opt = 0;
38
39 /* Whether to emit symbols for stubs. */
40 static int emit_stub_syms = -1;
41
42 /* Chooses the correct place for .plt and .got. */
43 static enum ppc_elf_plt_type plt_style = PLT_UNSET;
44 static int old_got = 0;
45
46 static void
47 ppc_after_open (void)
48 {
49 if (is_ppc_elf (link_info.output_bfd))
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
59 if (emit_stub_syms < 0)
60 emit_stub_syms = link_info.emitrelocations || link_info.shared;
61 new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info,
62 plt_style, emit_stub_syms);
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
104 static void
105 ppc_before_allocation (void)
106 {
107 if (is_ppc_elf (link_info.output_bfd))
108 {
109 if (ppc_elf_tls_setup (link_info.output_bfd, &link_info,
110 no_tls_get_addr_opt)
111 && !notlsopt)
112 {
113 if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info))
114 {
115 einfo ("%X%P: TLS problem %E\n");
116 return;
117 }
118 }
119 }
120
121 gld${EMULATION_NAME}_before_allocation ();
122
123 /* Turn on relaxation if executable sections have addresses that
124 might make branches overflow. */
125 if (RELAXATION_DISABLED_BY_DEFAULT)
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;
144 if (o->rawsize == 0)
145 continue;
146 if (low > o->vma)
147 low = o->vma;
148 if (high < o->vma + o->rawsize - 1)
149 high = o->vma + o->rawsize - 1;
150 }
151 if (high > low && high - low > (1 << 25) - 1)
152 ENABLE_RELAXATION;
153 }
154 }
155
156 EOF
157
158 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
159 fragment <<EOF
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
177 # Define some shell vars to insert bits of code into the standard elf
178 # parse_args and list_options functions.
179 #
180 PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
181 #define OPTION_NO_TLS_OPT 321
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)
187 #define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1)
188 '
189
190 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
191 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
192 { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
193 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
194 { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },
195 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
196 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
197 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
198 '
199
200 PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
201 fprintf (file, _("\
202 --emit-stub-syms Label linker stubs with a symbol.\n\
203 --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\
204 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
205 --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n\
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"
209 ));
210 '
211
212 PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
213 case OPTION_STUBSYMS:
214 emit_stub_syms = 1;
215 break;
216
217 case OPTION_NO_STUBSYMS:
218 emit_stub_syms = 0;
219 break;
220
221 case OPTION_NO_TLS_OPT:
222 notlsopt = 1;
223 break;
224
225 case OPTION_NO_TLS_GET_ADDR_OPT:
226 no_tls_get_addr_opt = 1;
227 break;
228
229 case OPTION_NEW_PLT:
230 plt_style = PLT_NEW;
231 break;
232
233 case OPTION_OLD_PLT:
234 plt_style = PLT_OLD;
235 break;
236
237 case OPTION_OLD_GOT:
238 old_got = 1;
239 break;
240 '
241
242 # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
243 #
244 LDEMUL_AFTER_OPEN=ppc_after_open
245 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
This page took 0.034726 seconds and 4 git commands to generate.