1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2003, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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,
22 # This file is sourced from elf32.em, and defines extra powerpc32-elf
28 #include "elf32-ppc.h"
30 #define is_ppc_elf(bfd) \
31 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
32 && elf_object_id (bfd) == PPC32_ELF_DATA)
34 /* Whether to run tls optimization. */
35 static int notlsopt = 0;
36 static int no_tls_get_addr_opt = 0;
38 /* Whether to emit symbols for stubs. */
39 static int emit_stub_syms = -1;
41 /* Chooses the correct place for .plt and .got. */
42 static enum ppc_elf_plt_type plt_style = PLT_UNSET;
43 static int old_got = 0;
48 if (is_ppc_elf (link_info.output_bfd))
54 lang_output_section_statement_type *os;
55 lang_output_section_statement_type *plt_os[2];
56 lang_output_section_statement_type *got_os[2];
58 if (emit_stub_syms < 0)
59 emit_stub_syms = link_info.emitrelocations || link_info.shared;
60 new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info,
61 plt_style, emit_stub_syms);
63 einfo ("%X%P: select_plt_layout problem %E\n");
67 for (os = &lang_output_section_statement.head->output_section_statement;
71 if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
77 if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
85 keep_new = new_plt == 1 ? 0 : -1;
88 plt_os[0]->constraint = keep_new;
89 plt_os[1]->constraint = ~keep_new;
95 got_os[0]->constraint = keep_new;
96 got_os[1]->constraint = ~keep_new;
100 gld${EMULATION_NAME}_after_open ();
104 ppc_before_allocation (void)
106 if (is_ppc_elf (link_info.output_bfd))
108 if (ppc_elf_tls_setup (link_info.output_bfd, &link_info,
112 if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info))
114 einfo ("%X%P: TLS problem %E\n");
120 gld${EMULATION_NAME}_before_allocation ();
122 /* Turn on relaxation if executable sections have addresses that
123 might make branches overflow. */
124 if (RELAXATION_DISABLED_BY_DEFAULT)
126 bfd_vma low = (bfd_vma) -1;
130 /* Run lang_size_sections (if not already done). */
131 if (expld.phase != lang_mark_phase_enum)
133 expld.phase = lang_mark_phase_enum;
134 expld.dataseg.phase = exp_dataseg_none;
135 one_lang_size_sections_pass (NULL, FALSE);
136 lang_reset_memory_regions ();
139 for (o = link_info.output_bfd->sections; o != NULL; o = o->next)
141 if ((o->flags & (SEC_ALLOC | SEC_CODE)) != (SEC_ALLOC | SEC_CODE))
147 if (high < o->vma + o->rawsize - 1)
148 high = o->vma + o->rawsize - 1;
150 if (high > low && high - low > (1 << 25) - 1)
157 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
159 /* Special handling for embedded SPU executables. */
160 extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
161 static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
164 ppc_recognized_file (lang_input_statement_type *entry)
166 if (embedded_spu_file (entry, "-m32"))
169 return gld${EMULATION_NAME}_load_symbols (entry);
173 LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
176 # Define some shell vars to insert bits of code into the standard elf
177 # parse_args and list_options functions.
179 PARSE_AND_LIST_PROLOGUE='
180 #define OPTION_NO_TLS_OPT 301
181 #define OPTION_NO_TLS_GET_ADDR_OPT (OPTION_NO_TLS_OPT + 1)
182 #define OPTION_NEW_PLT (OPTION_NO_TLS_GET_ADDR_OPT + 1)
183 #define OPTION_OLD_PLT (OPTION_NEW_PLT + 1)
184 #define OPTION_OLD_GOT (OPTION_OLD_PLT + 1)
185 #define OPTION_STUBSYMS (OPTION_OLD_GOT + 1)
186 #define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1)
189 PARSE_AND_LIST_LONGOPTS='
190 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
191 { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
192 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
193 { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },
194 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
195 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
196 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
199 PARSE_AND_LIST_OPTIONS='
201 --emit-stub-syms Label linker stubs with a symbol.\n\
202 --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\
203 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
204 --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n\
205 --secure-plt Use new-style PLT if possible.\n\
206 --bss-plt Force old-style BSS PLT.\n\
207 --sdata-got Force GOT location just before .sdata.\n"
211 PARSE_AND_LIST_ARGS_CASES='
212 case OPTION_STUBSYMS:
216 case OPTION_NO_STUBSYMS:
220 case OPTION_NO_TLS_OPT:
224 case OPTION_NO_TLS_GET_ADDR_OPT:
225 no_tls_get_addr_opt = 1;
241 # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
243 LDEMUL_AFTER_OPEN=ppc_after_open
244 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation