1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 cat >e${EMULATION_NAME}.c <<EOF
4 /* An emulation for HP PA-RISC ELF linkers.
5 Copyright (C) 1991, 93, 94, 95, 1997 Free Software Foundation, Inc.
6 Written by Steve Chamberlain steve@cygnus.com
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
37 /* Section in which we build stubs. */
38 static asection *stub_sec;
39 static lang_input_statement_type *stub_file;
42 /* FIXME. This doesn't belong here. */
43 extern lang_statement_list_type file_chain;
45 /* Perform some emulation specific initialization. For PA ELF we set
46 up the local label prefix and the output architecture. */
49 hppaelf_before_parse ()
51 ldfile_output_architecture = bfd_arch_hppa;
54 /* Set the output architecture and machine. */
57 hppaelf_set_output_arch()
59 unsigned long machine = 0;
61 bfd_set_arch_mach (output_bfd, ldfile_output_architecture, machine);
64 /* This is called before the input files are opened. We create a new
65 fake input file to hold the stub section. */
68 hppaelf_create_output_section_statements ()
70 stub_file = lang_add_input_file ("linker stubs",
71 lang_input_file_is_fake_enum,
73 stub_file->the_bfd = bfd_create ("linker stubs", output_bfd);
74 if (stub_file->the_bfd == NULL
75 || ! bfd_set_arch_mach (stub_file->the_bfd,
76 bfd_get_arch (output_bfd),
77 bfd_get_mach (output_bfd)))
79 einfo ("%X%P: can not create BFD %E\n");
83 stub_sec = bfd_make_section_old_way (stub_file->the_bfd, ".text");
84 /* Don't set SEC_RELOC until we actually have relocations in this
87 || ! bfd_set_section_flags (stub_file->the_bfd, stub_sec,
94 einfo ("%X%P: can not create stub section: %E\n");
98 ldlang_add_file (stub_file);
101 /* Walk all the lang statements splicing out any padding statements from
105 hppaelf_delete_padding_statements (s, prev)
106 lang_statement_union_type *s;
107 lang_statement_union_type **prev;
109 lang_statement_union_type *sprev = NULL;
110 for (; s != NULL; s = s->next)
112 switch (s->header.type)
115 /* We want recursively walk these sections. */
116 case lang_constructors_statement_enum:
117 hppaelf_delete_padding_statements (constructor_list.head,
118 &constructor_list.head);
121 case lang_output_section_statement_enum:
122 hppaelf_delete_padding_statements (s->output_section_statement.
124 &s->output_section_statement.
128 /* Huh? What is a lang_wild_statement? */
129 case lang_wild_statement_enum:
130 hppaelf_delete_padding_statements (s->wild_statement.
136 /* Here's what we are really looking for. Splice these out of
138 case lang_padding_statement_enum:
140 sprev->header.next = s->header.next;
145 /* We don't care about these cases. */
146 case lang_data_statement_enum:
147 case lang_object_symbols_statement_enum:
148 case lang_output_statement_enum:
149 case lang_target_statement_enum:
150 case lang_input_section_enum:
151 case lang_input_statement_enum:
152 case lang_assignment_statement_enum:
153 case lang_address_statement_enum:
164 /* Final emulation specific call. For the PA we use this opportunity
165 to build linker stubs. */
170 /* Call into the BFD backend to do the real work. */
171 if (elf32_hppa_size_stubs (stub_file->the_bfd, output_bfd, &link_info)
174 einfo ("%X%P: can not size stub section: %E\n");
178 /* If the size of the stub section is nonzero, then we need
179 to resize the sections, recompute the assignments, and finally
181 if (bfd_section_size (stub_file->the_bfd, stub_file->the_bfd->sections) != 0)
183 /* Delete all the padding statements, they're no longer valid. */
184 hppaelf_delete_padding_statements (stat_ptr->head, &stat_ptr->head);
186 /* Resize the sections. */
187 lang_size_sections (stat_ptr->head, abs_output_section,
188 &stat_ptr->head, 0, (bfd_vma) 0, false);
190 /* Redo special stuff. */
191 ldemul_after_allocation ();
193 /* Do the assignments again. */
194 lang_do_assignments (stat_ptr->head,
196 (fill_type) 0, (bfd_vma) 0);
198 /* Now build the linker stubs. */
199 if (elf32_hppa_build_stubs (stub_file->the_bfd, &link_info) == false)
201 einfo ("%X%P: can not build stubs: %E\n");
207 /* The script itself gets inserted here. */
210 hppaelf_get_script(isfile)
214 if test -n "$COMPILE_IN"
216 # Scripts compiled in.
218 # sed commands to quote an ld script as a C string.
225 cat >>e${EMULATION_NAME}.c <<EOF
229 if (link_info.relocateable == true && config.build_constructors == true)
230 return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
231 else if (link_info.relocateable == true)
232 return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
233 else if (!config.text_read_only)
234 return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
235 else if (!config.magic_demand_paged)
236 return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
238 return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
243 # Scripts read from the filesystem.
245 cat >>e${EMULATION_NAME}.c <<EOF
249 if (link_info.relocateable == true && config.build_constructors == true)
250 return "ldscripts/${EMULATION_NAME}.xu";
251 else if (link_info.relocateable == true)
252 return "ldscripts/${EMULATION_NAME}.xr";
253 else if (!config.text_read_only)
254 return "ldscripts/${EMULATION_NAME}.xbn";
255 else if (!config.magic_demand_paged)
256 return "ldscripts/${EMULATION_NAME}.xn";
258 return "ldscripts/${EMULATION_NAME}.x";
264 cat >>e${EMULATION_NAME}.c <<EOF
266 struct ld_emulation_xfer_struct ld_hppaelf_emulation =
268 hppaelf_before_parse,
273 after_allocation_default,
274 hppaelf_set_output_arch,
275 ldemul_default_target,
276 before_allocation_default,
281 hppaelf_create_output_section_statements,