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