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