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 OSF/1 linkers.
5 Copyright (C) 1991, 1993 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
38 static void hppaosf_before_parse()
40 link_info.lprefix = "L$";
41 link_info.lprefix_len = 2;
43 ldfile_output_architecture = bfd_arch_hppa;
46 static lang_input_statement_type *stub_file = 0;
48 static lang_input_section_type *stub_input_section = NULL;
51 hppaosf_search_for_padding_statements(s,prev)
52 lang_statement_union_type *s;
53 lang_statement_union_type **prev;
55 lang_statement_union_type *sprev = NULL;
56 for (; s != (lang_statement_union_type *) NULL; s = s->next)
58 switch (s->header.type)
60 case lang_constructors_statement_enum:
61 hppaosf_search_for_padding_statements (constructor_list.head,&constructor_list.head);
63 case lang_output_section_statement_enum:
64 hppaosf_search_for_padding_statements
65 (s->output_section_statement.children.head,&s->output_section_statement.children.head);
67 case lang_wild_statement_enum:
68 hppaosf_search_for_padding_statements
69 (s->wild_statement.children.head,&s->wild_statement.children.head);
71 case lang_data_statement_enum:
72 case lang_object_symbols_statement_enum:
73 case lang_output_statement_enum:
74 case lang_target_statement_enum:
75 case lang_input_section_enum:
76 case lang_input_statement_enum:
77 case lang_assignment_statement_enum:
78 case lang_address_statement_enum:
80 case lang_padding_statement_enum:
83 sprev->header.next = s->header.next;
101 extern asymbol *hppa_look_for_stubs_in_section();
103 if (link_info.relocateable == false)
105 /* check for needed stubs */
106 extern lang_statement_list_type file_chain;
107 lang_input_statement_type *statement;
109 for (statement = (lang_input_statement_type *)file_chain.head;
110 statement != (lang_input_statement_type *)NULL;
111 statement = (lang_input_statement_type *)statement->next)
114 bfd *abfd = statement->the_bfd;
115 for (section = abfd->sections;
116 section != (asection *)NULL;
117 section = section ->next)
123 syms = hppa_look_for_stubs_in_section (stub_file->the_bfd,
131 if ( (new_sym_cnt > 0) && syms )
133 struct symbol_cache_entry **old_asymbols;
135 old_asymbols = stub_file->asymbols;
137 stub_file->asymbols = xmalloc((stub_file->symbol_count + new_sym_cnt) * sizeof(asymbol *));
139 for ( j = 0; j < stub_file->symbol_count; j++ )
140 stub_file->asymbols[j] = old_asymbols[j];
142 for ( j = 0, i = stub_file->symbol_count; j < new_sym_cnt; j++, i++ )
143 stub_file->asymbols[i] = &syms[j];
145 stub_file->symbol_count += new_sym_cnt;
149 /* Add a statement to get the linker stubs included in the output */
150 lang_add_wild(".hppa_linker_stubs",NULL);
152 /* If we've added stubs,remove the padding_statements because */
153 /* they are no longer valid */
154 hppaosf_search_for_padding_statements(stat_ptr->head,&(stat_ptr->head));
159 hppaosf_create_output_section_statements()
162 asection *output_text_sec = bfd_make_section_old_way(output_bfd,".text");
163 lang_input_section_type *new_input_sec;
165 stub_file = lang_add_input_file ("linker stubs",
166 lang_input_file_is_fake_enum,
168 stub_file->the_bfd = bfd_create ("linker stubs", output_bfd);
169 stub_file->symbol_count = 0;
170 stub_file->the_bfd->sections = 0;
172 stub_sec = bfd_make_section_old_way(stub_file->the_bfd,".hppa_linker_stubs");
173 stub_sec->output_section = output_text_sec;
174 bfd_set_section_flags(stub_file->the_bfd, stub_sec, SEC_HAS_CONTENTS | SEC_ALLOC | SEC_CODE | SEC_RELOC );
176 /* The user data of a bfd points to the input statement attached */
177 stub_file->the_bfd->usrdata = (void *)stub_file;
178 stub_file->common_section =
179 bfd_make_section(stub_file->the_bfd,"COMMON");
181 new_input_sec = (lang_input_section_type *)stat_alloc(sizeof(lang_input_section_type));
184 lang_output_section_statement_type *text_output_sec;
185 lang_statement_union_type *stmt;
186 lang_wild_statement_type *stub_statement;
187 new_input_sec->section = stub_sec;
188 new_input_sec->ifile = stub_file;
189 new_input_sec->header.type = lang_input_section_enum;
190 new_input_sec->header.next = NULL;
192 stub_input_section = new_input_sec;
194 /* Find the output_section_statement for .text, */
195 /* then find the wild_statement for .hppa_linker_stubs */
197 text_output_sec = lang_output_section_find(".text");
199 stmt = text_output_sec->children.head;
201 while (stmt && stmt->header.type != lang_wild_statement_enum)
203 stmt = stmt->header.next;
208 lang_wild_statement_type *wstmt = (lang_wild_statement_type *)stmt;
209 lang_list_init(&wstmt->children);
210 lang_statement_append(&wstmt->children,
211 (lang_statement_union_type *)new_input_sec,
212 &new_input_sec->header.next);
218 hppaosf_set_output_arch()
220 /* Set the output architecture and machine if possible */
221 unsigned long machine = 0;
222 bfd_set_arch_mach(output_bfd, ldfile_output_architecture, machine);
226 hppaosf_get_script(isfile)
230 if test -n "$COMPILE_IN"
232 # Scripts compiled in.
234 # sed commands to quote an ld script as a C string.
241 cat >>em_${EMULATION_NAME}.c <<EOF
245 if (link_info.relocateable == true && config.build_constructors == true)
246 return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
247 else if (link_info.relocateable == true)
248 return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
249 else if (!config.text_read_only)
250 return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
251 else if (!config.magic_demand_paged)
252 return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
254 return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
259 # Scripts read from the filesystem.
261 cat >>em_${EMULATION_NAME}.c <<EOF
265 if (link_info.relocateable == true && config.build_constructors == true)
266 return "ldscripts/${EMULATION_NAME}.xu";
267 else if (link_info.relocateable == true)
268 return "ldscripts/${EMULATION_NAME}.xr";
269 else if (!config.text_read_only)
270 return "ldscripts/${EMULATION_NAME}.xbn";
271 else if (!config.magic_demand_paged)
272 return "ldscripts/${EMULATION_NAME}.xn";
274 return "ldscripts/${EMULATION_NAME}.x";
280 cat >>em_${EMULATION_NAME}.c <<EOF
282 struct ld_emulation_xfer_struct ld_hppaosf_emulation =
284 hppaosf_before_parse,
288 after_allocation_default,
289 hppaosf_set_output_arch,
290 ldemul_default_target,
291 before_allocation_default,
296 hppaosf_create_output_section_statements