1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2006, 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 along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
21 # This file is sourced from elf32.em, and defines extra spu specific
24 cat >>e${EMULATION_NAME}.c <<EOF
26 #include "elf32-spu.h"
28 /* Non-zero if no overlay processing should be done. */
29 static int no_overlays = 0;
31 /* Non-zero if we want stubs on all calls out of overlay regions. */
32 static int non_overlay_stubs = 0;
34 /* Whether to emit symbols for stubs. */
35 static int emit_stub_syms = 0;
37 /* Range of valid addresses for loadable sections. */
38 static bfd_vma local_store_lo = 0;
39 static bfd_vma local_store_hi = 0x3ffff;
41 static const char ovl_mgr[] = {
44 ../binutils/bin2c < ${srcdir}/emultempl/spu_ovl.o >> e${EMULATION_NAME}.c
46 cat >>e${EMULATION_NAME}.c <<EOF
49 static const struct _ovl_stream ovl_mgr_stream = {
51 ovl_mgr + sizeof (ovl_mgr)
54 static asection *toe = NULL;
60 extern const bfd_target bfd_elf32_spu_vec;
62 return link_info.hash->creator == &bfd_elf32_spu_vec;
65 /* Create our note section. */
71 && !link_info.relocatable
72 && link_info.input_bfds != NULL
73 && !spu_elf_create_sections (output_bfd, &link_info))
74 einfo ("%X%P: can not create note section: %E\n");
76 gld${EMULATION_NAME}_after_open ();
79 /* Add section S at the end of output section OUTPUT_NAME.
81 Really, we should be duplicating ldlang.c map_input_to_output_sections
82 logic here, ie. using the linker script to find where the section
83 goes. That's rather a lot of code, and we don't want to run
84 map_input_to_output_sections again because most sections are already
85 mapped. So cheat, and put the section in a fixed place, ignoring any
86 attempt via a linker script to put .stub, .ovtab, and built-in
87 overlay manager code somewhere else. */
90 spu_place_special_section (asection *s, const char *output_name)
92 lang_output_section_statement_type *os;
94 os = lang_output_section_find (output_name);
97 const char *save = s->name;
98 s->name = output_name;
99 gld${EMULATION_NAME}_place_orphan (s);
103 lang_add_section (&os->children, s, os);
105 s->output_section->size += s->size;
108 /* Load built-in overlay manager, and tweak overlay section alignment. */
111 spu_elf_load_ovl_mgr (void)
113 lang_output_section_statement_type *os;
114 struct elf_link_hash_entry *h;
116 h = elf_link_hash_lookup (elf_hash_table (&link_info),
117 "__ovly_load", FALSE, FALSE, FALSE);
120 && (h->root.type == bfd_link_hash_defined
121 || h->root.type == bfd_link_hash_defweak)
124 /* User supplied __ovly_load. */
126 else if (ovl_mgr_stream.start == ovl_mgr_stream.end)
127 einfo ("%F%P: no built-in overlay manager\n");
130 lang_input_statement_type *ovl_is;
132 ovl_is = lang_add_input_file ("builtin ovl_mgr",
133 lang_input_file_is_file_enum,
136 if (!spu_elf_open_builtin_lib (&ovl_is->the_bfd, &ovl_mgr_stream))
137 einfo ("%X%P: can not open built-in overlay manager: %E\n");
142 if (!load_symbols (ovl_is, NULL))
143 einfo ("%X%P: can not load built-in overlay manager: %E\n");
145 /* Map overlay manager sections to output sections. */
146 for (in = ovl_is->the_bfd->sections; in != NULL; in = in->next)
147 if ((in->flags & (SEC_ALLOC | SEC_LOAD))
148 == (SEC_ALLOC | SEC_LOAD))
149 spu_place_special_section (in, ".text");
153 /* Ensure alignment of overlay sections is sufficient. */
154 for (os = &lang_output_section_statement.head->output_section_statement;
157 if (os->bfd_section != NULL
158 && spu_elf_section_data (os->bfd_section) != NULL
159 && spu_elf_section_data (os->bfd_section)->ovl_index != 0)
161 if (os->bfd_section->alignment_power < 4)
162 os->bfd_section->alignment_power = 4;
164 /* Also ensure size rounds up. */
165 os->block_value = 16;
169 /* Go find if we need to do anything special for overlays. */
172 spu_before_allocation (void)
175 && !link_info.relocatable
178 /* Size the sections. This is premature, but we need to know the
179 rough layout so that overlays can be found. */
180 expld.phase = lang_mark_phase_enum;
181 expld.dataseg.phase = exp_dataseg_none;
182 one_lang_size_sections_pass (NULL, TRUE);
184 /* Find overlays by inspecting section vmas. */
185 if (spu_elf_find_overlays (output_bfd, &link_info))
187 asection *stub, *ovtab;
189 if (!spu_elf_size_stubs (output_bfd, &link_info, non_overlay_stubs,
190 &stub, &ovtab, &toe))
191 einfo ("%X%P: can not size overlay stubs: %E\n");
195 spu_place_special_section (stub, ".text");
196 spu_place_special_section (ovtab, ".data");
197 spu_place_special_section (toe, ".toe");
199 spu_elf_load_ovl_mgr ();
203 /* We must not cache anything from the preliminary sizing. */
204 lang_reset_memory_regions ();
207 gld${EMULATION_NAME}_before_allocation ();
210 /* Final emulation specific call. */
213 gld${EMULATION_NAME}_finish (void)
217 need_laying_out = bfd_elf_discard_info (output_bfd, &link_info);
219 gld${EMULATION_NAME}_map_segments (need_laying_out);
221 if (is_spu_target () && local_store_lo < local_store_hi)
225 s = spu_elf_check_vma (output_bfd, local_store_lo, local_store_hi);
227 einfo ("%X%P: %A exceeds local store range\n", s);
231 && !spu_elf_build_stubs (&link_info,
232 emit_stub_syms || link_info.emitrelocations,
234 einfo ("%X%P: can not build overlay stubs: %E\n");
241 # Define some shell vars to insert bits of code into the standard elf
242 # parse_args and list_options functions.
244 PARSE_AND_LIST_PROLOGUE='
245 #define OPTION_SPU_PLUGIN 301
246 #define OPTION_SPU_NO_OVERLAYS (OPTION_SPU_PLUGIN + 1)
247 #define OPTION_SPU_STUB_SYMS (OPTION_SPU_NO_OVERLAYS + 1)
248 #define OPTION_SPU_NON_OVERLAY_STUBS (OPTION_SPU_STUB_SYMS + 1)
249 #define OPTION_SPU_LOCAL_STORE (OPTION_SPU_NON_OVERLAY_STUBS + 1)
252 PARSE_AND_LIST_LONGOPTS='
253 { "plugin", no_argument, NULL, OPTION_SPU_PLUGIN },
254 { "no-overlays", no_argument, NULL, OPTION_SPU_NO_OVERLAYS },
255 { "emit-stub-syms", no_argument, NULL, OPTION_SPU_STUB_SYMS },
256 { "extra-overlay-stubs", no_argument, NULL, OPTION_SPU_NON_OVERLAY_STUBS },
257 { "local-store", required_argument, NULL, OPTION_SPU_LOCAL_STORE },
260 PARSE_AND_LIST_OPTIONS='
262 --plugin Make SPU plugin.\n\
263 --no-overlays No overlay handling.\n\
264 --emit-stub-syms Add symbols on overlay call stubs.\n\
265 --extra-overlay-stubs Add stubs on all calls out of overlay regions.\n\
266 --local-store=lo:hi Valid address range.\n"
270 PARSE_AND_LIST_ARGS_CASES='
271 case OPTION_SPU_PLUGIN:
275 case OPTION_SPU_NO_OVERLAYS:
279 case OPTION_SPU_STUB_SYMS:
283 case OPTION_SPU_NON_OVERLAY_STUBS:
284 non_overlay_stubs = 1;
287 case OPTION_SPU_LOCAL_STORE:
290 local_store_lo = strtoul (optarg, &end, 0);
291 if (*end == '\'':'\'')
293 local_store_hi = strtoul (end + 1, &end, 0);
297 einfo (_("%P%F: invalid --local-store address range `%s'\''\n"), optarg);
302 LDEMUL_AFTER_OPEN=spu_after_open
303 LDEMUL_BEFORE_ALLOCATION=spu_before_allocation
304 LDEMUL_FINISH=gld${EMULATION_NAME}_finish