* configure.tgt (powerpc-*-macos*): New target.
[deliverable/binutils-gdb.git] / ld / mpw-eppcmacos.c
1 /* This file is is generated by a shell script. DO NOT EDIT! */
2
3 /* AIX emulation code for ppcmacos
4 Copyright (C) 1991, 1993, 1995 Free Software Foundation, Inc.
5 Written by Steve Chamberlain <sac@cygnus.com>
6 AIX support by Ian Lance Taylor <ian@cygnus.com>
7
8 This file is part of GLD, the Gnu Linker.
9
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 2 of the License, or
13 (at your option) any later version.
14
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.
19
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23
24 #define TARGET_IS_ppcmacos
25
26 #include "bfd.h"
27 #include "sysdep.h"
28 #include "libiberty.h"
29 #include "getopt.h"
30 #include "bfdlink.h"
31
32 #include <ctype.h>
33
34 #include "ld.h"
35 #include "ldmain.h"
36 #include "ldemul.h"
37 #include "ldfile.h"
38 #include "ldmisc.h"
39 #include "ldexp.h"
40 #include "ldlang.h"
41 #include "ldctor.h"
42 #include "ldgram.h"
43
44 static void gldppcmacos_before_parse PARAMS ((void));
45 static int gldppcmacos_parse_args PARAMS ((int, char **));
46 static void gldppcmacos_after_open PARAMS ((void));
47 static void gldppcmacos_before_allocation PARAMS ((void));
48 static void gldppcmacos_read_file PARAMS ((const char *, boolean));
49 static void gldppcmacos_free PARAMS ((PTR));
50 static void gldppcmacos_find_relocs
51 PARAMS ((lang_statement_union_type *));
52 static void gldppcmacos_find_exp_assignment PARAMS ((etree_type *));
53 static char *gldppcmacos_get_script PARAMS ((int *isfile));
54
55 /* The file alignment required for each section. */
56 static unsigned long file_align;
57
58 /* The maximum size the stack is permitted to grow. This is stored in
59 the a.out header. */
60 static unsigned long maxstack;
61
62 /* The maximum data size. This is stored in the a.out header. */
63 static unsigned long maxdata;
64
65 /* Whether to perform garbage collection. */
66 static int gc = 1;
67
68 /* The module type to use. */
69 static unsigned short modtype = ('1' << 8) | 'L';
70
71 /* Whether the .text section must be read-only (i.e., no relocs
72 permitted). */
73 static int textro;
74
75 /* Structure used to hold import file list. */
76
77 struct filelist
78 {
79 struct filelist *next;
80 const char *name;
81 };
82
83 /* List of import files. */
84 static struct filelist *import_files;
85
86 /* List of export symbols read from the export files. */
87
88 struct export_symbol_list
89 {
90 struct export_symbol_list *next;
91 const char *name;
92 boolean syscall;
93 };
94
95 static struct export_symbol_list *export_symbols;
96
97 /* This routine is called before anything else is done. */
98
99 static void
100 gldppcmacos_before_parse()
101 {
102 #ifndef TARGET_ /* I.e., if not generic. */
103 ldfile_output_architecture = bfd_arch_powerpc;
104 #endif /* not TARGET_ */
105 }
106
107 /* Handle AIX specific options. */
108
109 static int
110 gldppcmacos_parse_args (argc, argv)
111 int argc;
112 char **argv;
113 {
114 int prevoptind = optind;
115 int prevopterr = opterr;
116 int indx;
117 int longind;
118 int optc;
119 long val;
120 char *end;
121
122 #define OPTION_IGNORE (300)
123 #define OPTION_AUTOIMP (OPTION_IGNORE + 1)
124 #define OPTION_ERNOTOK (OPTION_AUTOIMP + 1)
125 #define OPTION_EROK (OPTION_ERNOTOK + 1)
126 #define OPTION_EXPORT (OPTION_EROK + 1)
127 #define OPTION_IMPORT (OPTION_EXPORT + 1)
128 #define OPTION_LOADMAP (OPTION_IMPORT + 1)
129 #define OPTION_MAXDATA (OPTION_LOADMAP + 1)
130 #define OPTION_MAXSTACK (OPTION_MAXDATA + 1)
131 #define OPTION_MODTYPE (OPTION_MAXSTACK + 1)
132 #define OPTION_NOAUTOIMP (OPTION_MODTYPE + 1)
133 #define OPTION_NOSTRCMPCT (OPTION_NOAUTOIMP + 1)
134 #define OPTION_PD (OPTION_NOSTRCMPCT + 1)
135 #define OPTION_PT (OPTION_PD + 1)
136 #define OPTION_STRCMPCT (OPTION_PT + 1)
137
138 static struct option longopts[] = {
139 {"basis", no_argument, NULL, OPTION_IGNORE},
140 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
141 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
142 {"bcrld", no_argument, NULL, OPTION_IGNORE},
143 {"bcror31", no_argument, NULL, OPTION_IGNORE},
144 {"bD", required_argument, NULL, OPTION_MAXDATA},
145 {"bE", required_argument, NULL, OPTION_EXPORT},
146 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
147 {"berok", no_argument, NULL, OPTION_EROK},
148 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
149 {"bexport", required_argument, NULL, OPTION_EXPORT},
150 {"bf", no_argument, NULL, OPTION_ERNOTOK},
151 {"bgc", no_argument, &gc, 1},
152 {"bh", required_argument, NULL, OPTION_IGNORE},
153 {"bhalt", required_argument, NULL, OPTION_IGNORE},
154 {"bI", required_argument, NULL, OPTION_IMPORT},
155 {"bimport", required_argument, NULL, OPTION_IMPORT},
156 {"bl", required_argument, NULL, OPTION_LOADMAP},
157 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
158 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
159 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
160 {"bM", required_argument, NULL, OPTION_MODTYPE},
161 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
162 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
163 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
164 {"bnogc", no_argument, &gc, 0},
165 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
166 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
167 {"bnotextro", no_argument, &textro, 0},
168 {"bnro", no_argument, &textro, 0},
169 {"bpD", required_argument, NULL, OPTION_PD},
170 {"bpT", required_argument, NULL, OPTION_PT},
171 {"bro", no_argument, &textro, 1},
172 {"bS", required_argument, NULL, OPTION_MAXSTACK},
173 {"bso", no_argument, NULL, OPTION_AUTOIMP},
174 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
175 {"btextro", no_argument, &textro, 1},
176 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
177 {NULL, no_argument, NULL, 0}
178 };
179
180 /* Options supported by the AIX linker which we do not support: -f,
181 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
182 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
183 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
184 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
185 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
186 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
187 -bx, -bX, -bxref. */
188
189 /* If the current option starts with -b, change the first : to an =.
190 The AIX linker uses : to separate the option from the argument;
191 changing it to = lets us treat it as a getopt option. */
192 indx = optind;
193 if (indx == 0)
194 indx = 1;
195 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
196 {
197 char *s;
198
199 for (s = argv[indx]; *s != '\0'; s++)
200 {
201 if (*s == ':')
202 {
203 *s = '=';
204 break;
205 }
206 }
207 }
208
209 opterr = 0;
210 optc = getopt_long_only (argc, argv, "-D:H:KT:z", longopts, &longind);
211 opterr = prevopterr;
212
213 switch (optc)
214 {
215 default:
216 optind = prevoptind;
217 return 0;
218
219 case 0:
220 /* Long option which just sets a flag. */
221 break;
222
223 case 'D':
224 val = strtol (optarg, &end, 0);
225 if (*end != '\0')
226 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
227 else if (val != -1)
228 lang_section_start (".data", exp_intop (val));
229 break;
230
231 case 'H':
232 val = strtoul (optarg, &end, 0);
233 if (*end != '\0'
234 || (val & (val - 1)) != 0)
235 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
236 else
237 file_align = val;
238 break;
239
240 case 'K':
241 case 'z':
242 /* FIXME: This should use the page size for the target system. */
243 file_align = 4096;
244 break;
245
246 case 'T':
247 /* On AIX this is the same as GNU ld -Ttext. When we see -T
248 number, we assume the AIX option is intended. Otherwise, we
249 assume the usual GNU ld -T option is intended. We can't just
250 ignore the AIX option, because gcc passes it to the linker. */
251 val = strtoul (optarg, &end, 0);
252 if (*end != '\0')
253 {
254 optind = prevoptind;
255 return 0;
256 }
257 lang_section_start (".text", exp_intop (val));
258 break;
259
260 case OPTION_IGNORE:
261 break;
262
263 case OPTION_AUTOIMP:
264 link_info.static_link = false;
265 break;
266
267 case OPTION_ERNOTOK:
268 force_make_executable = false;
269 break;
270
271 case OPTION_EROK:
272 force_make_executable = true;
273 break;
274
275 case OPTION_EXPORT:
276 gldppcmacos_read_file (optarg, false);
277 break;
278
279 case OPTION_IMPORT:
280 {
281 struct filelist *n;
282 struct filelist **flpp;
283
284 n = (struct filelist *) xmalloc (sizeof (struct filelist));
285 n->next = NULL;
286 n->name = optarg;
287 flpp = &import_files;
288 while (*flpp != NULL)
289 flpp = &(*flpp)->next;
290 *flpp = n;
291 }
292 break;
293
294 case OPTION_LOADMAP:
295 config.map_filename = optarg;
296 break;
297
298 case OPTION_MAXDATA:
299 val = strtoul (optarg, &end, 0);
300 if (*end != '\0')
301 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n",
302 optarg);
303 else
304 maxdata = val;
305 break;
306
307 case OPTION_MAXSTACK:
308 val = strtoul (optarg, &end, 0);
309 if (*end != '\0')
310 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
311 optarg);
312 else
313 maxstack = val;
314 break;
315
316 case OPTION_MODTYPE:
317 if (*optarg == 'S')
318 {
319 link_info.shared = true;
320 ++optarg;
321 }
322 if (*optarg == '\0' || optarg[1] == '\0')
323 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
324 else
325 modtype = (*optarg << 8) | optarg[1];
326 break;
327
328 case OPTION_NOAUTOIMP:
329 link_info.static_link = true;
330 break;
331
332 case OPTION_NOSTRCMPCT:
333 config.traditional_format = true;
334 break;
335
336 case OPTION_PD:
337 /* This sets the page that the .data section is supposed to
338 start on. The offset within the page should still be the
339 offset within the file, so we need to build an appropriate
340 expression. */
341 val = strtoul (optarg, &end, 0);
342 if (*end != '\0')
343 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
344 else
345 {
346 etree_type *t;
347
348 t = exp_binop ('+',
349 exp_intop (val),
350 exp_binop ('&',
351 exp_nameop (NAME, "."),
352 exp_intop (0xfff)));
353 t = exp_binop ('&',
354 exp_binop ('+', t, exp_intop (7)),
355 exp_intop (~ (bfd_vma) 7));
356 lang_section_start (".data", t);
357 }
358 break;
359
360 case OPTION_PT:
361 /* This set the page that the .text section is supposed to start
362 on. The offset within the page should still be the offset
363 within the file. */
364 val = strtoul (optarg, &end, 0);
365 if (*end != '\0')
366 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
367 else
368 {
369 etree_type *t;
370
371 t = exp_binop ('+',
372 exp_intop (val),
373 exp_nameop (SIZEOF_HEADERS, NULL));
374 t = exp_binop ('&',
375 exp_binop ('+', t, exp_intop (7)),
376 exp_intop (~ (bfd_vma) 7));
377 lang_section_start (".text", t);
378 }
379 break;
380
381 case OPTION_STRCMPCT:
382 config.traditional_format = false;
383 break;
384 }
385
386 return 1;
387 }
388
389 /* This is called after the input files have been opened. */
390
391 static void
392 gldppcmacos_after_open ()
393 {
394 boolean r;
395 struct set_info *p;
396
397 /* Call ldctor_build_sets, after pretending that this is a
398 relocateable link. We do this because AIX requires relocation
399 entries for all references to symbols, even in a final
400 executable. */
401 r = link_info.relocateable;
402 link_info.relocateable = true;
403 ldctor_build_sets ();
404 link_info.relocateable = r;
405
406 /* For each set, record the size, so that the XCOFF backend can
407 output the correct csect length. */
408 for (p = sets; p != (struct set_info *) NULL; p = p->next)
409 {
410 bfd_size_type size;
411
412 /* If the symbol is defined, we may have been invoked from
413 collect, and the sets may already have been built, so we do
414 not do anything. */
415 if (p->h->type == bfd_link_hash_defined
416 || p->h->type == bfd_link_hash_defweak)
417 continue;
418
419 if (p->reloc != BFD_RELOC_CTOR)
420 {
421 /* Handle this if we need to. */
422 abort ();
423 }
424
425 size = (p->count + 2) * 4;
426 if (! bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
427 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
428 }
429 }
430
431 /* This is called after the sections have been attached to output
432 sections, but before any sizes or addresses have been set. */
433
434 static void
435 gldppcmacos_before_allocation ()
436 {
437 struct filelist *fl;
438 struct export_symbol_list *el;
439 char *libpath;
440 asection *special_sections[6];
441 int i;
442
443 /* Handle the import and export files, if any. */
444 for (fl = import_files; fl != NULL; fl = fl->next)
445 gldppcmacos_read_file (fl->name, true);
446 for (el = export_symbols; el != NULL; el = el->next)
447 {
448 struct bfd_link_hash_entry *h;
449
450 h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);
451 if (h == NULL)
452 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
453 if (! bfd_xcoff_export_symbol (output_bfd, &link_info, h, el->syscall))
454 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
455 }
456
457 /* Track down all relocations called for by the linker script (these
458 are typically constructor/destructor entries created by
459 CONSTRUCTORS) and let the backend know it will need to create
460 .loader relocs for them. */
461 lang_for_each_statement (gldppcmacos_find_relocs);
462
463 /* We need to build LIBPATH from the -L arguments. If any -rpath
464 arguments were used, though, we use -rpath instead, as a GNU
465 extension. */
466 if (command_line.rpath != NULL)
467 libpath = command_line.rpath;
468 else if (search_head == NULL)
469 libpath = (char *) "";
470 else
471 {
472 size_t len;
473 search_dirs_type *search;
474
475 len = strlen (search_head->name);
476 libpath = xmalloc (len + 1);
477 strcpy (libpath, search_head->name);
478 for (search = search_head->next; search != NULL; search = search->next)
479 {
480 size_t nlen;
481
482 nlen = strlen (search->name);
483 libpath = xrealloc (libpath, len + nlen + 2);
484 libpath[len] = ':';
485 strcpy (libpath + len + 1, search->name);
486 len += nlen + 1;
487 }
488 }
489
490 /* Let the XCOFF backend set up the .loader section. */
491 if (! bfd_xcoff_size_dynamic_sections (output_bfd, &link_info, libpath,
492 entry_symbol, file_align,
493 maxstack, maxdata,
494 gc ? true : false,
495 modtype,
496 textro ? true : false,
497 special_sections))
498 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
499
500 /* Look through the special sections, and put them in the right
501 place in the link ordering. This is especially magic. */
502 for (i = 0; i < 6; i++)
503 {
504 asection *sec;
505 lang_output_section_statement_type *os;
506 lang_statement_union_type **pls;
507 lang_input_section_type *is;
508 const char *oname;
509 boolean start;
510
511 sec = special_sections[i];
512 if (sec == NULL)
513 continue;
514
515 /* Remove this section from the list of the output section.
516 This assumes we know what the script looks like. */
517 is = NULL;
518 os = lang_output_section_find (sec->output_section->name);
519 if (os == NULL)
520 einfo ("%P%F: can't find output section %s\n",
521 sec->output_section->name);
522 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->next)
523 {
524 if ((*pls)->header.type == lang_input_section_enum
525 && (*pls)->input_section.section == sec)
526 {
527 is = (lang_input_section_type *) *pls;
528 *pls = (*pls)->next;
529 break;
530 }
531 if ((*pls)->header.type == lang_wild_statement_enum)
532 {
533 lang_statement_union_type **pwls;
534
535 for (pwls = &(*pls)->wild_statement.children.head;
536 *pwls != NULL;
537 pwls = &(*pwls)->next)
538 {
539 if ((*pwls)->header.type == lang_input_section_enum
540 && (*pwls)->input_section.section == sec)
541 {
542 is = (lang_input_section_type *) *pwls;
543 *pwls = (*pwls)->next;
544 break;
545 }
546 }
547 if (is != NULL)
548 break;
549 }
550 }
551
552 if (is == NULL)
553 einfo ("%P%F: can't find %s in output section\n",
554 bfd_get_section_name (sec->owner, sec));
555
556 /* Now figure out where the section should go. */
557 switch (i)
558 {
559 default: /* to avoid warnings */
560 case 0:
561 /* _text */
562 oname = ".text";
563 start = true;
564 break;
565 case 1:
566 /* _etext */
567 oname = ".text";
568 start = false;
569 break;
570 case 2:
571 /* _data */
572 oname = ".data";
573 start = true;
574 break;
575 case 3:
576 /* _edata */
577 oname = ".data";
578 start = false;
579 break;
580 case 4:
581 case 5:
582 /* _end and end */
583 oname = ".bss";
584 start = false;
585 break;
586 }
587
588 os = lang_output_section_find (oname);
589
590 if (start)
591 {
592 is->header.next = os->children.head;
593 os->children.head = (lang_statement_union_type *) is;
594 }
595 else
596 {
597 is->header.next = NULL;
598 lang_statement_append (&os->children,
599 (lang_statement_union_type *) is,
600 &is->header.next);
601 }
602 }
603 }
604
605 /* Read an import or export file. For an import file, this is called
606 by the before_allocation emulation routine. For an export file,
607 this is called by the parse_args emulation routine. */
608
609 static void
610 gldppcmacos_read_file (filename, import)
611 const char *filename;
612 boolean import;
613 {
614 struct obstack *o;
615 FILE *f;
616 int lineno;
617 int c;
618 boolean keep;
619 const char *imppath;
620 const char *impfile;
621 const char *impmember;
622
623 o = (struct obstack *) xmalloc (sizeof (struct obstack));
624 obstack_specify_allocation (o, 0, 0, xmalloc, gldppcmacos_free);
625
626 f = fopen (filename, "r");
627 if (f == NULL)
628 {
629 bfd_set_error (bfd_error_system_call);
630 einfo ("%F%s: %E\n", filename);
631 }
632
633 keep = false;
634
635 imppath = NULL;
636 impfile = NULL;
637 impmember = NULL;
638
639 lineno = 0;
640 while ((c = getc (f)) != EOF)
641 {
642 char *s;
643 char *symname;
644 boolean syscall;
645 bfd_vma address;
646 struct bfd_link_hash_entry *h;
647
648 if (c != '\n')
649 {
650 obstack_1grow (o, c);
651 continue;
652 }
653
654 obstack_1grow (o, '\0');
655 ++lineno;
656
657 s = (char *) obstack_base (o);
658 while (isspace ((unsigned char) *s))
659 ++s;
660 if (*s == '\0'
661 || *s == '*'
662 || (*s == '#' && s[1] == ' ')
663 || (! import && *s == '#' && s[1] == '!'))
664 {
665 obstack_free (o, obstack_base (o));
666 continue;
667 }
668
669 if (*s == '#' && s[1] == '!')
670 {
671 s += 2;
672 while (isspace ((unsigned char) *s))
673 ++s;
674 if (*s == '\0')
675 {
676 imppath = NULL;
677 impfile = NULL;
678 impmember = NULL;
679 obstack_free (o, obstack_base (o));
680 }
681 else if (*s == '(')
682 einfo ("%F%s%d: #! ([member]) is not supported in import files",
683 filename, lineno);
684 else
685 {
686 char cs;
687 char *file;
688
689 (void) obstack_finish (o);
690 keep = true;
691 imppath = s;
692 impfile = NULL;
693 while (! isspace ((unsigned char) *s) && *s != '(' && *s != '\0')
694 {
695 if (*s == '/')
696 file = s + 1;
697 ++s;
698 }
699 if (file != NULL)
700 {
701 file[-1] = '\0';
702 impfile = file;
703 if (imppath == file - 1)
704 imppath = "/";
705 }
706 else
707 {
708 impfile = imppath;
709 imppath = "";
710 }
711 cs = *s;
712 *s = '\0';
713 while (isspace ((unsigned char) cs))
714 {
715 ++s;
716 cs = *s;
717 }
718 if (cs != '(')
719 {
720 impmember = "";
721 if (cs != '\0')
722 einfo ("%s:%d: warning: syntax error in import file\n",
723 filename, lineno);
724 }
725 else
726 {
727 ++s;
728 impmember = s;
729 while (*s != ')' && *s != '\0')
730 ++s;
731 if (*s == ')')
732 *s = '\0';
733 else
734 einfo ("%s:%d: warning: syntax error in import file\n",
735 filename, lineno);
736 }
737 }
738
739 continue;
740 }
741
742 /* This is a symbol to be imported or exported. */
743 symname = s;
744 syscall = false;
745 address = (bfd_vma) -1;
746
747 while (! isspace ((unsigned char) *s) && *s != '\0')
748 ++s;
749 if (*s != '\0')
750 {
751 char *se;
752
753 *s++ = '\0';
754
755 while (isspace ((unsigned char) *s))
756 ++s;
757
758 se = s;
759 while (! isspace ((unsigned char) *se) && *se != '\0')
760 ++se;
761 if (*se != '\0')
762 {
763 *se++ = '\0';
764 while (isspace ((unsigned char) *se))
765 ++se;
766 if (*se != '\0')
767 einfo ("%s%d: warning: syntax error in import/export file\n",
768 filename, lineno);
769 }
770
771 if (strcasecmp (s, "svc") == 0
772 || strcasecmp (s, "syscall") == 0)
773 syscall = true;
774 else
775 {
776 char *end;
777
778 address = strtoul (s, &end, 0);
779 if (*end != '\0')
780 einfo ("%s:%d: warning: syntax error in import/export file\n",
781 filename, lineno);
782 }
783 }
784
785 if (! import)
786 {
787 struct export_symbol_list *n;
788
789 ldlang_add_undef (symname);
790 n = ((struct export_symbol_list *)
791 xmalloc (sizeof (struct export_symbol_list)));
792 n->next = export_symbols;
793 n->name = buystring (symname);
794 n->syscall = syscall;
795 export_symbols = n;
796 }
797 else
798 {
799 h = bfd_link_hash_lookup (link_info.hash, symname, false, false,
800 true);
801 if (h == NULL || h->type == bfd_link_hash_new)
802 {
803 /* We can just ignore attempts to import an unreferenced
804 symbol. */
805 }
806 else
807 {
808 if (! bfd_xcoff_import_symbol (output_bfd, &link_info, h,
809 address, imppath, impfile,
810 impmember))
811 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
812 filename, lineno, symname);
813 }
814 }
815
816 obstack_free (o, obstack_base (o));
817 }
818
819 if (obstack_object_size (o) > 0)
820 {
821 einfo ("%s:%d: warning: ignoring unterminated last line\n",
822 filename, lineno);
823 obstack_free (o, obstack_base (o));
824 }
825
826 if (! keep)
827 {
828 obstack_free (o, NULL);
829 free (o);
830 }
831 }
832
833 /* This routine saves us from worrying about declaring free. */
834
835 static void
836 gldppcmacos_free (p)
837 PTR p;
838 {
839 free (p);
840 }
841
842 /* This is called by the before_allocation routine via
843 lang_for_each_statement. It looks for relocations and assignments
844 to symbols. */
845
846 static void
847 gldppcmacos_find_relocs (s)
848 lang_statement_union_type *s;
849 {
850 if (s->header.type == lang_reloc_statement_enum)
851 {
852 lang_reloc_statement_type *rs;
853
854 rs = &s->reloc_statement;
855 if (rs->name == NULL)
856 einfo ("%F%P: only relocations against symbols are permitted\n");
857 if (! bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
858 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
859 }
860
861 if (s->header.type == lang_assignment_statement_enum)
862 gldppcmacos_find_exp_assignment (s->assignment_statement.exp);
863 }
864
865 /* Look through an expression for an assignment statement. */
866
867 static void
868 gldppcmacos_find_exp_assignment (exp)
869 etree_type *exp;
870 {
871 struct bfd_link_hash_entry *h;
872
873 switch (exp->type.node_class)
874 {
875 case etree_provide:
876 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
877 false, false, false);
878 if (h == NULL)
879 break;
880 /* Fall through. */
881 case etree_assign:
882 if (strcmp (exp->assign.dst, ".") != 0)
883 {
884 if (! bfd_xcoff_record_link_assignment (output_bfd, &link_info,
885 exp->assign.dst))
886 einfo ("%P%F: failed to record assignment to %s: %E\n",
887 exp->assign.dst);
888 }
889 gldppcmacos_find_exp_assignment (exp->assign.src);
890 break;
891
892 case etree_binary:
893 gldppcmacos_find_exp_assignment (exp->binary.lhs);
894 gldppcmacos_find_exp_assignment (exp->binary.rhs);
895 break;
896
897 case etree_trinary:
898 gldppcmacos_find_exp_assignment (exp->trinary.cond);
899 gldppcmacos_find_exp_assignment (exp->trinary.lhs);
900 gldppcmacos_find_exp_assignment (exp->trinary.rhs);
901 break;
902
903 case etree_unary:
904 gldppcmacos_find_exp_assignment (exp->unary.child);
905 break;
906
907 default:
908 break;
909 }
910 }
911
912 static char *
913 gldppcmacos_get_script(isfile)
914 int *isfile;
915 {
916 *isfile = 0;
917
918 if (link_info.relocateable == true && config.build_constructors == true)
919 return
920 "OUTPUT_FORMAT(\"xcoff-powermac\")\n\
921 OUTPUT_ARCH(powerpc)\n\
922 ENTRY(__start)\n\
923 SECTIONS\n\
924 {\n\
925 .pad 0 : { *(.pad) }\n\
926 .text 0 : {\n\
927 *(.text)\n\
928 *(.pr)\n\
929 *(.ro)\n\
930 *(.db)\n\
931 *(.gl)\n\
932 *(.xo)\n\
933 *(.ti)\n\
934 *(.tb)\n\
935 }\n\
936 .data 0 : {\n\
937 *(.data)\n\
938 *(.rw)\n\
939 *(.sv)\n\
940 *(.ua)\n\
941 . = ALIGN(4);\n\
942 CONSTRUCTORS\n\
943 *(.ds)\n\
944 *(.tc0)\n\
945 *(.tc)\n\
946 *(.td)\n\
947 }\n\
948 .bss : {\n\
949 *(.bss)\n\
950 *(.bs)\n\
951 *(.uc)\n\
952 *(COMMON)\n\
953 }\n\
954 .loader 0 : {\n\
955 *(.loader)\n\
956 }\n\
957 .debug 0 : {\n\
958 *(.debug)\n\
959 }\n\
960 }\n\n"
961 ; else if (link_info.relocateable == true) return
962 "OUTPUT_FORMAT(\"xcoff-powermac\")\n\
963 OUTPUT_ARCH(powerpc)\n\
964 ENTRY(__start)\n\
965 SECTIONS\n\
966 {\n\
967 .pad 0 : { *(.pad) }\n\
968 .text 0 : {\n\
969 *(.text)\n\
970 *(.pr)\n\
971 *(.ro)\n\
972 *(.db)\n\
973 *(.gl)\n\
974 *(.xo)\n\
975 *(.ti)\n\
976 *(.tb)\n\
977 }\n\
978 .data 0 : {\n\
979 *(.data)\n\
980 *(.rw)\n\
981 *(.sv)\n\
982 *(.ua)\n\
983 . = ALIGN(4);\n\
984 *(.ds)\n\
985 *(.tc0)\n\
986 *(.tc)\n\
987 *(.td)\n\
988 }\n\
989 .bss : {\n\
990 *(.bss)\n\
991 *(.bs)\n\
992 *(.uc)\n\
993 *(COMMON)\n\
994 }\n\
995 .loader 0 : {\n\
996 *(.loader)\n\
997 }\n\
998 .debug 0 : {\n\
999 *(.debug)\n\
1000 }\n\
1001 }\n\n"
1002 ; else if (!config.text_read_only) return
1003 "OUTPUT_FORMAT(\"xcoff-powermac\")\n\
1004 OUTPUT_ARCH(powerpc)\n\
1005 SEARCH_DIR(/usr/local/powerpc-apple-macos/lib);\n\
1006 ENTRY(__start)\n\
1007 SECTIONS\n\
1008 {\n\
1009 .pad 0 : { *(.pad) }\n\
1010 .text : {\n\
1011 PROVIDE (_text = .);\n\
1012 *(.text)\n\
1013 *(.pr)\n\
1014 *(.ro)\n\
1015 *(.db)\n\
1016 *(.gl)\n\
1017 *(.xo)\n\
1018 *(.ti)\n\
1019 *(.tb)\n\
1020 PROVIDE (_etext = .);\n\
1021 }\n\
1022 .data 0 : {\n\
1023 PROVIDE (_data = .);\n\
1024 *(.data)\n\
1025 *(.rw)\n\
1026 *(.sv)\n\
1027 *(.ua)\n\
1028 . = ALIGN(4);\n\
1029 CONSTRUCTORS\n\
1030 *(.ds)\n\
1031 *(.tc0)\n\
1032 *(.tc)\n\
1033 *(.td)\n\
1034 PROVIDE (_edata = .);\n\
1035 }\n\
1036 .bss : {\n\
1037 *(.bss)\n\
1038 *(.bs)\n\
1039 *(.uc)\n\
1040 *(COMMON)\n\
1041 PROVIDE (_end = .);\n\
1042 PROVIDE (end = .);\n\
1043 }\n\
1044 .loader 0 : {\n\
1045 *(.loader)\n\
1046 }\n\
1047 .debug 0 : {\n\
1048 *(.debug)\n\
1049 }\n\
1050 }\n\n"
1051 ; else if (!config.magic_demand_paged) return
1052 "OUTPUT_FORMAT(\"xcoff-powermac\")\n\
1053 OUTPUT_ARCH(powerpc)\n\
1054 SEARCH_DIR(/usr/local/powerpc-apple-macos/lib);\n\
1055 ENTRY(__start)\n\
1056 SECTIONS\n\
1057 {\n\
1058 .pad 0 : { *(.pad) }\n\
1059 .text : {\n\
1060 PROVIDE (_text = .);\n\
1061 *(.text)\n\
1062 *(.pr)\n\
1063 *(.ro)\n\
1064 *(.db)\n\
1065 *(.gl)\n\
1066 *(.xo)\n\
1067 *(.ti)\n\
1068 *(.tb)\n\
1069 PROVIDE (_etext = .);\n\
1070 }\n\
1071 .data 0 : {\n\
1072 PROVIDE (_data = .);\n\
1073 *(.data)\n\
1074 *(.rw)\n\
1075 *(.sv)\n\
1076 *(.ua)\n\
1077 . = ALIGN(4);\n\
1078 CONSTRUCTORS\n\
1079 *(.ds)\n\
1080 *(.tc0)\n\
1081 *(.tc)\n\
1082 *(.td)\n\
1083 PROVIDE (_edata = .);\n\
1084 }\n\
1085 .bss : {\n\
1086 *(.bss)\n\
1087 *(.bs)\n\
1088 *(.uc)\n\
1089 *(COMMON)\n\
1090 PROVIDE (_end = .);\n\
1091 PROVIDE (end = .);\n\
1092 }\n\
1093 .loader 0 : {\n\
1094 *(.loader)\n\
1095 }\n\
1096 .debug 0 : {\n\
1097 *(.debug)\n\
1098 }\n\
1099 }\n\n"
1100 ; else return
1101 "OUTPUT_FORMAT(\"xcoff-powermac\")\n\
1102 OUTPUT_ARCH(powerpc)\n\
1103 SEARCH_DIR(/usr/local/powerpc-apple-macos/lib);\n\
1104 ENTRY(__start)\n\
1105 SECTIONS\n\
1106 {\n\
1107 .pad 0 : { *(.pad) }\n\
1108 .text : {\n\
1109 PROVIDE (_text = .);\n\
1110 *(.text)\n\
1111 *(.pr)\n\
1112 *(.ro)\n\
1113 *(.db)\n\
1114 *(.gl)\n\
1115 *(.xo)\n\
1116 *(.ti)\n\
1117 *(.tb)\n\
1118 PROVIDE (_etext = .);\n\
1119 }\n\
1120 .data 0 : {\n\
1121 PROVIDE (_data = .);\n\
1122 *(.data)\n\
1123 *(.rw)\n\
1124 *(.sv)\n\
1125 *(.ua)\n\
1126 . = ALIGN(4);\n\
1127 CONSTRUCTORS\n\
1128 *(.ds)\n\
1129 *(.tc0)\n\
1130 *(.tc)\n\
1131 *(.td)\n\
1132 PROVIDE (_edata = .);\n\
1133 }\n\
1134 .bss : {\n\
1135 *(.bss)\n\
1136 *(.bs)\n\
1137 *(.uc)\n\
1138 *(COMMON)\n\
1139 PROVIDE (_end = .);\n\
1140 PROVIDE (end = .);\n\
1141 }\n\
1142 .loader 0 : {\n\
1143 *(.loader)\n\
1144 }\n\
1145 .debug 0 : {\n\
1146 *(.debug)\n\
1147 }\n\
1148 }\n\n"
1149 ; }
1150
1151 struct ld_emulation_xfer_struct ld_ppcmacos_emulation =
1152 {
1153 gldppcmacos_before_parse,
1154 syslib_default,
1155 hll_default,
1156 after_parse_default,
1157 gldppcmacos_after_open,
1158 after_allocation_default,
1159 set_output_arch_default,
1160 ldemul_default_target,
1161 gldppcmacos_before_allocation,
1162 gldppcmacos_get_script,
1163 "ppcmacos",
1164 "xcoff-powermac",
1165 0, /* finish */
1166 0, /* create_output_section_statements */
1167 0, /* open_dynamic_archive */
1168 0, /* place_orphan */
1169 0, /* set_symbols */
1170 gldppcmacos_parse_args,
1171 };
This page took 0.054606 seconds and 4 git commands to generate.