* emultempl/alphaelf.em: Format option help.
[binutils-gdb.git] / ld / emultempl / ppc32elf.em
1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2003, 2005, 2007 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
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 3 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
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21
22 # This file is sourced from elf32.em, and defines extra powerpc32-elf
23 # specific routines.
24 #
25 fragment <<EOF
26
27 #include "libbfd.h"
28 #include "elf32-ppc.h"
29
30 extern const bfd_target bfd_elf32_powerpc_vec;
31 extern const bfd_target bfd_elf32_powerpcle_vec;
32 extern const bfd_target bfd_elf32_powerpc_vxworks_vec;
33
34 static inline int
35 is_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 }
41
42 /* Whether to run tls optimization. */
43 static int notlsopt = 0;
44
45 /* Whether to emit symbols for stubs. */
46 static int emit_stub_syms = 0;
47
48 /* Chooses the correct place for .plt and .got. */
49 static enum ppc_elf_plt_type plt_style = PLT_UNSET;
50 static int old_got = 0;
51
52 static void
53 ppc_after_open (void)
54 {
55 if (is_ppc_elf32_vec (link_info.hash->creator))
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
65 emit_stub_syms |= link_info.emitrelocations;
66 new_plt = ppc_elf_select_plt_layout (output_bfd, &link_info, plt_style,
67 emit_stub_syms);
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
109 static void
110 ppc_before_allocation (void)
111 {
112 if (is_ppc_elf32_vec (link_info.hash->creator))
113 {
114 if (ppc_elf_tls_setup (output_bfd, &link_info) && !notlsopt)
115 {
116 if (!ppc_elf_tls_optimize (output_bfd, &link_info))
117 {
118 einfo ("%X%P: TLS problem %E\n");
119 return;
120 }
121 }
122 }
123 gld${EMULATION_NAME}_before_allocation ();
124 }
125
126 EOF
127
128 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
129 fragment <<EOF
130 /* Special handling for embedded SPU executables. */
131 extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
132 static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
133
134 static bfd_boolean
135 ppc_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
143 EOF
144 LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
145 fi
146
147 # Define some shell vars to insert bits of code into the standard elf
148 # parse_args and list_options functions.
149 #
150 PARSE_AND_LIST_PROLOGUE='
151 #define OPTION_NO_TLS_OPT 301
152 #define OPTION_NEW_PLT 302
153 #define OPTION_OLD_PLT 303
154 #define OPTION_OLD_GOT 304
155 #define OPTION_STUBSYMS 305
156 '
157
158 PARSE_AND_LIST_LONGOPTS='
159 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
160 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
161 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
162 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
163 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
164 '
165
166 PARSE_AND_LIST_OPTIONS='
167 fprintf (file, _("\
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"
173 ));
174 '
175
176 PARSE_AND_LIST_ARGS_CASES='
177 case OPTION_STUBSYMS:
178 emit_stub_syms = 1;
179 break;
180
181 case OPTION_NO_TLS_OPT:
182 notlsopt = 1;
183 break;
184
185 case OPTION_NEW_PLT:
186 plt_style = PLT_NEW;
187 break;
188
189 case OPTION_OLD_PLT:
190 plt_style = PLT_OLD;
191 break;
192
193 case OPTION_OLD_GOT:
194 old_got = 1;
195 break;
196 '
197
198 # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
199 #
200 LDEMUL_AFTER_OPEN=ppc_after_open
201 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation