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