1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2003, 2005, 2007 Free Software Foundation, Inc.
4 # This file is part of GLD, the Gnu Linker.
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.
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, MA 02110-1301, USA.
21 # This file is sourced from elf32.em, and defines extra powerpc32-elf
24 cat >>e${EMULATION_NAME}.c <<EOF
27 #include "elf32-ppc.h"
29 extern const bfd_target bfd_elf32_powerpc_vec;
30 extern const bfd_target bfd_elf32_powerpcle_vec;
31 extern const bfd_target bfd_elf32_powerpc_vxworks_vec;
34 is_ppc_elf32_vec(const bfd_target * vec)
36 return (vec == &bfd_elf32_powerpc_vec
37 || vec == &bfd_elf32_powerpc_vxworks_vec
38 || vec == &bfd_elf32_powerpcle_vec);
41 /* Whether to run tls optimization. */
42 static int notlsopt = 0;
44 /* Whether to emit symbols for stubs. */
45 static int emit_stub_syms = 0;
47 /* Chooses the correct place for .plt and .got. */
48 static enum ppc_elf_plt_type plt_style = PLT_UNSET;
49 static int old_got = 0;
54 if (is_ppc_elf32_vec (link_info.hash->creator))
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];
64 emit_stub_syms |= link_info.emitrelocations;
65 new_plt = ppc_elf_select_plt_layout (output_bfd, &link_info, plt_style,
68 einfo ("%X%P: select_plt_layout problem %E\n");
72 for (os = &lang_output_section_statement.head->output_section_statement;
76 if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
82 if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
90 keep_new = new_plt == 1 ? 0 : -1;
93 plt_os[0]->constraint = keep_new;
94 plt_os[1]->constraint = ~keep_new;
100 got_os[0]->constraint = keep_new;
101 got_os[1]->constraint = ~keep_new;
105 gld${EMULATION_NAME}_after_open ();
109 ppc_before_allocation (void)
111 if (is_ppc_elf32_vec (link_info.hash->creator))
113 if (ppc_elf_tls_setup (output_bfd, &link_info) && !notlsopt)
115 if (!ppc_elf_tls_optimize (output_bfd, &link_info))
117 einfo ("%X%P: TLS problem %E\n");
123 gld${EMULATION_NAME}_before_allocation ();
125 /* Turn on relaxation if executable sections have addresses that
126 might make branches overflow. */
127 if (!command_line.relax)
129 bfd_vma low = (bfd_vma) -1;
133 /* Run lang_size_sections (if not already done). */
134 if (expld.phase != lang_mark_phase_enum)
136 expld.phase = lang_mark_phase_enum;
137 expld.dataseg.phase = exp_dataseg_none;
138 one_lang_size_sections_pass (NULL, FALSE);
139 lang_reset_memory_regions ();
142 for (o = output_bfd->sections; o != NULL; o = o->next)
144 if ((o->flags & (SEC_ALLOC | SEC_CODE)) != (SEC_ALLOC | SEC_CODE))
150 if (high < o->vma + o->rawsize - 1)
151 high = o->vma + o->rawsize - 1;
153 if (high > low && high - low > (1 << 25) - 1)
154 command_line.relax = TRUE;
160 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
161 cat >>e${EMULATION_NAME}.c <<EOF
162 /* Special handling for embedded SPU executables. */
163 extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
164 static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
167 ppc_recognized_file (lang_input_statement_type *entry)
169 if (embedded_spu_file (entry, "-m32"))
172 return gld${EMULATION_NAME}_load_symbols (entry);
176 LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
179 # Define some shell vars to insert bits of code into the standard elf
180 # parse_args and list_options functions.
182 PARSE_AND_LIST_PROLOGUE='
183 #define OPTION_NO_TLS_OPT 301
184 #define OPTION_NEW_PLT 302
185 #define OPTION_OLD_PLT 303
186 #define OPTION_OLD_GOT 304
187 #define OPTION_STUBSYMS 305
190 PARSE_AND_LIST_LONGOPTS='
191 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
192 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
193 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
194 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
195 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
198 PARSE_AND_LIST_OPTIONS='
200 --emit-stub-syms Label linker stubs with a symbol.\n\
201 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
202 --secure-plt Use new-style PLT if possible.\n\
203 --bss-plt Force old-style BSS PLT.\n\
204 --sdata-got Force GOT location just before .sdata.\n"
208 PARSE_AND_LIST_ARGS_CASES='
209 case OPTION_STUBSYMS:
213 case OPTION_NO_TLS_OPT:
230 # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
232 LDEMUL_AFTER_OPEN=ppc_after_open
233 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation