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_TDATA)
34 /* Whether to run tls optimization. */
35 static int notlsopt = 0;
37 /* Whether to emit symbols for stubs. */
38 static int emit_stub_syms = 0;
40 /* Chooses the correct place for .plt and .got. */
41 static enum ppc_elf_plt_type plt_style = PLT_UNSET;
42 static int old_got = 0;
47 if (is_ppc_elf (link_info.output_bfd))
53 lang_output_section_statement_type *os;
54 lang_output_section_statement_type *plt_os[2];
55 lang_output_section_statement_type *got_os[2];
57 emit_stub_syms |= link_info.emitrelocations;
58 new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info,
59 plt_style, emit_stub_syms);
61 einfo ("%X%P: select_plt_layout problem %E\n");
65 for (os = &lang_output_section_statement.head->output_section_statement;
69 if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
75 if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
83 keep_new = new_plt == 1 ? 0 : -1;
86 plt_os[0]->constraint = keep_new;
87 plt_os[1]->constraint = ~keep_new;
93 got_os[0]->constraint = keep_new;
94 got_os[1]->constraint = ~keep_new;
98 gld${EMULATION_NAME}_after_open ();
102 ppc_before_allocation (void)
104 if (is_ppc_elf (link_info.output_bfd))
106 if (ppc_elf_tls_setup (link_info.output_bfd, &link_info) && !notlsopt)
108 if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info))
110 einfo ("%X%P: TLS problem %E\n");
116 gld${EMULATION_NAME}_before_allocation ();
118 /* Turn on relaxation if executable sections have addresses that
119 might make branches overflow. */
120 if (!command_line.relax)
122 bfd_vma low = (bfd_vma) -1;
126 /* Run lang_size_sections (if not already done). */
127 if (expld.phase != lang_mark_phase_enum)
129 expld.phase = lang_mark_phase_enum;
130 expld.dataseg.phase = exp_dataseg_none;
131 one_lang_size_sections_pass (NULL, FALSE);
132 lang_reset_memory_regions ();
135 for (o = link_info.output_bfd->sections; o != NULL; o = o->next)
137 if ((o->flags & (SEC_ALLOC | SEC_CODE)) != (SEC_ALLOC | SEC_CODE))
143 if (high < o->vma + o->rawsize - 1)
144 high = o->vma + o->rawsize - 1;
146 if (high > low && high - low > (1 << 25) - 1)
147 command_line.relax = TRUE;
153 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
155 /* Special handling for embedded SPU executables. */
156 extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
157 static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
160 ppc_recognized_file (lang_input_statement_type *entry)
162 if (embedded_spu_file (entry, "-m32"))
165 return gld${EMULATION_NAME}_load_symbols (entry);
169 LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
172 # Define some shell vars to insert bits of code into the standard elf
173 # parse_args and list_options functions.
175 PARSE_AND_LIST_PROLOGUE='
176 #define OPTION_NO_TLS_OPT 301
177 #define OPTION_NEW_PLT 302
178 #define OPTION_OLD_PLT 303
179 #define OPTION_OLD_GOT 304
180 #define OPTION_STUBSYMS 305
183 PARSE_AND_LIST_LONGOPTS='
184 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
185 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
186 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
187 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
188 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
191 PARSE_AND_LIST_OPTIONS='
193 --emit-stub-syms Label linker stubs with a symbol.\n\
194 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
195 --secure-plt Use new-style PLT if possible.\n\
196 --bss-plt Force old-style BSS PLT.\n\
197 --sdata-got Force GOT location just before .sdata.\n"
201 PARSE_AND_LIST_ARGS_CASES='
202 case OPTION_STUBSYMS:
206 case OPTION_NO_TLS_OPT:
223 # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
225 LDEMUL_AFTER_OPEN=ppc_after_open
226 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation