Don't try to read past end of info buffer, and correct test results.
[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.
3cat >e${EMULATION_NAME}.c <<EOF
4/* intel coff loader emulation specific stuff
a2b64bed 5 Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000
b71e2778 6 Free Software Foundation, Inc.
252b5132
RH
7 Written by Steve Chamberlain steve@cygnus.com
8
9This file is part of GLD, the Gnu Linker.
10
11GLD is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2, or (at your option)
14any later version.
15
16GLD is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with GLD; see the file COPYING. If not, write to
23the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24
25#include "libiberty.h"
26#include "bfd.h"
27#include "sysdep.h"
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
52append(list, name)
53 lib_list_type ***list;
54 char *name;
55{
56 lib_list_type *element =
57 (lib_list_type *)(xmalloc(sizeof(lib_list_type)));
58
59 element->name = name;
60 element->next = (lib_list_type *)NULL;
61 **list = element;
62 *list = &element->next;
63
64}
65
66static boolean had_hll = false;
67static boolean had_hll_name = false;
68
69static void
70lnk960_hll(name)
71 char *name;
72{
73 had_hll = true;
74 if (name != (char *)NULL) {
75 had_hll_name = true;
76 append(&hll_list_tail, name);
77 }
78}
79
80static void
81lnk960_syslib(name)
82 char *name;
83{
84 append(&syslib_list_tail,name);
85}
86
87
88#ifdef GNU960
89
90static void
91lnk960_before_parse()
92{
93 static char *env_variables[] = { "G960LIB", "G960BASE", 0 };
94 char **p;
95 char *env ;
96
97 for ( p = env_variables; *p; p++ ){
98 env = (char *) getenv(*p);
99 if (env) {
100 ldfile_add_library_path(concat(env,"/lib/libcoff",""), false);
101 }
102 }
103
104 env= (char *) getenv("I960BASE");
105 if ( env ) {
106 ldfile_add_library_path(concat(env,"/lib",""), false);
107 }
108
109 ldfile_output_architecture = bfd_arch_i960;
110 ldfile_output_machine = bfd_mach_i960_core;
111}
112
113#else /* not GNU960 */
114
115static void
116lnk960_before_parse()
117{
118 char *name = getenv("I960BASE");
119
120 if (name == (char *)NULL) {
121 name = getenv("G960BASE");
122 if (name == (char *)NULL) {
123 einfo("%P%F I960BASE and G960BASE not set\n");
124 }
125 }
126
127
128 ldfile_add_library_path(concat(name,"/lib",""), false);
129 ldfile_output_architecture = bfd_arch_i960;
130 ldfile_output_machine = bfd_mach_i960_core;
131}
132
133#endif /* GNU960 */
134
135
136static void
137add_on(list, search)
138 lib_list_type *list;
139 lang_input_file_enum_type search;
140{
141 while (list) {
142 lang_add_input_file(list->name,
143 search,
144 (char *)NULL);
145 list = list->next;
146 }
147}
148static void
149lnk960_after_parse()
150{
151 /* If there has been no arch, default to -KB */
152 if (ldfile_output_machine_name[0] ==0) {
153 ldfile_add_arch("KB");
154 }
155
156 /* if there has been no hll list then add our own */
157
158 if(had_hll && !had_hll_name) {
159 append(&hll_list_tail,"cg");
160 if (ldfile_output_machine == bfd_mach_i960_ka_sa ||
161 ldfile_output_machine == bfd_mach_i960_ca) {
162 {
163 append(&hll_list_tail,"fpg");
164 }
165 }
166 }
167
168 add_on(hll_list, lang_input_file_is_l_enum);
169 add_on(syslib_list, lang_input_file_is_search_file_enum);
170}
171
172static void
173lnk960_before_allocation()
174{
175}
176
177static void
178lnk960_after_allocation()
179{
180 if (link_info.relocateable == false) {
181 lang_abs_symbol_at_end_of(".text","_etext");
182 lang_abs_symbol_at_end_of(".data","_edata");
183 lang_abs_symbol_at_beginning_of(".bss","_bss_start");
184 lang_abs_symbol_at_end_of(".bss","_end");
185 }
186}
187
188
189static struct
190 {
191 unsigned long number;
192 char *name;
193 }
194machine_table[] =
195{
196 { bfd_mach_i960_core ,"CORE" },
197 { bfd_mach_i960_kb_sb ,"KB" },
198 { bfd_mach_i960_kb_sb ,"SB" },
199 { bfd_mach_i960_mc ,"MC" },
200 { bfd_mach_i960_xa ,"XA" },
201 { bfd_mach_i960_ca ,"CA" },
202 { bfd_mach_i960_ka_sa ,"KA" },
203 { bfd_mach_i960_ka_sa ,"SA" },
204 { bfd_mach_i960_jx ,"JX" },
205 { bfd_mach_i960_hx ,"HX" },
206
207 { bfd_mach_i960_core ,"core" },
208 { bfd_mach_i960_kb_sb ,"kb" },
209 { bfd_mach_i960_kb_sb ,"sb" },
210 { bfd_mach_i960_mc ,"mc" },
211 { bfd_mach_i960_xa ,"xa" },
212 { bfd_mach_i960_ca ,"ca" },
213 { bfd_mach_i960_ka_sa ,"ka" },
214 { bfd_mach_i960_ka_sa ,"sa" },
215 { bfd_mach_i960_jx ,"jx" },
216 { bfd_mach_i960_hx ,"hx" },
217
218 { 0, (char *) NULL }
219};
220
221static void
222lnk960_set_output_arch()
223{
224 /* Set the output architecture and machine if possible */
225 unsigned int i;
226 ldfile_output_machine = bfd_mach_i960_core;
227 for (i= 0; machine_table[i].name != (char*)NULL; i++) {
228 if (strcmp(ldfile_output_machine_name,machine_table[i].name)==0) {
229 ldfile_output_machine = machine_table[i].number;
230 break;
231 }
232 }
233 bfd_set_arch_mach(output_bfd, ldfile_output_architecture, ldfile_output_machine);
234}
235
236static char *
237lnk960_choose_target()
238{
239#ifdef GNU960
240
241 return bfd_make_targ_name(BFD_COFF_FORMAT, 0);
242
243#else
244
245 char *from_outside = getenv(TARGET_ENVIRON);
246 if (from_outside != (char *)NULL)
247 return from_outside;
248#ifdef LNK960_LITTLE
249 return "coff-Intel-little";
250#else
251 return "coff-Intel-big";
252#endif
253#endif
254
255}
256
257static char *
258lnk960_get_script(isfile)
259 int *isfile;
260EOF
261
262if test -n "$COMPILE_IN"
263then
264# Scripts compiled in.
265
266# sed commands to quote an ld script as a C string.
597e2591 267sc="-f stringify.sed"
252b5132
RH
268
269cat >>e${EMULATION_NAME}.c <<EOF
597e2591 270{
252b5132
RH
271 *isfile = 0;
272
273 if (link_info.relocateable == true && config.build_constructors == true)
597e2591 274 return
252b5132 275EOF
597e2591
ILT
276sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
277echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
278sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
279echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
280sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
281echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
282sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
283echo ' ; else return' >> e${EMULATION_NAME}.c
284sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
285echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
286
287else
288# Scripts read from the filesystem.
289
290cat >>e${EMULATION_NAME}.c <<EOF
291{
292 *isfile = 1;
293
294 if (link_info.relocateable == true && config.build_constructors == true)
295 return "ldscripts/${EMULATION_NAME}.xu";
296 else if (link_info.relocateable == true)
297 return "ldscripts/${EMULATION_NAME}.xr";
298 else if (!config.text_read_only)
299 return "ldscripts/${EMULATION_NAME}.xbn";
300 else if (!config.magic_demand_paged)
301 return "ldscripts/${EMULATION_NAME}.xn";
302 else
303 return "ldscripts/${EMULATION_NAME}.x";
304}
305EOF
306
307fi
308
309cat >>e${EMULATION_NAME}.c <<EOF
310
311struct ld_emulation_xfer_struct ld_lnk960_emulation =
312{
313 lnk960_before_parse,
314 lnk960_syslib,
315 lnk960_hll,
316 lnk960_after_parse,
317 NULL, /* after_open */
318 lnk960_after_allocation,
319 lnk960_set_output_arch,
320 lnk960_choose_target,
321 lnk960_before_allocation,
322 lnk960_get_script,
323 "lnk960",
e1c47aa4
AM
324 "",
325 NULL, /* finish */
326 NULL, /* create output section statements */
327 NULL, /* open dynamic archive */
328 NULL, /* place orphan */
329 NULL, /* set symbols */
330 NULL, /* parse args */
331 NULL, /* unrecognized file */
332 NULL, /* list options */
40d109bf
AM
333 NULL, /* recognized file */
334 NULL /* find_potential_libraries */
252b5132
RH
335};
336EOF
This page took 0.265907 seconds and 4 git commands to generate.