* emultempl/elf32.em (gld${EMULATION_NAME}_check_ld_so_conf): Replace
[deliverable/binutils-gdb.git] / ld / emultempl / lnk960.em
CommitLineData
252b5132
RH
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
92b93329 3fragment <<EOF
252b5132 4/* intel coff loader emulation specific stuff
3db64b00 5 Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2003,
ff7a0acf 6 2005, 2007, 2008 Free Software Foundation, Inc.
252b5132
RH
7 Written by Steve Chamberlain steve@cygnus.com
8
f96b4a7b 9 This file is part of the GNU Binutils.
252b5132 10
f96b4a7b
NC
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
252b5132 15
f96b4a7b
NC
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
252b5132 20
f96b4a7b
NC
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 MA 02110-1301, USA. */
252b5132 25
3db64b00 26#include "sysdep.h"
252b5132
RH
27#include "libiberty.h"
28#include "bfd.h"
252b5132
RH
29#include "bfdlink.h"
30
31/*#include "archures.h"*/
32#include "ld.h"
b71e2778 33#include "ldmain.h"
252b5132
RH
34#include "ldmisc.h"
35#include "ldexp.h"
36#include "ldlang.h"
37#include "ldfile.h"
b71e2778 38#include "ldemul.h"
252b5132
RH
39
40typedef struct lib_list {
41 char *name;
42 struct lib_list *next;
43} lib_list_type;
44
45static lib_list_type *hll_list;
46static lib_list_type **hll_list_tail = &hll_list;
47
48static lib_list_type *syslib_list;
49static lib_list_type **syslib_list_tail = &syslib_list;
50
51
52static void
0c7a8e5a 53append (lib_list_type ***list, char *name)
252b5132 54{
b34976b6 55 lib_list_type *element = (lib_list_type *) xmalloc (sizeof (lib_list_type));
252b5132
RH
56
57 element->name = name;
b34976b6 58 element->next = (lib_list_type *) NULL;
252b5132
RH
59 **list = element;
60 *list = &element->next;
61
62}
63
b34976b6
AM
64static bfd_boolean had_hll = FALSE;
65static bfd_boolean had_hll_name = FALSE;
252b5132
RH
66
67static void
0c7a8e5a 68lnk960_hll (char *name)
252b5132 69{
b34976b6
AM
70 had_hll = TRUE;
71 if (name != (char *) NULL)
72 {
73 had_hll_name = TRUE;
74 append (&hll_list_tail, name);
75 }
252b5132
RH
76}
77
0c7a8e5a
AM
78static void
79lnk960_syslib (char *name)
252b5132 80{
b34976b6 81 append (&syslib_list_tail, name);
252b5132
RH
82}
83
84
0c7a8e5a
AM
85static void
86lnk960_before_parse (void)
252b5132 87{
b34976b6 88 char *name = getenv ("I960BASE");
252b5132 89
b34976b6
AM
90 if (name == (char *) NULL)
91 {
92 name = getenv("G960BASE");
93 if (name == (char *) NULL)
94 einfo ("%P%F I960BASE and G960BASE not set\n");
252b5132 95 }
252b5132 96
ff7a0acf 97 ldfile_add_library_path (concat (name, "/lib", (const char *) NULL), FALSE);
252b5132
RH
98 ldfile_output_architecture = bfd_arch_i960;
99 ldfile_output_machine = bfd_mach_i960_core;
100}
101
252b5132 102static void
0c7a8e5a 103add_on (lib_list_type *list, lang_input_file_enum_type search)
252b5132 104{
b34976b6
AM
105 while (list)
106 {
107 lang_add_input_file (list->name, search, (char *) NULL);
108 list = list->next;
109 }
252b5132 110}
0c7a8e5a 111
252b5132 112static void
0c7a8e5a 113lnk960_after_parse (void)
252b5132
RH
114{
115 /* If there has been no arch, default to -KB */
b34976b6
AM
116 if (ldfile_output_machine_name[0] == 0)
117 ldfile_add_arch ("KB");
252b5132
RH
118
119 /* if there has been no hll list then add our own */
0c7a8e5a 120
b34976b6
AM
121 if (had_hll && !had_hll_name)
122 {
123 append (&hll_list_tail, "cg");
124 if (ldfile_output_machine == bfd_mach_i960_ka_sa
125 || ldfile_output_machine == bfd_mach_i960_ca)
126 append (&hll_list_tail, "fpg");
252b5132 127 }
0c7a8e5a 128
b34976b6
AM
129 add_on (hll_list, lang_input_file_is_l_enum);
130 add_on (syslib_list, lang_input_file_is_search_file_enum);
252b5132
RH
131}
132
d2667025
AM
133/* Create a symbol with the given name with the value of the
134 address of first byte of the section named.
135
136 If the symbol already exists, then do nothing. */
137
138static void
139symbol_at_beginning_of (const char *secname, const char *name)
140{
141 struct bfd_link_hash_entry *h;
142
143 h = bfd_link_hash_lookup (link_info.hash, name, TRUE, TRUE, TRUE);
144 if (h == NULL)
145 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
146
147 if (h->type == bfd_link_hash_new
148 || h->type == bfd_link_hash_undefined)
149 {
150 asection *sec;
151
152 h->type = bfd_link_hash_defined;
153
154 sec = bfd_get_section_by_name (link_info.output_bfd, secname);
155 if (sec == NULL)
156 sec = bfd_abs_section_ptr;
157 h->u.def.value = 0;
158 h->u.def.section = sec;
159 }
160}
161
162/* Create a symbol with the given name with the value of the
163 address of the first byte after the end of the section named.
164
165 If the symbol already exists, then do nothing. */
166
167static void
168symbol_at_end_of (const char *secname, const char *name)
169{
170 struct bfd_link_hash_entry *h;
171
172 h = bfd_link_hash_lookup (link_info.hash, name, TRUE, TRUE, TRUE);
173 if (h == NULL)
174 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
175
176 if (h->type == bfd_link_hash_new
177 || h->type == bfd_link_hash_undefined)
178 {
179 asection *sec;
180
181 h->type = bfd_link_hash_defined;
182
183 sec = bfd_get_section_by_name (link_info.output_bfd, secname);
184 if (sec == NULL)
185 sec = bfd_abs_section_ptr;
186 h->u.def.value = sec->size;
187 h->u.def.section = sec;
188 }
189}
190
252b5132 191static void
0c7a8e5a 192lnk960_after_allocation (void)
252b5132 193{
1049f94e 194 if (!link_info.relocatable)
b34976b6 195 {
d2667025
AM
196 symbol_at_end_of (".text", "_etext");
197 symbol_at_end_of (".data", "_edata");
198 symbol_at_beginning_of (".bss", "_bss_start");
199 symbol_at_end_of (".bss", "_end");
b34976b6 200 }
252b5132
RH
201}
202
203
204static struct
205 {
206 unsigned long number;
0c7a8e5a 207 char *name;
252b5132
RH
208 }
209machine_table[] =
210{
211 { bfd_mach_i960_core ,"CORE" },
212 { bfd_mach_i960_kb_sb ,"KB" },
213 { bfd_mach_i960_kb_sb ,"SB" },
214 { bfd_mach_i960_mc ,"MC" },
215 { bfd_mach_i960_xa ,"XA" },
216 { bfd_mach_i960_ca ,"CA" },
217 { bfd_mach_i960_ka_sa ,"KA" },
218 { bfd_mach_i960_ka_sa ,"SA" },
219 { bfd_mach_i960_jx ,"JX" },
220 { bfd_mach_i960_hx ,"HX" },
221
222 { bfd_mach_i960_core ,"core" },
223 { bfd_mach_i960_kb_sb ,"kb" },
224 { bfd_mach_i960_kb_sb ,"sb" },
225 { bfd_mach_i960_mc ,"mc" },
226 { bfd_mach_i960_xa ,"xa" },
227 { bfd_mach_i960_ca ,"ca" },
228 { bfd_mach_i960_ka_sa ,"ka" },
229 { bfd_mach_i960_ka_sa ,"sa" },
230 { bfd_mach_i960_jx ,"jx" },
231 { bfd_mach_i960_hx ,"hx" },
232
233 { 0, (char *) NULL }
234};
235
236static void
0c7a8e5a 237lnk960_set_output_arch (void)
252b5132
RH
238{
239 /* Set the output architecture and machine if possible */
240 unsigned int i;
241 ldfile_output_machine = bfd_mach_i960_core;
b34976b6
AM
242 for (i= 0; machine_table[i].name != (char*) NULL; i++)
243 {
244 if (strcmp (ldfile_output_machine_name, machine_table[i].name) == 0)
245 {
246 ldfile_output_machine = machine_table[i].number;
247 break;
248 }
252b5132 249 }
f13a99db 250 bfd_set_arch_mach (link_info.output_bfd, ldfile_output_architecture,
b34976b6 251 ldfile_output_machine);
252b5132
RH
252}
253
254static char *
0c7a8e5a 255lnk960_choose_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
252b5132 256{
b34976b6
AM
257 char *from_outside = getenv (TARGET_ENVIRON);
258 if (from_outside != (char *) NULL)
252b5132
RH
259 return from_outside;
260#ifdef LNK960_LITTLE
261 return "coff-Intel-little";
262#else
263 return "coff-Intel-big";
264#endif
252b5132
RH
265}
266
267static char *
0c7a8e5a 268lnk960_get_script (int *isfile)
252b5132
RH
269EOF
270
271if test -n "$COMPILE_IN"
272then
273# Scripts compiled in.
274
275# sed commands to quote an ld script as a C string.
597e2591 276sc="-f stringify.sed"
252b5132 277
92b93329 278fragment <<EOF
0c7a8e5a 279{
252b5132
RH
280 *isfile = 0;
281
1049f94e 282 if (link_info.relocatable && config.build_constructors)
597e2591 283 return
252b5132 284EOF
b34976b6 285sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1049f94e 286echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
b34976b6
AM
287sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
288echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
289sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
290echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
291sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
292echo ' ; else return' >> e${EMULATION_NAME}.c
293sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
294echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
295
296else
297# Scripts read from the filesystem.
298
92b93329 299fragment <<EOF
0c7a8e5a 300{
252b5132
RH
301 *isfile = 1;
302
1049f94e 303 if (link_info.relocatable && config.build_constructors)
252b5132 304 return "ldscripts/${EMULATION_NAME}.xu";
1049f94e 305 else if (link_info.relocatable)
252b5132
RH
306 return "ldscripts/${EMULATION_NAME}.xr";
307 else if (!config.text_read_only)
308 return "ldscripts/${EMULATION_NAME}.xbn";
309 else if (!config.magic_demand_paged)
310 return "ldscripts/${EMULATION_NAME}.xn";
311 else
312 return "ldscripts/${EMULATION_NAME}.x";
313}
314EOF
315
316fi
317
92b93329 318fragment <<EOF
252b5132 319
0c7a8e5a 320struct ld_emulation_xfer_struct ld_lnk960_emulation =
252b5132
RH
321{
322 lnk960_before_parse,
323 lnk960_syslib,
324 lnk960_hll,
325 lnk960_after_parse,
5c3049d2 326 after_open_default,
252b5132
RH
327 lnk960_after_allocation,
328 lnk960_set_output_arch,
329 lnk960_choose_target,
8423293d 330 before_allocation_default,
252b5132
RH
331 lnk960_get_script,
332 "lnk960",
e1c47aa4 333 "",
1e035701 334 finish_default,
e1c47aa4
AM
335 NULL, /* create output section statements */
336 NULL, /* open dynamic archive */
337 NULL, /* place orphan */
338 NULL, /* set symbols */
339 NULL, /* parse args */
3bcf5557
AM
340 NULL, /* add_options */
341 NULL, /* handle_option */
e1c47aa4
AM
342 NULL, /* unrecognized file */
343 NULL, /* list options */
40d109bf 344 NULL, /* recognized file */
fac1652d
AM
345 NULL, /* find_potential_libraries */
346 NULL /* new_vers_pattern */
252b5132
RH
347};
348EOF
This page took 0.528838 seconds and 4 git commands to generate.