cb01a321e4464d503c45b0cc586c2cc44a0acfb3
[deliverable/binutils-gdb.git] / ld / emultempl / hppaelf.em
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
7
8 This file is part of GLD, the Gnu Linker.
9
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.
14
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.
19
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. */
23
24 #include "bfd.h"
25 #include "sysdep.h"
26 #include "bfdlink.h"
27
28 #include "ld.h"
29 #include "config.h"
30 #include "ldemul.h"
31 #include "ldfile.h"
32 #include "ldexp.h"
33 #include "ldlang.h"
34 #include "ldmisc.h"
35 #include "ldmain.h"
36 #include "ldctor.h"
37
38 static void hppaosf_before_parse()
39 {
40 link_info.lprefix = "L$";
41 link_info.lprefix_len = 2;
42
43 ldfile_output_architecture = bfd_arch_hppa;
44 }
45
46 static lang_input_statement_type *stub_file = 0;
47
48 static lang_input_section_type *stub_input_section = NULL;
49
50 static void
51 hppaosf_search_for_padding_statements(s,prev)
52 lang_statement_union_type *s;
53 lang_statement_union_type **prev;
54 {
55 lang_statement_union_type *sprev = NULL;
56 for (; s != (lang_statement_union_type *) NULL; s = s->next)
57 {
58 switch (s->header.type)
59 {
60 case lang_constructors_statement_enum:
61 hppaosf_search_for_padding_statements (constructor_list.head,&constructor_list.head);
62 break;
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);
66 break;
67 case lang_wild_statement_enum:
68 hppaosf_search_for_padding_statements
69 (s->wild_statement.children.head,&s->wild_statement.children.head);
70 break;
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:
79 break;
80 case lang_padding_statement_enum:
81 if ( sprev )
82 {
83 sprev->header.next = s->header.next;
84 }
85 else
86 {
87 **prev = *s;
88 }
89 break;
90 default:
91 FAIL ();
92 break;
93 }
94 sprev = s;
95 }
96 }
97
98 static void
99 hppaosf_finish()
100 {
101 extern asymbol *hppa_look_for_stubs_in_section();
102
103 if (link_info.relocateable == false)
104 {
105 /* check for needed stubs */
106 extern lang_statement_list_type file_chain;
107 lang_input_statement_type *statement;
108
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)
112 {
113 asection *section;
114 bfd *abfd = statement->the_bfd;
115 for (section = abfd->sections;
116 section != (asection *)NULL;
117 section = section ->next)
118 {
119 int new_sym_cnt = 0;
120 int i,j;
121 asymbol *syms;
122
123 syms = hppa_look_for_stubs_in_section (stub_file->the_bfd,
124 abfd,
125 output_bfd,
126 section,
127 statement->asymbols,
128 &new_sym_cnt,
129 &link_info);
130
131 if ( (new_sym_cnt > 0) && syms )
132 {
133 struct symbol_cache_entry **old_asymbols;
134
135 old_asymbols = stub_file->asymbols;
136
137 stub_file->asymbols = xmalloc((stub_file->symbol_count + new_sym_cnt) * sizeof(asymbol *));
138
139 for ( j = 0; j < stub_file->symbol_count; j++ )
140 stub_file->asymbols[j] = old_asymbols[j];
141
142 for ( j = 0, i = stub_file->symbol_count; j < new_sym_cnt; j++, i++ )
143 stub_file->asymbols[i] = &syms[j];
144
145 stub_file->symbol_count += new_sym_cnt;
146 }
147 }
148 }
149 /* Add a statement to get the linker stubs included in the output */
150 lang_add_wild(".hppa_linker_stubs",NULL);
151
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));
155 }
156 }
157
158 static void
159 hppaosf_create_output_section_statements()
160 {
161 asection *stub_sec;
162 asection *output_text_sec = bfd_make_section_old_way(output_bfd,".text");
163 lang_input_section_type *new_input_sec;
164
165 stub_file = lang_add_input_file ("linker stubs",
166 lang_input_file_is_fake_enum,
167 (char *) NULL);
168 stub_file->the_bfd = bfd_create ("linker stubs", output_bfd);
169 stub_file->symbol_count = 0;
170 stub_file->the_bfd->sections = 0;
171
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 );
175
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");
180
181 new_input_sec = (lang_input_section_type *)stat_alloc(sizeof(lang_input_section_type));
182 if ( new_input_sec )
183 {
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;
191
192 stub_input_section = new_input_sec;
193
194 /* Find the output_section_statement for .text, */
195 /* then find the wild_statement for .hppa_linker_stubs */
196
197 text_output_sec = lang_output_section_find(".text");
198
199 stmt = text_output_sec->children.head;
200
201 while (stmt && stmt->header.type != lang_wild_statement_enum)
202 {
203 stmt = stmt->header.next;
204 }
205
206 if ( stmt )
207 {
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);
213 }
214 }
215 }
216
217 static void
218 hppaosf_set_output_arch()
219 {
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);
223 }
224
225 static char *
226 hppaosf_get_script(isfile)
227 int *isfile;
228 EOF
229
230 if test -n "$COMPILE_IN"
231 then
232 # Scripts compiled in.
233
234 # sed commands to quote an ld script as a C string.
235 sc='s/["\\]/\\&/g
236 s/$/\\n\\/
237 1s/^/"{/
238 $s/$/n}"/
239 '
240
241 cat >>em_${EMULATION_NAME}.c <<EOF
242 {
243 *isfile = 0;
244
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`;
253 else
254 return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
255 }
256 EOF
257
258 else
259 # Scripts read from the filesystem.
260
261 cat >>em_${EMULATION_NAME}.c <<EOF
262 {
263 *isfile = 1;
264
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";
273 else
274 return "ldscripts/${EMULATION_NAME}.x";
275 }
276 EOF
277
278 fi
279
280 cat >>em_${EMULATION_NAME}.c <<EOF
281
282 struct ld_emulation_xfer_struct ld_hppaosf_emulation =
283 {
284 hppaosf_before_parse,
285 syslib_default,
286 hll_default,
287 after_parse_default,
288 after_allocation_default,
289 hppaosf_set_output_arch,
290 ldemul_default_target,
291 before_allocation_default,
292 hppaosf_get_script,
293 "hppaosf",
294 "elf32-hppa",
295 hppaosf_finish,
296 hppaosf_create_output_section_statements
297 };
298 EOF
This page took 0.068261 seconds and 4 git commands to generate.