1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 cat >em_${EMULATION_NAME}.c <<EOF
4 /* An emulation for HP PA-RISC ELF linkers.
5 Copyright (C) 1991, 1993 Free Software Foundation, Inc.
8 This file is part of GLD, the Gnu Linker.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
38 static lang_input_statement_type *stub_file = 0;
39 static lang_input_section_type *stub_input_section = NULL;
41 /* FIXME. This doesn't belong here. */
42 extern lang_statement_list_type file_chain;
44 /* Perform some emulation specific initialization. For PA ELF we set
45 up the local label prefix and the output architecture. */
48 hppaelf_before_parse ()
50 link_info.lprefix = "L$";
51 link_info.lprefix_len = 2;
53 ldfile_output_architecture = bfd_arch_hppa;
56 /* Walk all the lang statements splicing out any padding statements from
60 hppaelf_search_for_padding_statements (s, prev)
61 lang_statement_union_type *s;
62 lang_statement_union_type **prev;
64 lang_statement_union_type *sprev = NULL;
65 for (; s != NULL; s = s->next)
67 switch (s->header.type)
70 /* We want recursively walk these sections. */
71 case lang_constructors_statement_enum:
72 hppaelf_search_for_padding_statements (constructor_list.head,
73 &constructor_list.head);
76 case lang_output_section_statement_enum:
77 hppaelf_search_for_padding_statements (s->output_section_statement.
79 &s->output_section_statement.
83 /* Huh? What is a lang_wild_statement? */
84 case lang_wild_statement_enum:
85 hppaelf_search_for_padding_statements(s->wild_statement.
91 /* Here's what we are really looking for. Splice these out of
93 case lang_padding_statement_enum:
95 sprev->header.next = s->header.next;
100 /* We don't care about these cases. */
101 case lang_data_statement_enum:
102 case lang_object_symbols_statement_enum:
103 case lang_output_statement_enum:
104 case lang_target_statement_enum:
105 case lang_input_section_enum:
106 case lang_input_statement_enum:
107 case lang_assignment_statement_enum:
108 case lang_address_statement_enum:
119 /* Final emulation specific call. For the PA we use this opportunity
120 to determine what linker stubs are needed and generate them.
122 FIXME: fast-linker work broke this in a big way. statement->asymbols
123 doesn't have anything useful in it anymore. And if we slurp in
124 the symbol table here and pass it down then we get lots of undefined
131 /* Disabled until it's fixed to work with the new linker. A noteworty
132 amount of code will still function without linker stubs allowing us
133 to continue testing. */
135 /* Only create stubs for final objects. */
136 if (link_info.relocateable == false)
138 lang_input_statement_type *statement;
140 /* Look at all the statements. */
141 for (statement = (lang_input_statement_type *)file_chain.head;
143 statement = (lang_input_statement_type *)statement->next)
146 bfd *abfd = statement->the_bfd;
148 /* Look at all the sections attached to the bfd associated with
149 the current statement. */
150 for (section = abfd->sections;
151 section != (asection *)NULL;
152 section = section ->next)
158 /* Do the dirty work; an array of symbols for each new stub
160 syms = hppa_look_for_stubs_in_section (stub_file->the_bfd,
167 if (new_sym_cnt > 0 && syms)
169 struct symbol_cache_entry **old_asymbols;
171 old_asymbols = stub_file->asymbols;
173 /* Allocate space for the updated symbols */
175 = xmalloc ((stub_file->symbol_count + new_sym_cnt)
176 * sizeof(asymbol *));
177 if (stub_file->asymbols == NULL)
180 /* Copy the old symbols.
182 FIXME. Shouldn't we free the space used by the old
183 symbols here? Might there be dangling references
184 made within hppa_look_for_stubs_in_section? */
185 for (j = 0; j < stub_file->symbol_count; j++)
186 stub_file->asymbols[j] = old_asymbols[j];
188 /* Copy in the new symbols. */
189 for (j = 0, i = stub_file->symbol_count;
192 stub_file->asymbols[i] = &syms[j];
194 /* Finally, adjust the symbol count. */
195 stub_file->symbol_count += new_sym_cnt;
200 /* Add a statement to get the linker stubs included in the output. */
201 lang_add_wild (".hppa_linker_stubs",NULL);
203 /* If stubs were added, then remove all the (now invalid) padding
205 hppaelf_search_for_padding_statements (stat_ptr->head,
209 /* Size up the sections again. */
210 lang_size_sections (stat_ptr->head, abs_output_section,
211 &stat_ptr->head, 0, (bfd_vma) 0, false);
213 /* FIXME: Do we need to redo the "assignments" too? */
216 /* Create any emulation specific output statements. FIXME? Is this
217 redundant with above lang_add_wild or the code in the script? */
220 hppaelf_create_output_section_statements ()
223 asection *output_text_sec = bfd_make_section_old_way (output_bfd, ".text");
224 lang_input_section_type *new_input_sec;
226 /* Add a new "input file" (the linker stubs themselves). */
227 stub_file = lang_add_input_file ("linker stubs",
228 lang_input_file_is_fake_enum,
230 stub_file->the_bfd = bfd_create ("linker stubs", output_bfd);
231 stub_file->symbol_count = 0;
232 stub_file->the_bfd->sections = 0;
234 /* Add a section to the fake input file. */
235 stub_sec = bfd_make_section_old_way (stub_file->the_bfd,
236 ".hppa_linker_stubs");
237 stub_sec->output_section = output_text_sec;
238 bfd_set_section_flags (stub_file->the_bfd, stub_sec,
239 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_CODE | SEC_RELOC);
241 /* The user data of a bfd points to the input statement attached. */
242 stub_file->the_bfd->usrdata = (void *)stub_file;
243 stub_file->common_section = bfd_make_section(stub_file->the_bfd,"COMMON");
245 new_input_sec = (lang_input_section_type *)
246 stat_alloc (sizeof (lang_input_section_type));
250 lang_output_section_statement_type *text_output_sec;
251 lang_statement_union_type *stmt;
253 new_input_sec->section = stub_sec;
254 new_input_sec->ifile = stub_file;
255 new_input_sec->header.type = lang_input_section_enum;
256 new_input_sec->header.next = NULL;
258 stub_input_section = new_input_sec;
260 /* Find the output_section_statement for .text,
261 then find the wild_statement for .hppa_linker_stubs. */
262 text_output_sec = lang_output_section_find (".text");
264 stmt = text_output_sec->children.head;
266 while (stmt && stmt->header.type != lang_wild_statement_enum)
267 stmt = stmt->header.next;
269 /* Do something with the wild statement. FIXME. */
272 lang_wild_statement_type *wstmt = (lang_wild_statement_type *)stmt;
273 lang_list_init (&wstmt->children);
274 lang_statement_append (&wstmt->children,
275 (lang_statement_union_type *)new_input_sec,
276 &new_input_sec->header.next);
281 /* Set the output architecture and machine. */
284 hppaelf_set_output_arch()
286 unsigned long machine = 0;
288 bfd_set_arch_mach (output_bfd, ldfile_output_architecture, machine);
291 /* The script itself gets inserted here. */
294 hppaelf_get_script(isfile)
298 if test -n "$COMPILE_IN"
300 # Scripts compiled in.
302 # sed commands to quote an ld script as a C string.
309 cat >>em_${EMULATION_NAME}.c <<EOF
313 if (link_info.relocateable == true && config.build_constructors == true)
314 return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
315 else if (link_info.relocateable == true)
316 return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
317 else if (!config.text_read_only)
318 return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
319 else if (!config.magic_demand_paged)
320 return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
322 return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
327 # Scripts read from the filesystem.
329 cat >>em_${EMULATION_NAME}.c <<EOF
333 if (link_info.relocateable == true && config.build_constructors == true)
334 return "ldscripts/${EMULATION_NAME}.xu";
335 else if (link_info.relocateable == true)
336 return "ldscripts/${EMULATION_NAME}.xr";
337 else if (!config.text_read_only)
338 return "ldscripts/${EMULATION_NAME}.xbn";
339 else if (!config.magic_demand_paged)
340 return "ldscripts/${EMULATION_NAME}.xn";
342 return "ldscripts/${EMULATION_NAME}.x";
348 cat >>em_${EMULATION_NAME}.c <<EOF
350 struct ld_emulation_xfer_struct ld_hppaelf_emulation =
352 hppaelf_before_parse,
356 after_allocation_default,
357 hppaelf_set_output_arch,
358 ldemul_default_target,
359 before_allocation_default,
364 hppaelf_create_output_section_statements