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 part of GLD, the Gnu Linker.
5 Copyright 1995, 96, 97, 1998 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* The original file generated returned different default scripts depending
23 on whether certain switches were set, but these switches pertain to the
24 Linux system and that particular version of coff. In the NT case, we
25 only determine if the subsystem is console or windows in order to select
26 the correct entry point by default. */
32 #include "libiberty.h"
43 #include "coff/internal.h"
44 #include "../bfd/libcoff.h"
47 #define TARGET_IS_${EMULATION_NAME}
49 static void gld_${EMULATION_NAME}_set_symbols PARAMS ((void));
50 static void gld_${EMULATION_NAME}_after_open PARAMS ((void));
51 static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
52 static void gld_${EMULATION_NAME}_after_parse PARAMS ((void));
53 static void gld_${EMULATION_NAME}_before_allocation PARAMS ((void));
54 static boolean gld_${EMULATION_NAME}_place_orphan
55 PARAMS ((lang_input_statement_type *, asection *));
56 static void gld${EMULATION_NAME}_place_section
57 PARAMS ((lang_statement_union_type *));
58 static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
59 static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
61 static struct internal_extra_pe_aouthdr pe;
63 static int support_old_code = 0;
64 def_file *pe_def_file = 0;
65 static lang_assignment_statement_type *image_base_statement = 0;
67 static char *pe_out_def_filename = 0;
68 int pe_dll_export_everything = 0;
69 int pe_dll_do_default_excludes = 1;
70 int pe_dll_kill_ats = 0;
71 int pe_dll_stdcall_aliases = 0;
73 extern const char *output_filename;
76 gld_${EMULATION_NAME}_before_parse()
78 output_filename = "a.exe";
79 ldfile_output_architecture = bfd_arch_${ARCH};
80 #ifdef TARGET_IS_i386pe
81 config.has_shared = 1;
85 /* PE format extra command line options. */
87 /* Used for setting flags in the PE header. */
88 #define OPTION_BASE_FILE (300 + 1)
89 #define OPTION_DLL (OPTION_BASE_FILE + 1)
90 #define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1)
91 #define OPTION_IMAGE_BASE (OPTION_FILE_ALIGNMENT + 1)
92 #define OPTION_MAJOR_IMAGE_VERSION (OPTION_IMAGE_BASE + 1)
93 #define OPTION_MAJOR_OS_VERSION (OPTION_MAJOR_IMAGE_VERSION + 1)
94 #define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1)
95 #define OPTION_MINOR_IMAGE_VERSION (OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
96 #define OPTION_MINOR_OS_VERSION (OPTION_MINOR_IMAGE_VERSION + 1)
97 #define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
98 #define OPTION_SECTION_ALIGNMENT (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
99 #define OPTION_STACK (OPTION_SECTION_ALIGNMENT + 1)
100 #define OPTION_SUBSYSTEM (OPTION_STACK + 1)
101 #define OPTION_HEAP (OPTION_SUBSYSTEM + 1)
102 #define OPTION_SUPPORT_OLD_CODE (OPTION_HEAP + 1)
103 #define OPTION_OUT_DEF (OPTION_SUPPORT_OLD_CODE + 1)
104 #define OPTION_EXPORT_ALL (OPTION_OUT_DEF + 1)
105 #define OPTION_EXCLUDE_SYMBOLS (OPTION_EXPORT_ALL + 1)
106 #define OPTION_KILL_ATS (OPTION_EXCLUDE_SYMBOLS + 1)
107 #define OPTION_STDCALL_ALIASES (OPTION_KILL_ATS + 1)
109 static struct option longopts[] =
112 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
113 {"dll", no_argument, NULL, OPTION_DLL},
114 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
115 {"heap", required_argument, NULL, OPTION_HEAP},
116 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
117 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
118 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
119 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
120 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
121 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
122 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
123 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
124 {"stack", required_argument, NULL, OPTION_STACK},
125 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
126 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
127 /* getopt allows abbreviations, so we do this to stop it from treating -o
128 as an abbreviation for this option */
129 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
130 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
131 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
132 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
133 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
134 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
135 {NULL, no_argument, NULL, 0}
139 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
140 parameters which may be input from the command line */
151 #define D(field,symbol,def) {&pe.field,sizeof(pe.field), def, symbol,0}
153 static definfo init[] =
155 /* imagebase must be first */
156 #define IMAGEBASEOFF 0
157 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE),
159 {&dll, sizeof(dll), 0, "__dll__"},
160 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),
161 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
162 D(MajorOperatingSystemVersion,"__major_os_version__", 4),
163 D(MinorOperatingSystemVersion,"__minor_os_version__", 0),
164 D(MajorImageVersion,"__major_image_version__", 1),
165 D(MinorImageVersion,"__minor_image_version__", 0),
166 D(MajorSubsystemVersion,"__major_subsystem_version__", 4),
167 D(MinorSubsystemVersion,"__minor_subsystem_version__", 0),
168 D(Subsystem,"__subsystem__", 3),
169 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x2000000),
170 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000),
171 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000),
172 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000),
173 D(LoaderFlags,"__loader_flags__", 0x0),
174 { NULL, 0, 0, NULL, 0 }
178 gld_${EMULATION_NAME}_list_options (file)
181 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
182 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
183 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
184 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
185 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
186 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
187 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
188 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
189 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
190 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
191 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
192 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
193 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
194 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
195 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
199 set_pe_name (name, val)
204 /* Find the name and set it. */
205 for (i = 0; init[i].ptr; i++)
207 if (strcmp (name, init[i].symbol) == 0)
232 { "native", 1, "_NtProcessStartup" },
233 { "windows", 2, "_WinMainCRTStartup" },
234 { "console", 3, "_mainCRTStartup" },
236 /* The Microsoft linker does not recognize this. */
239 { "posix", 7, "___PosixProcessStartup"},
243 sver = strchr (optarg, ':');
245 len = strlen (optarg);
251 set_pe_name ("__major_subsystem_version__",
252 strtoul (sver + 1, &end, 0));
254 set_pe_name ("__minor_subsystem_version__",
255 strtoul (end + 1, &end, 0));
257 einfo (_("%P: warning: bad version number in -subsystem option\n"));
260 for (i = 0; v[i].name; i++)
262 if (strncmp (optarg, v[i].name, len) == 0
263 && v[i].name[len] == '\0')
265 set_pe_name ("__subsystem__", v[i].value);
267 lang_add_entry (v[i].entry, 1);
273 einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
285 set_pe_name (name, strtoul (optarg, &end, 0));
288 einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
294 set_pe_stack_heap (resname, comname)
298 set_pe_value (resname);
303 set_pe_value (comname);
306 einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
312 gld_${EMULATION_NAME}_parse_args(argc, argv)
318 int prevoptind = optind;
319 int prevopterr = opterr;
321 static int lastoptind = -1;
323 if (lastoptind != optind)
329 optc = getopt_long_only (argc, argv, "-", longopts, &longind);
340 case OPTION_BASE_FILE:
341 link_info.base_file = (PTR) fopen (optarg, FOPEN_WB);
342 if (link_info.base_file == NULL)
344 /* xgettext:c-format */
345 fprintf (stderr, _("%s: Can't open base file %s\n"),
346 program_name, optarg);
353 set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
356 set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
358 case OPTION_SUBSYSTEM:
361 case OPTION_MAJOR_OS_VERSION:
362 set_pe_value ("__major_os_version__");
364 case OPTION_MINOR_OS_VERSION:
365 set_pe_value ("__minor_os_version__");
367 case OPTION_MAJOR_SUBSYSTEM_VERSION:
368 set_pe_value ("__major_subsystem_version__");
370 case OPTION_MINOR_SUBSYSTEM_VERSION:
371 set_pe_value ("__minor_subsystem_version__");
373 case OPTION_MAJOR_IMAGE_VERSION:
374 set_pe_value ("__major_image_version__");
376 case OPTION_MINOR_IMAGE_VERSION:
377 set_pe_value ("__minor_image_version__");
379 case OPTION_FILE_ALIGNMENT:
380 set_pe_value ("__file_alignment__");
382 case OPTION_SECTION_ALIGNMENT:
383 set_pe_value ("__section_alignment__");
386 set_pe_name ("__dll__", 1);
388 case OPTION_IMAGE_BASE:
389 set_pe_value ("__image_base__");
391 case OPTION_SUPPORT_OLD_CODE:
392 support_old_code = 1;
395 pe_out_def_filename = xstrdup (optarg);
397 case OPTION_EXPORT_ALL:
398 pe_dll_export_everything = 1;
400 case OPTION_EXCLUDE_SYMBOLS:
401 pe_dll_add_excludes (optarg);
403 case OPTION_KILL_ATS:
406 case OPTION_STDCALL_ALIASES:
407 pe_dll_stdcall_aliases = 1;
413 /* Assign values to the special symbols before the linker script is
417 gld_${EMULATION_NAME}_set_symbols ()
419 /* Run through and invent symbols for all the
420 names and insert the defaults. */
422 lang_statement_list_type *save;
424 if (!init[IMAGEBASEOFF].inited)
426 if (link_info.relocateable)
427 init[IMAGEBASEOFF].value = 0;
428 else if (init[DLLOFF].value || link_info.shared)
429 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
431 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
434 /* Don't do any symbol assignments if this is a relocateable link. */
435 if (link_info.relocateable)
438 /* Glue the assignments into the abs section */
441 stat_ptr = &(abs_output_section->children);
443 for (j = 0; init[j].ptr; j++)
445 long val = init[j].value;
446 lang_assignment_statement_type *rv;
447 rv = lang_add_assignment (exp_assop ('=' ,init[j].symbol, exp_intop (val)));
448 if (init[j].size == sizeof(short))
449 *(short *)init[j].ptr = val;
450 else if (init[j].size == sizeof(int))
451 *(int *)init[j].ptr = val;
452 else if (init[j].size == sizeof(long))
453 *(long *)init[j].ptr = val;
454 /* This might be a long long or other special type. */
455 else if (init[j].size == sizeof(bfd_vma))
456 *(bfd_vma *)init[j].ptr = val;
458 if (j == IMAGEBASEOFF)
459 image_base_statement = rv;
461 /* Restore the pointer. */
464 if (pe.FileAlignment >
467 einfo (_("%P: warning, file alignment > section alignment.\n"));
471 /* This is called after the linker script and the command line options
475 gld_${EMULATION_NAME}_after_parse ()
477 /* The Windows libraries are designed for the linker to treat the
478 entry point as an undefined symbol. Otherwise, the .obj that
479 defines mainCRTStartup is brought in because it is the first
480 encountered in libc.lib and it has other symbols in it which will
481 be pulled in by the link process. To avoid this, we act as
482 though the user specified -u with the entry point symbol.
484 This function is called after the linker script and command line
485 options have been read, so at this point we know the right entry
486 point. This function is called before the input files are
487 opened, so registering the symbol as undefined will make a
490 ldlang_add_undef (entry_symbol);
493 static struct bfd_link_hash_entry *pe_undef_found_sym;
496 pe_undef_cdecl_match (h, string)
497 struct bfd_link_hash_entry *h;
500 int sl = strlen (string);
501 if (h->type == bfd_link_hash_defined
502 && strncmp (h->root.string, string, sl) == 0
503 && h->root.string[sl] == '@')
505 pe_undef_found_sym = h;
514 struct bfd_link_hash_entry *undef, *sym;
516 for (undef = link_info.hash->undefs; undef; undef=undef->next)
517 if (undef->type == bfd_link_hash_undefined)
519 at = strchr (undef->root.string, '@');
522 /* The symbol is a stdcall symbol, so let's look for a cdecl
523 symbol with the same name and resolve to that */
524 char *cname = xstrdup (undef->root.string);
525 at = strchr (cname, '@');
527 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
528 if (sym && sym->type == bfd_link_hash_defined)
530 undef->type = bfd_link_hash_defined;
531 undef->u.def.value = sym->u.def.value;
532 undef->u.def.section = sym->u.def.section;
537 /* The symbol is a cdecl symbol, so we don't look for stdcall
538 symbols - you should have included the right header */
539 pe_undef_found_sym = 0;
540 bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match,
541 (PTR) undef->root.string);
542 sym = pe_undef_found_sym;
545 undef->type = bfd_link_hash_defined;
546 undef->u.def.value = sym->u.def.value;
547 undef->u.def.section = sym->u.def.section;
554 gld_${EMULATION_NAME}_after_open ()
556 /* Pass the wacky PE command line options into the output bfd.
557 FIXME: This should be done via a function, rather than by
558 including an internal BFD header. */
560 if (!coff_data (output_bfd)->pe)
561 einfo (_("%F%P: PE operations on non PE file.\n"));
563 pe_data (output_bfd)->pe_opthdr = pe;
564 pe_data (output_bfd)->dll = init[DLLOFF].value;
566 pe_fixup_stdcalls ();
568 #ifdef TARGET_IS_i386pe
569 if (link_info.shared)
570 pe_dll_build_sections (output_bfd, &link_info);
573 #ifdef TARGET_IS_armpe
575 /* Find a BFD that can hold the interworking stubs. */
576 LANG_FOR_EACH_INPUT_STATEMENT (is)
578 if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info))
586 gld_${EMULATION_NAME}_before_allocation()
588 #ifdef TARGET_IS_ppcpe
589 /* Here we rummage through the found bfds to collect toc information */
591 LANG_FOR_EACH_INPUT_STATEMENT (is)
593 if (!ppc_process_before_allocation (is->the_bfd, &link_info))
595 /* xgettext:c-format */
596 einfo (_("Errors encountered processing file %s\n"), is->filename);
601 /* We have seen it all. Allocate it, and carry on */
602 ppc_allocate_toc_section (&link_info);
603 #endif /* TARGET_IS_ppcpe */
605 #ifdef TARGET_IS_armpe
606 /* FIXME: we should be able to set the size of the interworking stub
609 Here we rummage through the found bfds to collect glue
610 information. FIXME: should this be based on a command line
611 option? krk@cygnus.com */
613 LANG_FOR_EACH_INPUT_STATEMENT (is)
615 if (! bfd_arm_process_before_allocation
616 (is->the_bfd, & link_info, support_old_code))
618 /* xgettext:c-format */
619 einfo (_("Errors encountered processing file %s for interworking"),
625 /* We have seen it all. Allocate it, and carry on */
626 bfd_arm_allocate_interworking_sections (& link_info);
627 #endif /* TARGET_IS_armpe */
631 /* This is called when an input file isn't recognized as a BFD. We
632 check here for .DEF files and pull them in automatically. */
635 saw_option(char *option)
638 for (i=0; init[i].ptr; i++)
639 if (strcmp (init[i].symbol, option) == 0)
640 return init[i].inited;
645 gld_${EMULATION_NAME}_unrecognized_file(entry)
646 lang_input_statement_type *entry;
648 #ifdef TARGET_IS_i386pe
649 const char *ext = entry->filename + strlen (entry->filename) - 4;
651 if (strcmp (ext, ".def") == 0 || strcmp (ext, ".DEF") == 0)
653 if (pe_def_file == 0)
654 pe_def_file = def_file_empty ();
655 def_file_parse (entry->filename, pe_def_file);
658 /* def_file_print (stdout, pe_def_file); */
659 if (pe_def_file->is_dll == 1)
660 link_info.shared = 1;
662 if (pe_def_file->base_address != (bfd_vma)(-1))
665 pe_data (output_bfd)->pe_opthdr.ImageBase =
666 init[IMAGEBASEOFF].value = pe_def_file->base_address;
667 init[IMAGEBASEOFF].inited = 1;
668 if (image_base_statement)
669 image_base_statement->exp =
670 exp_assop ('=', "__image_base__", exp_intop (pe.ImageBase));
674 /* Not sure if these *should* be set */
675 if (pe_def_file->version_major != -1)
677 pe.MajorImageVersion = pe_def_file->version_major;
678 pe.MinorImageVersion = pe_def_file->version_minor;
681 if (pe_def_file->stack_reserve != -1
682 && ! saw_option ("__size_of_stack_reserve__"))
684 pe.SizeOfStackReserve = pe_def_file->stack_reserve;
685 if (pe_def_file->stack_commit != -1)
686 pe.SizeOfStackCommit = pe_def_file->stack_commit;
688 if (pe_def_file->heap_reserve != -1
689 && ! saw_option ("__size_of_heap_reserve__"))
691 pe.SizeOfHeapReserve = pe_def_file->heap_reserve;
692 if (pe_def_file->heap_commit != -1)
693 pe.SizeOfHeapCommit = pe_def_file->heap_commit;
704 gld_${EMULATION_NAME}_finish ()
706 #ifdef TARGET_IS_i386pe
707 if (link_info.shared)
708 pe_dll_fill_sections (output_bfd, &link_info);
709 if (pe_out_def_filename)
710 pe_dll_generate_def_file (pe_out_def_filename);
715 /* Place an orphan section.
717 We use this to put sections in a reasonable place in the file, and
718 to ensure that they are aligned as required.
720 We handle grouped sections here as well. A section named .foo$nn
721 goes into the output section .foo. All grouped sections are sorted
724 Grouped sections for the default sections are handled by the
725 default linker script using wildcards, and are sorted by
728 static asection *hold_section;
729 static char *hold_section_name;
730 static lang_output_section_statement_type *hold_use;
731 static lang_output_section_statement_type *hold_text;
732 static lang_output_section_statement_type *hold_rdata;
733 static lang_output_section_statement_type *hold_data;
734 static lang_output_section_statement_type *hold_bss;
736 /* Place an orphan section. We use this to put random SHF_ALLOC
737 sections in the right segment. */
741 gld_${EMULATION_NAME}_place_orphan (file, s)
742 lang_input_statement_type *file;
748 if ((s->flags & SEC_ALLOC) == 0)
751 secname = bfd_get_section_name (s->owner, s);
753 /* Look through the script to see where to place this section. */
757 hold_section_name = xstrdup (secname);
758 dollar = strchr (hold_section_name, '$');
763 lang_for_each_statement (gld${EMULATION_NAME}_place_section);
765 if (hold_use == NULL)
767 lang_output_section_statement_type *place;
769 asection *snew, **pps;
770 lang_statement_list_type *old;
771 lang_statement_list_type add;
774 /* Try to put the new output section in a reasonable place based
775 on the section name and section flags. */
777 if ((s->flags & SEC_HAS_CONTENTS) == 0
780 else if ((s->flags & SEC_READONLY) == 0
781 && hold_data != NULL)
783 else if ((s->flags & SEC_CODE) == 0
784 && (s->flags & SEC_READONLY) != 0
785 && hold_rdata != NULL)
787 else if ((s->flags & SEC_READONLY) != 0
788 && hold_text != NULL)
791 /* Choose a unique name for the section. This will be needed if
792 the same section name appears in the input file with
793 different loadable or allocateable characteristics. */
794 outsecname = xstrdup (hold_section_name);
795 if (bfd_get_section_by_name (output_bfd, outsecname) != NULL)
801 len = strlen (outsecname);
802 newname = xmalloc (len + 5);
803 strcpy (newname, outsecname);
807 sprintf (newname + len, "%d", i);
810 while (bfd_get_section_by_name (output_bfd, newname) != NULL);
813 outsecname = newname;
816 /* We don't want to free OUTSECNAME, as it may get attached to
817 the output section statement. */
819 /* Create the section in the output file, and put it in the
820 right place. This shuffling is to make the output file look
822 snew = bfd_make_section (output_bfd, outsecname);
824 einfo ("%P%F: output format %s cannot represent section called %s\n",
825 output_bfd->xvec->name, outsecname);
826 if (place != NULL && place->bfd_section != NULL)
828 for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next)
831 snew->next = place->bfd_section->next;
832 place->bfd_section->next = snew;
835 /* Start building a list of statements for this section. */
838 lang_list_init (stat_ptr);
840 if (link_info.relocateable)
844 /* All sections in an executable must be aligned to a page
846 address = exp_unop (ALIGN_K,
847 exp_nameop (NAME, "__section_alignment__"));
850 lang_enter_output_section_statement (outsecname, address, 0,
854 (etree_type *) NULL);
856 hold_use = lang_output_section_statement_lookup (outsecname);
858 lang_leave_output_section_statement
859 ((bfd_vma) 0, "*default*",
860 (struct lang_output_section_phdr_list *) NULL);
862 /* Now stick the new statement list right after PLACE. */
865 *add.tail = place->header.next;
866 place->header.next = add.head;
873 wild_doit (&hold_use->children, s, hold_use, file);
876 lang_statement_union_type **pl;
877 boolean found_dollar;
878 lang_statement_list_type list;
880 /* The section name has a '$'. Sort it with the other '$'
883 found_dollar = false;
884 for (pl = &hold_use->children.head; *pl != NULL; pl = &(*pl)->next)
886 lang_input_section_type *ls;
889 if ((*pl)->header.type != lang_input_section_enum)
892 ls = &(*pl)->input_section;
894 lname = bfd_get_section_name (ls->ifile->the_bfd, ls->section);
895 if (strchr (lname, '$') == NULL)
903 if (strcmp (secname, lname) < 0)
908 lang_list_init (&list);
909 wild_doit (&list, s, hold_use, file);
910 if (list.head != NULL)
912 ASSERT (list.head->next == NULL);
913 list.head->next = *pl;
918 free (hold_section_name);
924 gld${EMULATION_NAME}_place_section (s)
925 lang_statement_union_type *s;
927 lang_output_section_statement_type *os;
929 if (s->header.type != lang_output_section_statement_enum)
932 os = &s->output_section_statement;
934 if (strcmp (os->name, hold_section_name) == 0
935 && os->bfd_section != NULL
936 && ((hold_section->flags & (SEC_LOAD | SEC_ALLOC))
937 == (os->bfd_section->flags & (SEC_LOAD | SEC_ALLOC))))
940 if (strcmp (os->name, ".text") == 0)
942 else if (strcmp (os->name, ".rdata") == 0)
944 else if (strcmp (os->name, ".data") == 0)
946 else if (strcmp (os->name, ".bss") == 0)
951 gld_${EMULATION_NAME}_get_script(isfile)
954 # Scripts compiled in.
955 # sed commands to quote an ld script as a C string.
956 sc="-f ${srcdir}/emultempl/stringify.sed"
958 cat >>e${EMULATION_NAME}.c <<EOF
962 if (link_info.relocateable == true && config.build_constructors == true)
965 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
966 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
967 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
968 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
969 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
970 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
971 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
972 echo ' ; else return' >> e${EMULATION_NAME}.c
973 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
974 echo '; }' >> e${EMULATION_NAME}.c
976 cat >>e${EMULATION_NAME}.c <<EOF
979 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
981 gld_${EMULATION_NAME}_before_parse,
984 gld_${EMULATION_NAME}_after_parse,
985 gld_${EMULATION_NAME}_after_open,
986 after_allocation_default,
987 set_output_arch_default,
988 ldemul_default_target,
989 gld_${EMULATION_NAME}_before_allocation,
990 gld_${EMULATION_NAME}_get_script,
993 gld_${EMULATION_NAME}_finish, /* finish */
994 NULL, /* create output section statements */
995 NULL, /* open dynamic archive */
996 gld_${EMULATION_NAME}_place_orphan,
997 gld_${EMULATION_NAME}_set_symbols,
998 gld_${EMULATION_NAME}_parse_args,
999 gld_${EMULATION_NAME}_unrecognized_file,
1000 gld_${EMULATION_NAME}_list_options