bfd:
[deliverable/binutils-gdb.git] / ld / emultempl / ppc32elf.em
CommitLineData
f9e6bfa8 1# This shell script emits a C file. -*- C -*-
016687f8 2# Copyright 2003, 2005, 2007 Free Software Foundation, Inc.
f9e6bfa8
AM
3#
4# This file is part of GLD, the Gnu Linker.
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
8# the Free Software Foundation; either version 2 of the License, or
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
75be928b 18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
f9e6bfa8
AM
19#
20
c9a2f333 21# This file is sourced from elf32.em, and defines extra powerpc32-elf
f9e6bfa8
AM
22# specific routines.
23#
24cat >>e${EMULATION_NAME}.c <<EOF
25
26#include "libbfd.h"
27#include "elf32-ppc.h"
28
c9a2f333
AM
29extern const bfd_target bfd_elf32_powerpc_vec;
30extern const bfd_target bfd_elf32_powerpcle_vec;
9d8504b1
PB
31extern const bfd_target bfd_elf32_powerpc_vxworks_vec;
32
33static inline int
34is_ppc_elf32_vec(const bfd_target * vec)
35{
36 return (vec == &bfd_elf32_powerpc_vec
37 || vec == &bfd_elf32_powerpc_vxworks_vec
38 || vec == &bfd_elf32_powerpcle_vec);
39}
c9a2f333 40
f9e6bfa8
AM
41/* Whether to run tls optimization. */
42static int notlsopt = 0;
43
0ba07910
AM
44/* Whether to emit symbols for stubs. */
45static int emit_stub_syms = 0;
46
0cf7d72c 47/* Chooses the correct place for .plt and .got. */
016687f8 48static enum ppc_elf_plt_type plt_style = PLT_UNSET;
0cf7d72c
AM
49static int old_got = 0;
50
51static void
52ppc_after_open (void)
53{
9d8504b1 54 if (is_ppc_elf32_vec (link_info.hash->creator))
0cf7d72c
AM
55 {
56 int new_plt;
57 int keep_new;
58 unsigned int num_plt;
59 unsigned int num_got;
60 lang_output_section_statement_type *os;
61 lang_output_section_statement_type *plt_os[2];
62 lang_output_section_statement_type *got_os[2];
63
0ba07910 64 emit_stub_syms |= link_info.emitrelocations;
016687f8 65 new_plt = ppc_elf_select_plt_layout (output_bfd, &link_info, plt_style,
0ba07910 66 emit_stub_syms);
0cf7d72c
AM
67 if (new_plt < 0)
68 einfo ("%X%P: select_plt_layout problem %E\n");
69
70 num_got = 0;
71 num_plt = 0;
72 for (os = &lang_output_section_statement.head->output_section_statement;
73 os != NULL;
74 os = os->next)
75 {
76 if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
77 {
78 if (num_plt < 2)
79 plt_os[num_plt] = os;
80 ++num_plt;
81 }
82 if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
83 {
84 if (num_got < 2)
85 got_os[num_got] = os;
86 ++num_got;
87 }
88 }
89
90 keep_new = new_plt == 1 ? 0 : -1;
91 if (num_plt == 2)
92 {
93 plt_os[0]->constraint = keep_new;
94 plt_os[1]->constraint = ~keep_new;
95 }
96 if (num_got == 2)
97 {
98 if (old_got)
99 keep_new = -1;
100 got_os[0]->constraint = keep_new;
101 got_os[1]->constraint = ~keep_new;
102 }
103 }
104
105 gld${EMULATION_NAME}_after_open ();
106}
107
f9e6bfa8 108static void
7e5d8d48 109ppc_before_allocation (void)
f9e6bfa8 110{
9d8504b1 111 if (is_ppc_elf32_vec (link_info.hash->creator))
f9e6bfa8
AM
112 {
113 if (ppc_elf_tls_setup (output_bfd, &link_info) && !notlsopt)
114 {
115 if (!ppc_elf_tls_optimize (output_bfd, &link_info))
116 {
117 einfo ("%X%P: TLS problem %E\n");
118 return;
119 }
120 }
121 }
122 gld${EMULATION_NAME}_before_allocation ();
123}
124
125EOF
126
dc27aea4
AM
127if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
128 cat >>e${EMULATION_NAME}.c <<EOF
129/* Special handling for embedded SPU executables. */
130extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
131static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
132
133static bfd_boolean
134ppc_recognized_file (lang_input_statement_type *entry)
135{
136 if (embedded_spu_file (entry, "-m32"))
137 return TRUE;
138
139 return gld${EMULATION_NAME}_load_symbols (entry);
140}
141
142EOF
143LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
144fi
145
f9e6bfa8
AM
146# Define some shell vars to insert bits of code into the standard elf
147# parse_args and list_options functions.
148#
149PARSE_AND_LIST_PROLOGUE='
150#define OPTION_NO_TLS_OPT 301
016687f8
AM
151#define OPTION_NEW_PLT 302
152#define OPTION_OLD_PLT 303
153#define OPTION_OLD_GOT 304
154#define OPTION_STUBSYMS 305
f9e6bfa8
AM
155'
156
f9e6bfa8 157PARSE_AND_LIST_LONGOPTS='
0ba07910 158 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
f9e6bfa8 159 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
016687f8 160 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
0cf7d72c
AM
161 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
162 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
f9e6bfa8
AM
163'
164
165PARSE_AND_LIST_OPTIONS='
166 fprintf (file, _("\
0ba07910 167 --emit-stub-syms Label linker stubs with a symbol.\n\
0cf7d72c 168 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
016687f8 169 --secure-plt Use new-style PLT if possible.\n\
0cf7d72c
AM
170 --bss-plt Force old-style BSS PLT.\n\
171 --sdata-got Force GOT location just before .sdata.\n"
f9e6bfa8
AM
172 ));
173'
174
175PARSE_AND_LIST_ARGS_CASES='
0ba07910
AM
176 case OPTION_STUBSYMS:
177 emit_stub_syms = 1;
178 break;
179
f9e6bfa8
AM
180 case OPTION_NO_TLS_OPT:
181 notlsopt = 1;
182 break;
0cf7d72c 183
016687f8
AM
184 case OPTION_NEW_PLT:
185 plt_style = PLT_NEW;
186 break;
187
0cf7d72c 188 case OPTION_OLD_PLT:
016687f8 189 plt_style = PLT_OLD;
0cf7d72c
AM
190 break;
191
192 case OPTION_OLD_GOT:
193 old_got = 1;
194 break;
f9e6bfa8
AM
195'
196
c9a2f333 197# Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
f9e6bfa8 198#
0cf7d72c 199LDEMUL_AFTER_OPEN=ppc_after_open
f9e6bfa8 200LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
This page took 0.181611 seconds and 4 git commands to generate.