Commit | Line | Data |
---|---|---|
57fc1e90 ILT |
1 | # This shell script emits a C file. -*- C -*- |
2 | # It does some substitutions. | |
3 | cat >e${EMULATION_NAME}.c <<EOF | |
4 | /* This file is is generated by a shell script. DO NOT EDIT! */ | |
5 | ||
6 | /* AIX emulation code for ${EMULATION_NAME} | |
7 | Copyright (C) 1991, 1993, 1995 Free Software Foundation, Inc. | |
8 | Written by Steve Chamberlain <sac@cygnus.com> | |
9 | AIX support by Ian Lance Taylor <ian@cygnus.com> | |
10 | ||
11 | This file is part of GLD, the Gnu Linker. | |
12 | ||
13 | This program is free software; you can redistribute it and/or modify | |
14 | it under the terms of the GNU General Public License as published by | |
15 | the Free Software Foundation; either version 2 of the License, or | |
16 | (at your option) any later version. | |
17 | ||
18 | This program is distributed in the hope that it will be useful, | |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | GNU General Public License for more details. | |
22 | ||
23 | You should have received a copy of the GNU General Public License | |
24 | along with this program; if not, write to the Free Software | |
25 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
26 | ||
27 | #define TARGET_IS_${EMULATION_NAME} | |
28 | ||
29 | #include "bfd.h" | |
30 | #include "sysdep.h" | |
31 | #include "libiberty.h" | |
32 | #include "getopt.h" | |
33 | #include "bfdlink.h" | |
34 | ||
35 | #include <ctype.h> | |
36 | ||
37 | #include "ld.h" | |
38 | #include "ldmain.h" | |
39 | #include "ldemul.h" | |
40 | #include "ldfile.h" | |
41 | #include "ldmisc.h" | |
42 | #include "ldexp.h" | |
43 | #include "ldlang.h" | |
cf79773c | 44 | #include "ldctor.h" |
57fc1e90 ILT |
45 | |
46 | static void gld${EMULATION_NAME}_before_parse PARAMS ((void)); | |
47 | static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **)); | |
cf79773c | 48 | static void gld${EMULATION_NAME}_after_open PARAMS ((void)); |
57fc1e90 ILT |
49 | static void gld${EMULATION_NAME}_before_allocation PARAMS ((void)); |
50 | static void gld${EMULATION_NAME}_read_file PARAMS ((const char *, boolean)); | |
51 | static void gld${EMULATION_NAME}_free PARAMS ((PTR)); | |
cf79773c ILT |
52 | static void gld${EMULATION_NAME}_find_relocs |
53 | PARAMS ((lang_statement_union_type *)); | |
54 | static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *)); | |
57fc1e90 ILT |
55 | static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile)); |
56 | ||
57 | /* The file alignment required for each section. */ | |
58 | static unsigned long file_align; | |
59 | ||
60 | /* The maximum size the stack is permitted to grow. This is stored in | |
61 | the a.out header. */ | |
62 | static unsigned long maxstack; | |
63 | ||
64 | /* The maximum data size. This is stored in the a.out header. */ | |
65 | static unsigned long maxdata; | |
66 | ||
67 | /* Whether to perform garbage collection. */ | |
68 | static int gc = 1; | |
69 | ||
70 | /* The module type to use. */ | |
71 | static unsigned short modtype = ('1' << 8) | 'L'; | |
72 | ||
73 | /* Whether the .text section must be read-only (i.e., no relocs | |
74 | permitted). */ | |
75 | static int textro; | |
76 | ||
77 | /* Structure used to hold import or export file list. */ | |
78 | ||
79 | struct filelist | |
80 | { | |
81 | struct filelist *next; | |
82 | const char *name; | |
83 | }; | |
84 | ||
85 | /* List of import files. */ | |
86 | struct filelist *import_files; | |
87 | ||
88 | /* List of export files. */ | |
89 | struct filelist *export_files; | |
90 | ||
91 | static void | |
92 | gld${EMULATION_NAME}_before_parse() | |
93 | { | |
94 | #ifndef TARGET_ /* I.e., if not generic. */ | |
95 | ldfile_output_architecture = bfd_arch_${ARCH}; | |
96 | #endif /* not TARGET_ */ | |
97 | } | |
98 | ||
99 | /* Handle AIX specific options. */ | |
100 | ||
101 | static int | |
102 | gld${EMULATION_NAME}_parse_args (argc, argv) | |
103 | int argc; | |
104 | char **argv; | |
105 | { | |
106 | int prevoptind = optind; | |
107 | int prevopterr = opterr; | |
108 | int longind; | |
109 | int optc; | |
110 | long val; | |
111 | char *end; | |
112 | ||
113 | #define OPTION_IGNORE (300) | |
114 | #define OPTION_AUTOIMP (OPTION_IGNORE + 1) | |
115 | #define OPTION_ERNOTOK (OPTION_AUTOIMP + 1) | |
116 | #define OPTION_EROK (OPTION_ERNOTOK + 1) | |
117 | #define OPTION_EXPORT (OPTION_EROK + 1) | |
118 | #define OPTION_IMPORT (OPTION_EXPORT + 1) | |
119 | #define OPTION_MAXDATA (OPTION_IMPORT + 1) | |
120 | #define OPTION_MAXSTACK (OPTION_MAXDATA + 1) | |
121 | #define OPTION_MODTYPE (OPTION_MAXSTACK + 1) | |
122 | #define OPTION_NOAUTOIMP (OPTION_MODTYPE + 1) | |
123 | #define OPTION_NOSTRCMPCT (OPTION_NOAUTOIMP + 1) | |
124 | #define OPTION_STRCMPCT (OPTION_NOSTRCMPCT + 1) | |
125 | ||
126 | static struct option longopts[] = { | |
127 | {"basis", no_argument, NULL, OPTION_IGNORE}, | |
128 | {"bautoimp", no_argument, NULL, OPTION_AUTOIMP}, | |
129 | {"bcomprld", no_argument, NULL, OPTION_IGNORE}, | |
130 | {"bcrld", no_argument, NULL, OPTION_IGNORE}, | |
131 | {"bcror31", no_argument, NULL, OPTION_IGNORE}, | |
132 | {"bD", required_argument, NULL, OPTION_MAXDATA}, | |
133 | {"bE", required_argument, NULL, OPTION_EXPORT}, | |
134 | {"bernotok", no_argument, NULL, OPTION_ERNOTOK}, | |
135 | {"berok", no_argument, NULL, OPTION_EROK}, | |
136 | {"berrmsg", no_argument, NULL, OPTION_IGNORE}, | |
137 | {"bexport", required_argument, NULL, OPTION_EXPORT}, | |
138 | {"bf", no_argument, NULL, OPTION_ERNOTOK}, | |
139 | {"bgc", no_argument, &gc, 1}, | |
140 | {"bh", required_argument, NULL, OPTION_IGNORE}, | |
141 | {"bhalt", required_argument, NULL, OPTION_IGNORE}, | |
142 | {"bI", required_argument, NULL, OPTION_IMPORT}, | |
143 | {"bimport", required_argument, NULL, OPTION_IMPORT}, | |
144 | {"bmaxdata", required_argument, NULL, OPTION_MAXDATA}, | |
145 | {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK}, | |
146 | {"bM", required_argument, NULL, OPTION_MODTYPE}, | |
147 | {"bmodtype", required_argument, NULL, OPTION_MODTYPE}, | |
148 | {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP}, | |
149 | {"bnodelcsect", no_argument, NULL, OPTION_IGNORE}, | |
150 | {"bnogc", no_argument, &gc, 0}, | |
151 | {"bnso", no_argument, NULL, OPTION_NOAUTOIMP}, | |
152 | {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT}, | |
153 | {"bnotextro", no_argument, &textro, 0}, | |
154 | {"bnro", no_argument, &textro, 0}, | |
155 | {"bro", no_argument, &textro, 1}, | |
156 | {"bS", required_argument, NULL, OPTION_MAXSTACK}, | |
157 | {"bso", no_argument, NULL, OPTION_AUTOIMP}, | |
158 | {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT}, | |
159 | {"btextro", no_argument, &textro, 1}, | |
c7c8b500 | 160 | {"static", no_argument, NULL, OPTION_NOAUTOIMP}, |
57fc1e90 ILT |
161 | {NULL, no_argument, NULL, 0} |
162 | }; | |
163 | ||
164 | /* Options supported by the AIX linker which we do not support: -f, | |
165 | -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps, | |
166 | -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl, | |
167 | -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl, | |
168 | -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink, | |
169 | -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder, | |
170 | -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk, | |
171 | -bx, -bX, -bxref. */ | |
172 | ||
173 | /* If the first option starts with -b, change the first : to an =. | |
174 | The AIX linker uses : to separate the option from the argument; | |
175 | changing it to = lets us treat it as a getopt option. */ | |
176 | if (optind < argc && strncmp (argv[optind], "-b", 2) == 0) | |
177 | { | |
178 | char *s; | |
179 | ||
180 | for (s = argv[optind]; *s != '\0'; s++) | |
181 | { | |
182 | if (*s == ':') | |
183 | { | |
184 | *s = '='; | |
185 | break; | |
186 | } | |
187 | } | |
188 | } | |
189 | ||
190 | opterr = 0; | |
191 | optc = getopt_long_only (argc, argv, "-D:H:KT:z", longopts, &longind); | |
192 | opterr = prevopterr; | |
193 | ||
194 | switch (optc) | |
195 | { | |
196 | default: | |
197 | optind = prevoptind; | |
198 | return 0; | |
199 | ||
1764521f ILT |
200 | case 0: |
201 | /* Long option which just sets a flag. */ | |
202 | break; | |
203 | ||
57fc1e90 ILT |
204 | case 'D': |
205 | val = strtol (optarg, &end, 0); | |
206 | if (*end != '\0') | |
207 | einfo ("%P: warning: ignoring invalid -D number %s\n", optarg); | |
208 | else if (val != -1) | |
209 | lang_section_start (".data", exp_intop (val)); | |
210 | break; | |
211 | ||
212 | case 'H': | |
213 | val = strtoul (optarg, &end, 0); | |
214 | if (*end != '\0' | |
215 | || (val & (val - 1)) != 0) | |
216 | einfo ("%P: warning: ignoring invalid -H number %s\n", optarg); | |
217 | else | |
218 | file_align = val; | |
219 | break; | |
220 | ||
221 | case 'K': | |
222 | case 'z': | |
223 | /* FIXME: This should use the page size for the target system. */ | |
224 | file_align = 4096; | |
225 | break; | |
226 | ||
227 | case 'T': | |
228 | /* On AIX this is the same as GNU ld -Ttext. When we see -T | |
229 | number, we assume the AIX option is intended. Otherwise, we | |
230 | assume the usual GNU ld -T option is intended. We can't just | |
231 | ignore the AIX option, because gcc passes it to the linker. */ | |
232 | val = strtoul (optarg, &end, 0); | |
233 | if (*end != '\0') | |
234 | { | |
235 | optind = prevoptind; | |
236 | return 0; | |
237 | } | |
238 | lang_section_start (".text", exp_intop (val)); | |
239 | break; | |
240 | ||
241 | case OPTION_IGNORE: | |
242 | break; | |
243 | ||
244 | case OPTION_AUTOIMP: | |
245 | link_info.static_link = false; | |
246 | break; | |
247 | ||
248 | case OPTION_ERNOTOK: | |
249 | force_make_executable = false; | |
250 | break; | |
251 | ||
252 | case OPTION_EROK: | |
253 | force_make_executable = true; | |
254 | break; | |
255 | ||
256 | case OPTION_EXPORT: | |
257 | case OPTION_IMPORT: | |
258 | { | |
259 | struct filelist *n; | |
260 | struct filelist **flpp; | |
261 | ||
262 | n = (struct filelist *) xmalloc (sizeof (struct filelist)); | |
263 | n->next = NULL; | |
264 | n->name = optarg; | |
265 | if (optc == OPTION_EXPORT) | |
266 | flpp = &export_files; | |
267 | else | |
268 | flpp = &import_files; | |
269 | while (*flpp != NULL) | |
270 | flpp = &(*flpp)->next; | |
271 | *flpp = n; | |
272 | } | |
273 | break; | |
274 | ||
275 | case OPTION_MAXDATA: | |
276 | val = strtoul (optarg, &end, 0); | |
277 | if (*end != '\0') | |
278 | einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", | |
279 | optarg); | |
280 | else | |
281 | maxdata = val; | |
282 | break; | |
283 | ||
284 | case OPTION_MAXSTACK: | |
285 | val = strtoul (optarg, &end, 0); | |
286 | if (*end != '\0') | |
287 | einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n", | |
288 | optarg); | |
289 | else | |
290 | maxstack = val; | |
291 | break; | |
292 | ||
293 | case OPTION_MODTYPE: | |
294 | if (*optarg == 'S') | |
295 | { | |
296 | link_info.shared = true; | |
297 | ++optarg; | |
298 | } | |
299 | if (*optarg == '\0' || optarg[1] == '\0') | |
300 | einfo ("%P: warning: ignoring invalid module type %s\n", optarg); | |
301 | else | |
302 | modtype = (*optarg << 8) | optarg[1]; | |
303 | break; | |
304 | ||
305 | case OPTION_NOAUTOIMP: | |
306 | link_info.static_link = true; | |
307 | break; | |
308 | ||
309 | case OPTION_NOSTRCMPCT: | |
310 | config.traditional_format = true; | |
311 | break; | |
312 | ||
313 | case OPTION_STRCMPCT: | |
314 | config.traditional_format = false; | |
315 | break; | |
316 | } | |
317 | ||
318 | return 1; | |
319 | } | |
320 | ||
cf79773c ILT |
321 | /* This is called after the input files have been opened. */ |
322 | ||
323 | static void | |
324 | gld${EMULATION_NAME}_after_open () | |
325 | { | |
326 | boolean r; | |
327 | struct set_info *p; | |
328 | ||
329 | /* Call ldctor_build_sets, after pretending that this is a | |
330 | relocateable link. We do this because AIX requires relocation | |
331 | entries for all references to symbols, even in a final | |
332 | executable. */ | |
333 | r = link_info.relocateable; | |
334 | link_info.relocateable = true; | |
335 | ldctor_build_sets (); | |
336 | link_info.relocateable = r; | |
337 | ||
338 | /* For each set, record the size, so that the XCOFF backend can | |
339 | output the correct csect length. */ | |
340 | for (p = sets; p != (struct set_info *) NULL; p = p->next) | |
341 | { | |
342 | bfd_size_type size; | |
343 | ||
344 | /* If the symbol is defined, we may have been invoked from | |
345 | collect, and the sets may already have been built, so we do | |
346 | not do anything. */ | |
347 | if (p->h->type == bfd_link_hash_defined | |
348 | || p->h->type == bfd_link_hash_defweak) | |
349 | continue; | |
350 | ||
351 | if (p->reloc != BFD_RELOC_CTOR) | |
352 | { | |
353 | /* Handle this if we need to. */ | |
354 | abort (); | |
355 | } | |
356 | ||
357 | size = (p->count + 2) * 4; | |
358 | if (! bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size)) | |
359 | einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n"); | |
360 | } | |
361 | } | |
362 | ||
57fc1e90 ILT |
363 | /* This is called after the sections have been attached to output |
364 | sections, but before any sizes or addresses have been set. */ | |
365 | ||
366 | static void | |
367 | gld${EMULATION_NAME}_before_allocation () | |
368 | { | |
369 | struct filelist *fl; | |
370 | char *libpath; | |
371 | ||
372 | /* Handle the import and export files, if any. */ | |
373 | for (fl = import_files; fl != NULL; fl = fl->next) | |
374 | gld${EMULATION_NAME}_read_file (fl->name, true); | |
375 | for (fl = export_files; fl != NULL; fl = fl->next) | |
376 | gld${EMULATION_NAME}_read_file (fl->name, false); | |
377 | ||
cf79773c ILT |
378 | /* Track down all relocations called for by the linker script (these |
379 | are typically constructor/destructor entries created by | |
380 | CONSTRUCTORS) and let the backend know it will need to create | |
381 | .loader relocs for them. */ | |
382 | lang_for_each_statement (gld${EMULATION_NAME}_find_relocs); | |
383 | ||
57fc1e90 ILT |
384 | /* We need to build LIBPATH from the -L arguments. If any -rpath |
385 | arguments were used, though, we use -rpath instead, as a GNU | |
386 | extension. */ | |
387 | if (command_line.rpath != NULL) | |
388 | libpath = command_line.rpath; | |
389 | else if (search_head == NULL) | |
390 | libpath = (char *) ""; | |
391 | else | |
392 | { | |
393 | size_t len; | |
394 | search_dirs_type *search; | |
395 | ||
396 | len = strlen (search_head->name); | |
397 | libpath = xmalloc (len + 1); | |
398 | strcpy (libpath, search_head->name); | |
399 | for (search = search_head->next; search != NULL; search = search->next) | |
400 | { | |
401 | size_t nlen; | |
402 | ||
403 | nlen = strlen (search->name); | |
404 | libpath = xrealloc (libpath, len + nlen + 2); | |
405 | libpath[len] = ':'; | |
406 | strcpy (libpath + len + 1, search->name); | |
407 | len += nlen + 1; | |
408 | } | |
409 | } | |
410 | ||
411 | /* Let the XCOFF backend set up the .loader section. */ | |
412 | if (! bfd_xcoff_size_dynamic_sections (output_bfd, &link_info, libpath, | |
413 | entry_symbol, file_align, | |
414 | maxstack, maxdata, | |
415 | gc ? true : false, | |
416 | modtype, | |
417 | textro ? true : false)) | |
418 | einfo ("%P%F: failed to set dynamic section sizes: %E\n"); | |
419 | } | |
420 | ||
421 | /* Read an import or export file. */ | |
422 | ||
423 | static void | |
424 | gld${EMULATION_NAME}_read_file (filename, import) | |
425 | const char *filename; | |
426 | boolean import; | |
427 | { | |
428 | struct obstack *o; | |
429 | FILE *f; | |
430 | int lineno; | |
431 | int c; | |
432 | boolean keep; | |
433 | const char *imppath; | |
434 | const char *impfile; | |
435 | const char *impmember; | |
436 | ||
437 | o = (struct obstack *) xmalloc (sizeof (struct obstack)); | |
438 | obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free); | |
439 | ||
440 | f = fopen (filename, "r"); | |
441 | if (f == NULL) | |
442 | { | |
443 | bfd_set_error (bfd_error_system_call); | |
444 | einfo ("%F%s: %E\n", filename); | |
445 | } | |
446 | ||
447 | keep = false; | |
448 | ||
449 | imppath = NULL; | |
450 | impfile = NULL; | |
451 | impmember = NULL; | |
452 | ||
453 | lineno = 0; | |
454 | while ((c = getc (f)) != EOF) | |
455 | { | |
456 | char *s; | |
457 | char *symname; | |
458 | boolean syscall; | |
459 | bfd_vma address; | |
460 | struct bfd_link_hash_entry *h; | |
461 | ||
462 | if (c != '\n') | |
463 | { | |
464 | obstack_1grow (o, c); | |
465 | continue; | |
466 | } | |
467 | ||
468 | obstack_1grow (o, '\0'); | |
469 | ++lineno; | |
470 | ||
471 | s = (char *) obstack_base (o); | |
472 | while (isspace ((unsigned char) *s)) | |
473 | ++s; | |
474 | if (*s == '\0' | |
475 | || *s == '*' | |
476 | || (*s == '#' && s[1] == ' ') | |
477 | || (! import && *s == '#' && s[1] == '!')) | |
478 | { | |
479 | obstack_free (o, obstack_base (o)); | |
480 | continue; | |
481 | } | |
482 | ||
483 | if (*s == '#' && s[1] == '!') | |
484 | { | |
485 | s += 2; | |
486 | while (isspace ((unsigned char) *s)) | |
487 | ++s; | |
488 | if (*s == '\0') | |
489 | { | |
490 | imppath = NULL; | |
491 | impfile = NULL; | |
492 | impmember = NULL; | |
493 | obstack_free (o, obstack_base (o)); | |
494 | } | |
495 | else if (*s == '(') | |
496 | einfo ("%F%s%d: #! ([member]) is not supported in import files", | |
497 | filename, lineno); | |
498 | else | |
499 | { | |
500 | char cs; | |
501 | char *file; | |
502 | ||
503 | (void) obstack_finish (o); | |
504 | keep = true; | |
505 | imppath = s; | |
506 | impfile = NULL; | |
507 | while (! isspace ((unsigned char) *s) && *s != '(' && *s != '\0') | |
508 | { | |
509 | if (*s == '/') | |
510 | file = s + 1; | |
511 | ++s; | |
512 | } | |
513 | if (file != NULL) | |
514 | { | |
515 | file[-1] = '\0'; | |
516 | impfile = file; | |
517 | if (imppath == file - 1) | |
518 | imppath = "/"; | |
519 | } | |
520 | else | |
521 | { | |
522 | impfile = imppath; | |
523 | imppath = ""; | |
524 | } | |
525 | cs = *s; | |
526 | *s = '\0'; | |
527 | while (isspace ((unsigned char) cs)) | |
528 | { | |
529 | ++s; | |
530 | cs = *s; | |
531 | } | |
532 | if (cs != '(') | |
533 | { | |
534 | impmember = ""; | |
535 | if (cs != '\0') | |
536 | einfo ("%s:%d: warning: syntax error in import file\n", | |
537 | filename, lineno); | |
538 | } | |
539 | else | |
540 | { | |
541 | ++s; | |
542 | impmember = s; | |
543 | while (*s != ')' && *s != '\0') | |
544 | ++s; | |
545 | if (*s == ')') | |
546 | *s = '\0'; | |
547 | else | |
548 | einfo ("%s:%d: warning: syntax error in import file\n", | |
549 | filename, lineno); | |
550 | } | |
551 | } | |
552 | ||
553 | continue; | |
554 | } | |
555 | ||
556 | /* This is a symbol to be imported or exported. */ | |
557 | symname = s; | |
558 | syscall = false; | |
559 | address = (bfd_vma) -1; | |
560 | ||
561 | while (! isspace ((unsigned char) *s) && *s != '\0') | |
562 | ++s; | |
563 | if (*s != '\0') | |
564 | { | |
565 | char *se; | |
566 | ||
567 | *s++ = '\0'; | |
568 | ||
569 | while (isspace ((unsigned char) *s)) | |
570 | ++s; | |
571 | ||
572 | se = s; | |
573 | while (! isspace ((unsigned char) *se) && *se != '\0') | |
574 | ++se; | |
575 | if (*se != '\0') | |
576 | { | |
577 | *se++ = '\0'; | |
578 | while (isspace ((unsigned char) *se)) | |
579 | ++se; | |
580 | if (*se != '\0') | |
581 | einfo ("%s%d: warning: syntax error in import/export file\n", | |
582 | filename, lineno); | |
583 | } | |
584 | ||
585 | if (strcasecmp (s, "svc") == 0 | |
586 | || strcasecmp (s, "syscall") == 0) | |
587 | syscall = true; | |
588 | else | |
589 | { | |
590 | char *end; | |
591 | ||
592 | address = strtoul (s, &end, 0); | |
593 | if (*end != '\0') | |
594 | einfo ("%s:%d: warning: syntax error in import/export file\n", | |
595 | filename, lineno); | |
596 | } | |
597 | } | |
598 | ||
599 | h = bfd_link_hash_lookup (link_info.hash, symname, false, false, true); | |
600 | if (h == NULL || h->type == bfd_link_hash_new) | |
601 | { | |
602 | /* We can just ignore attempts to import an unreferenced | |
603 | symbol. */ | |
604 | if (! import) | |
605 | einfo ("%X%s:%d: attempt to export undefined symbol %s\n", | |
606 | filename, lineno, symname); | |
607 | } | |
608 | else if (import) | |
609 | { | |
610 | if (! bfd_xcoff_import_symbol (output_bfd, &link_info, h, address, | |
611 | imppath, impfile, impmember)) | |
612 | einfo ("%X%s:%d: failed to import symbol %s: %E\n", | |
613 | filename, lineno, symname); | |
614 | } | |
615 | else | |
616 | { | |
617 | if (! bfd_xcoff_export_symbol (output_bfd, &link_info, h, syscall)) | |
618 | einfo ("%X%s:%d: failed to export symbol %s: %E\n", | |
619 | filename, lineno, symname); | |
620 | } | |
621 | ||
622 | obstack_free (o, obstack_base (o)); | |
623 | } | |
624 | ||
625 | if (obstack_object_size (o) > 0) | |
626 | { | |
627 | einfo ("%s:%d: warning: ignoring unterminated last line\n", | |
628 | filename, lineno); | |
629 | obstack_free (o, obstack_base (o)); | |
630 | } | |
631 | ||
632 | if (! keep) | |
633 | { | |
634 | obstack_free (o, NULL); | |
635 | free (o); | |
636 | } | |
637 | } | |
638 | ||
639 | /* This routine saves us from worrying about declaring free. */ | |
640 | ||
641 | static void | |
642 | gld${EMULATION_NAME}_free (p) | |
643 | PTR p; | |
644 | { | |
645 | free (p); | |
646 | } | |
647 | ||
cf79773c ILT |
648 | /* This is called by the before_allocation routine via |
649 | lang_for_each_statement. It looks for relocations and assignments | |
650 | to symbols. */ | |
651 | ||
652 | static void | |
653 | gld${EMULATION_NAME}_find_relocs (s) | |
654 | lang_statement_union_type *s; | |
655 | { | |
656 | if (s->header.type == lang_reloc_statement_enum) | |
657 | { | |
658 | lang_reloc_statement_type *rs; | |
659 | ||
660 | rs = &s->reloc_statement; | |
661 | if (rs->name == NULL) | |
662 | einfo ("%F%P: only relocations against symbols are permitted\n"); | |
663 | if (! bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name)) | |
664 | einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n"); | |
665 | } | |
666 | ||
667 | if (s->header.type == lang_assignment_statement_enum) | |
668 | gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp); | |
669 | } | |
670 | ||
671 | /* Look through an expression for an assignment statement. */ | |
672 | ||
673 | static void | |
674 | gld${EMULATION_NAME}_find_exp_assignment (exp) | |
675 | etree_type *exp; | |
676 | { | |
677 | struct bfd_link_hash_entry *h; | |
678 | ||
679 | switch (exp->type.node_class) | |
680 | { | |
681 | case etree_provide: | |
682 | h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst, | |
683 | false, false, false); | |
684 | if (h == NULL) | |
685 | break; | |
686 | /* Fall through. */ | |
687 | case etree_assign: | |
688 | if (strcmp (exp->assign.dst, ".") != 0) | |
689 | { | |
690 | if (! bfd_xcoff_record_link_assignment (output_bfd, &link_info, | |
691 | exp->assign.dst)) | |
692 | einfo ("%P%F: failed to record assignment to %s: %E\n", | |
693 | exp->assign.dst); | |
694 | } | |
695 | gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src); | |
696 | break; | |
697 | ||
698 | case etree_binary: | |
699 | gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs); | |
700 | gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs); | |
701 | break; | |
702 | ||
703 | case etree_trinary: | |
704 | gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond); | |
705 | gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs); | |
706 | gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs); | |
707 | break; | |
708 | ||
709 | case etree_unary: | |
710 | gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child); | |
711 | break; | |
712 | ||
713 | default: | |
714 | break; | |
715 | } | |
716 | } | |
717 | ||
57fc1e90 ILT |
718 | static char * |
719 | gld${EMULATION_NAME}_get_script(isfile) | |
720 | int *isfile; | |
721 | EOF | |
722 | ||
723 | if test -n "$COMPILE_IN" | |
724 | then | |
725 | # Scripts compiled in. | |
726 | ||
727 | # sed commands to quote an ld script as a C string. | |
728 | sc="-f ${srcdir}/emultempl/stringify.sed" | |
729 | ||
730 | cat >>e${EMULATION_NAME}.c <<EOF | |
731 | { | |
732 | *isfile = 0; | |
733 | ||
734 | if (link_info.relocateable == true && config.build_constructors == true) | |
735 | return | |
736 | EOF | |
737 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c | |
738 | echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c | |
739 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c | |
740 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c | |
741 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c | |
742 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c | |
743 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c | |
744 | echo ' ; else return' >> e${EMULATION_NAME}.c | |
745 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c | |
746 | echo '; }' >> e${EMULATION_NAME}.c | |
747 | ||
748 | else | |
749 | # Scripts read from the filesystem. | |
750 | ||
751 | cat >>e${EMULATION_NAME}.c <<EOF | |
752 | { | |
753 | *isfile = 1; | |
754 | ||
755 | if (link_info.relocateable == true && config.build_constructors == true) | |
756 | return "ldscripts/${EMULATION_NAME}.xu"; | |
757 | else if (link_info.relocateable == true) | |
758 | return "ldscripts/${EMULATION_NAME}.xr"; | |
759 | else if (!config.text_read_only) | |
760 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
761 | else if (!config.magic_demand_paged) | |
762 | return "ldscripts/${EMULATION_NAME}.xn"; | |
763 | else | |
764 | return "ldscripts/${EMULATION_NAME}.x"; | |
765 | } | |
766 | EOF | |
767 | ||
768 | fi | |
769 | ||
770 | cat >>e${EMULATION_NAME}.c <<EOF | |
771 | ||
772 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = | |
773 | { | |
774 | gld${EMULATION_NAME}_before_parse, | |
775 | syslib_default, | |
776 | hll_default, | |
777 | after_parse_default, | |
cf79773c | 778 | gld${EMULATION_NAME}_after_open, |
57fc1e90 ILT |
779 | after_allocation_default, |
780 | set_output_arch_default, | |
781 | ldemul_default_target, | |
782 | gld${EMULATION_NAME}_before_allocation, | |
783 | gld${EMULATION_NAME}_get_script, | |
784 | "${EMULATION_NAME}", | |
785 | "${OUTPUT_FORMAT}", | |
786 | 0, /* finish */ | |
787 | 0, /* create_output_section_statements */ | |
788 | 0, /* open_dynamic_archive */ | |
789 | 0, /* place_orphan */ | |
790 | 0, /* set_symbols */ | |
791 | gld${EMULATION_NAME}_parse_args, | |
792 | }; | |
793 | EOF |