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