1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2003, 2005, 2007, 2008, 2009, 2010, 2011
3 # Free Software Foundation, Inc.
5 # This file is part of the GNU Binutils.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 # This file is sourced from elf32.em, and defines extra powerpc32-elf
29 #include "elf32-ppc.h"
31 #define is_ppc_elf(bfd) \
32 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
33 && elf_object_id (bfd) == PPC32_ELF_DATA)
35 /* Whether to run tls optimization. */
36 static int notlsopt = 0;
37 static int no_tls_get_addr_opt = 0;
39 /* Whether to emit symbols for stubs. */
40 static int emit_stub_syms = -1;
42 /* Chooses the correct place for .plt and .got. */
43 static enum ppc_elf_plt_type plt_style = PLT_UNSET;
44 static int old_got = 0;
49 if (is_ppc_elf (link_info.output_bfd))
55 lang_output_section_statement_type *os;
56 lang_output_section_statement_type *plt_os[2];
57 lang_output_section_statement_type *got_os[2];
59 if (emit_stub_syms < 0)
60 emit_stub_syms = link_info.emitrelocations || link_info.shared;
61 new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info,
62 plt_style, emit_stub_syms);
64 einfo ("%X%P: select_plt_layout problem %E\n");
68 for (os = &lang_output_section_statement.head->output_section_statement;
72 if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
78 if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
86 keep_new = new_plt == 1 ? 0 : -1;
89 plt_os[0]->constraint = keep_new;
90 plt_os[1]->constraint = ~keep_new;
96 got_os[0]->constraint = keep_new;
97 got_os[1]->constraint = ~keep_new;
101 gld${EMULATION_NAME}_after_open ();
105 ppc_before_allocation (void)
107 if (is_ppc_elf (link_info.output_bfd))
109 if (ppc_elf_tls_setup (link_info.output_bfd, &link_info,
113 if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info))
115 einfo ("%X%P: TLS problem %E\n");
121 gld${EMULATION_NAME}_before_allocation ();
123 /* Turn on relaxation if executable sections have addresses that
124 might make branches overflow. */
125 if (RELAXATION_DISABLED_BY_DEFAULT)
127 bfd_vma low = (bfd_vma) -1;
131 /* Run lang_size_sections (if not already done). */
132 if (expld.phase != lang_mark_phase_enum)
134 expld.phase = lang_mark_phase_enum;
135 expld.dataseg.phase = exp_dataseg_none;
136 one_lang_size_sections_pass (NULL, FALSE);
137 lang_reset_memory_regions ();
140 for (o = link_info.output_bfd->sections; o != NULL; o = o->next)
142 if ((o->flags & (SEC_ALLOC | SEC_CODE)) != (SEC_ALLOC | SEC_CODE))
148 if (high < o->vma + o->rawsize - 1)
149 high = o->vma + o->rawsize - 1;
151 if (high > low && high - low > (1 << 25) - 1)
158 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
160 /* Special handling for embedded SPU executables. */
161 extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
162 static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
165 ppc_recognized_file (lang_input_statement_type *entry)
167 if (embedded_spu_file (entry, "-m32"))
170 return gld${EMULATION_NAME}_load_symbols (entry);
174 LDEMUL_RECOGNIZED_FILE=ppc_recognized_file
177 # Define some shell vars to insert bits of code into the standard elf
178 # parse_args and list_options functions.
180 PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
181 #define OPTION_NO_TLS_OPT 321
182 #define OPTION_NO_TLS_GET_ADDR_OPT (OPTION_NO_TLS_OPT + 1)
183 #define OPTION_NEW_PLT (OPTION_NO_TLS_GET_ADDR_OPT + 1)
184 #define OPTION_OLD_PLT (OPTION_NEW_PLT + 1)
185 #define OPTION_OLD_GOT (OPTION_OLD_PLT + 1)
186 #define OPTION_STUBSYMS (OPTION_OLD_GOT + 1)
187 #define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1)
190 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
191 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
192 { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
193 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
194 { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },
195 { "secure-plt", no_argument, NULL, OPTION_NEW_PLT },
196 { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
197 { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
200 PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
202 --emit-stub-syms Label linker stubs with a symbol.\n\
203 --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\
204 --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\
205 --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n\
206 --secure-plt Use new-style PLT if possible.\n\
207 --bss-plt Force old-style BSS PLT.\n\
208 --sdata-got Force GOT location just before .sdata.\n"
212 PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
213 case OPTION_STUBSYMS:
217 case OPTION_NO_STUBSYMS:
221 case OPTION_NO_TLS_OPT:
225 case OPTION_NO_TLS_GET_ADDR_OPT:
226 no_tls_get_addr_opt = 1;
242 # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
244 LDEMUL_AFTER_OPEN=ppc_after_open
245 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation