Update release readme after making 2.43.1 release
[binutils-gdb.git] / ld / emultempl / beos.em
blob29c386c61f8fdcf28db278262a2f376e435ae5c4
1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 if [ -z "$MACHINE" ]; then
4   OUTPUT_ARCH=${ARCH}
5 else
6   OUTPUT_ARCH=${ARCH}:${MACHINE}
7 fi
8 fragment <<EOF
9 /* This file is part of GLD, the Gnu Linker.
10    Copyright (C) 1995-2024 Free Software Foundation, Inc.
12    This file is part of the GNU Binutils.
14    This program is free software; you can redistribute it and/or modify
15    it under the terms of the GNU General Public License as published by
16    the Free Software Foundation; either version 3 of the License, or
17    (at your option) any later version.
19    This program is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22    GNU General Public License for more details.
24    You should have received a copy of the GNU General Public License
25    along with this program; if not, write to the Free Software
26    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
27    MA 02110-1301, USA.  */
30 /* For WINDOWS_NT */
31 /* The original file generated returned different default scripts depending
32    on whether certain switches were set, but these switches pertain to the
33    Linux system and that particular version of coff.  In the NT case, we
34    only determine if the subsystem is console or windows in order to select
35    the correct entry point by default. */
37 #include "sysdep.h"
38 #include "bfd.h"
39 #include "bfdlink.h"
40 #include "ctf-api.h"
41 #include "getopt.h"
42 #include "libiberty.h"
43 #include "filenames.h"
44 #include "ld.h"
45 #include "ldmain.h"
46 #include "ldexp.h"
47 #include "ldlang.h"
48 #include "ldfile.h"
49 #include "ldemul.h"
50 #include <ldgram.h>
51 #include "ldlex.h"
52 #include "ldmisc.h"
53 #include "ldctor.h"
54 #include "coff/internal.h"
55 #include "../bfd/libcoff.h"
57 #define TARGET_IS_${EMULATION_NAME}
59 static struct internal_extra_pe_aouthdr pe;
60 static int dll;
62 extern const char *output_filename;
64 static void
65 gld${EMULATION_NAME}_before_parse (void)
67   ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
68   output_filename = "a.exe";
71 /* PE format extra command line options.  */
73 static void
74 gld${EMULATION_NAME}_add_options
75   (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
76    struct option **longopts, int nrl ATTRIBUTE_UNUSED,
77    struct option **really_longopts ATTRIBUTE_UNUSED)
79   static const struct option xtra_long[] = {
80     /* PE options */
81     {"base-file", required_argument, NULL, OPTION_BASE_FILE},
82     {"dll", no_argument, NULL, OPTION_DLL},
83     {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
84     {"heap", required_argument, NULL, OPTION_HEAP},
85     {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
86     {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
87     {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
88     {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
89     {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
90     {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
91     {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
92     {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
93     {"stack", required_argument, NULL, OPTION_STACK},
94     {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
95     {NULL, no_argument, NULL, 0}
96   };
98   *longopts = (struct option *)
99     xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
100   memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
104 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
105    parameters which may be input from the command line */
107 typedef struct {
108   void *ptr;
109   int size;
110   int value;
111   char *symbol;
112   int inited;
113 } definfo;
115 #define D(field,symbol,def)  {&pe.field,sizeof(pe.field), def, symbol,0}
117 static definfo init[] =
119   /* imagebase must be first */
120 #define IMAGEBASEOFF 0
121   D(ImageBase,"__image_base__", BEOS_EXE_IMAGE_BASE),
122 #define DLLOFF 1
123   {&dll, sizeof(dll), 0, "__dll__", 0},
124   D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),
125   D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
126   D(MajorOperatingSystemVersion,"__major_os_version__", 4),
127   D(MinorOperatingSystemVersion,"__minor_os_version__", 0),
128   D(MajorImageVersion,"__major_image_version__", 1),
129   D(MinorImageVersion,"__minor_image_version__", 0),
130   D(MajorSubsystemVersion,"__major_subsystem_version__", 4),
131   D(MinorSubsystemVersion,"__minor_subsystem_version__", 0),
132   D(Subsystem,"__subsystem__", 3),
133   D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x2000000),
134   D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000),
135   D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000),
136   D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000),
137   D(LoaderFlags,"__loader_flags__", 0x0),
138   { NULL, 0, 0, NULL, 0 }
142 static void
143 set_pe_name (char *name, long val)
145   int i;
146   /* Find the name and set it. */
147   for (i = 0; init[i].ptr; i++)
148     {
149       if (strcmp (name, init[i].symbol) == 0)
150         {
151           init[i].value = val;
152           init[i].inited = 1;
153           return;
154         }
155     }
156   abort();
160 static void
161 set_pe_subsystem (void)
163   const char *sver;
164   int len;
165   int i;
166   static const struct
167     {
168       const char *name;
169       const int value;
170       const char *entry;
171     }
172   v[] =
173     {
174       { "native", 1, "_NtProcessStartup" },
175       { "windows", 2, "_WinMainCRTStartup" },
176       { "wwindows", 2, "_wWinMainCRTStartup" },
177       { "console", 3, "_mainCRTStartup" },
178       { "wconsole", 3, "_wmainCRTStartup" },
179       { "posix", 7, "___PosixProcessStartup"},
180       { 0, 0, 0 }
181     };
183   sver = strchr (optarg, ':');
184   if (sver == NULL)
185     len = strlen (optarg);
186   else
187     {
188       char *end;
190       len = sver - optarg;
191       set_pe_name ("__major_subsystem_version__",
192                    strtoul (sver + 1, &end, 0));
193       if (*end == '.')
194         set_pe_name ("__minor_subsystem_version__",
195                      strtoul (end + 1, &end, 0));
196       if (*end != '\0')
197         einfo (_("%P: warning: bad version number in -subsystem option\n"));
198     }
200   for (i = 0; v[i].name; i++)
201     {
202       if (strncmp (optarg, v[i].name, len) == 0
203           && v[i].name[len] == '\0')
204         {
205           set_pe_name ("__subsystem__", v[i].value);
207           /* If the subsystem is windows, we use a different entry
208              point.  */
209           lang_default_entry (v[i].entry);
211           return;
212         }
213     }
214   einfo (_("%F%P: invalid subsystem type %s\n"), optarg);
218 static void
219 set_pe_value (char *name)
221   char *end;
222   set_pe_name (name,  strtoul (optarg, &end, 0));
223   if (end == optarg)
224     {
225       einfo (_("%F%P: invalid hex number for PE parameter '%s'\n"), optarg);
226     }
228   optarg = end;
231 static void
232 set_pe_stack_heap (char *resname, char *comname)
234   set_pe_value (resname);
235   if (*optarg == ',')
236     {
237       optarg++;
238       set_pe_value (comname);
239     }
240   else if (*optarg)
241     {
242       einfo (_("%F%P: strange hex info for PE parameter '%s'\n"), optarg);
243     }
247 static bool
248 gld${EMULATION_NAME}_handle_option (int optc)
250   switch (optc)
251     {
252     default:
253       return false;
255     case OPTION_BASE_FILE:
256       link_info.base_file = fopen (optarg, FOPEN_WB);
257       if (link_info.base_file == NULL)
258         einfo (_("%F%P: cannot open base file %s\n"), optarg);
259       break;
261       /* PE options */
262     case OPTION_HEAP:
263       set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
264       break;
265     case OPTION_STACK:
266       set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
267       break;
268     case OPTION_SUBSYSTEM:
269       set_pe_subsystem ();
270       break;
271     case OPTION_MAJOR_OS_VERSION:
272       set_pe_value ("__major_os_version__");
273       break;
274     case OPTION_MINOR_OS_VERSION:
275       set_pe_value ("__minor_os_version__");
276       break;
277     case OPTION_MAJOR_SUBSYSTEM_VERSION:
278       set_pe_value ("__major_subsystem_version__");
279       break;
280     case OPTION_MINOR_SUBSYSTEM_VERSION:
281       set_pe_value ("__minor_subsystem_version__");
282       break;
283     case OPTION_MAJOR_IMAGE_VERSION:
284       set_pe_value ("__major_image_version__");
285       break;
286     case OPTION_MINOR_IMAGE_VERSION:
287       set_pe_value ("__minor_image_version__");
288       break;
289     case OPTION_FILE_ALIGNMENT:
290       set_pe_value ("__file_alignment__");
291       break;
292     case OPTION_SECTION_ALIGNMENT:
293       set_pe_value ("__section_alignment__");
294       break;
295     case OPTION_DLL:
296       set_pe_name ("__dll__", 1);
297       break;
298     case OPTION_IMAGE_BASE:
299       set_pe_value ("__image_base__");
300       break;
301     }
302   return true;
305 /* Assign values to the special symbols before the linker script is
306    read.  */
308 static void
309 gld${EMULATION_NAME}_set_symbols (void)
311   /* Run through and invent symbols for all the
312      names and insert the defaults. */
313   int j;
315   if (!init[IMAGEBASEOFF].inited)
316     {
317       if (bfd_link_relocatable (&link_info))
318         init[IMAGEBASEOFF].value = 0;
319       else if (init[DLLOFF].value)
320         init[IMAGEBASEOFF].value = BEOS_DLL_IMAGE_BASE;
321       else
322         init[IMAGEBASEOFF].value = BEOS_EXE_IMAGE_BASE;
323     }
325   /* Don't do any symbol assignments if this is a relocatable link.  */
326   if (bfd_link_relocatable (&link_info))
327     return;
329   /* Glue the assignments into the abs section */
330   push_stat_ptr (&abs_output_section->children);
332   for (j = 0; init[j].ptr; j++)
333     {
334       long val = init[j].value;
335       lang_add_assignment (exp_assign (init[j].symbol, exp_intop (val),
336                                        false));
337       if (init[j].size == sizeof(short))
338         *(short *)init[j].ptr = val;
339       else if (init[j].size == sizeof(int))
340         *(int *)init[j].ptr = val;
341       else if (init[j].size == sizeof(long))
342         *(long *)init[j].ptr = val;
343       /* This might be a long long or other special type.  */
344       else if (init[j].size == sizeof(bfd_vma))
345         *(bfd_vma *)init[j].ptr = val;
346       else      abort();
347     }
348   /* Restore the pointer. */
349   pop_stat_ptr ();
351   if (pe.FileAlignment >
352       pe.SectionAlignment)
353     {
354       einfo (_("%P: warning, file alignment > section alignment\n"));
355     }
358 static void
359 gld${EMULATION_NAME}_after_open (void)
361   after_open_default ();
363   /* Pass the wacky PE command line options into the output bfd.
364      FIXME: This should be done via a function, rather than by
365      including an internal BFD header.  */
366   if (!obj_pe (link_info.output_bfd))
367     {
368       einfo (_("%F%P: PE operations on non PE file\n"));
369     }
371   pe_data(link_info.output_bfd)->pe_opthdr = pe;
372   pe_data(link_info.output_bfd)->dll = init[DLLOFF].value;
376 /* Callback functions for qsort in sort_sections. */
378 static int
379 sort_by_file_name (const void *a, const void *b)
381   const lang_input_section_type *const *ra = a;
382   const lang_input_section_type *const *rb = b;
383   asection *sa = (*ra)->section;
384   asection *sb = (*rb)->section;
385   int i, a_sec, b_sec;
387   i = filename_cmp (bfd_get_filename (sa->owner->my_archive),
388                     bfd_get_filename (sb->owner->my_archive));
389   if (i != 0)
390     return i;
392   i = filename_cmp (bfd_get_filename (sa->owner),
393                     bfd_get_filename (sb->owner));
394   if (i != 0)
395     return i;
396   /* the tail idata4/5 are the only ones without relocs to an
397      idata$6 section unless we are importing by ordinal,
398      so sort them to last to terminate the IAT
399      and HNT properly. if no reloc this one is import by ordinal
400      so we have to sort by section contents */
402   if (sa->reloc_count + sb->reloc_count != 0)
403     {
404       i = sa->reloc_count > sb->reloc_count ? -1 : 0;
405       if (i != 0)
406         return i;
408       return sa->reloc_count > sb->reloc_count ? 0 : 1;
409     }
410   else
411     {
412       /* don't sort .idata$6 or .idata$7 FIXME dlltool eliminate .idata$7 */
413       if ((strcmp (sa->name, ".idata$6") == 0))
414         return 0;
416       if (!bfd_get_section_contents (sa->owner, sa, &a_sec, (file_ptr) 0,
417                                      (bfd_size_type) sizeof (a_sec)))
418         einfo (_("%F%P: %pB: can't read contents of section .idata: %E\n"),
419                sa->owner);
421       if (!bfd_get_section_contents (sb->owner, sb, &b_sec, (file_ptr) 0,
422                                      (bfd_size_type) sizeof (b_sec)))
423         einfo (_("%F%P: %pB: can't read contents of section .idata: %E\n"),
424                sb->owner);
426       i = a_sec < b_sec ? -1 : 0;
427       if (i != 0)
428         return i;
429       return a_sec < b_sec ? 0 : 1;
430     }
431   return 0;
434 static int
435 sort_by_section_name (const void *a, const void *b)
437   const lang_input_section_type *const *ra = a;
438   const lang_input_section_type *const *rb = b;
439   const char *sna = (*ra)->section->name;
440   const char *snb = (*rb)->section->name;
441   int i;
442   i = strcmp (sna, snb);
443   /* This is a hack to make .stab and .stabstr last, so we don't have
444      to fix strip/objcopy for .reloc sections.
445      FIXME stripping images with a .rsrc section still needs to be fixed.  */
446   if (i != 0)
447     {
448       if ((startswith (sna, ".stab"))
449           && (!startswith (snb, ".stab")))
450         return 1;
451     }
452   return i;
455 /* Subroutine of sort_sections to a contiguous subset of a list of sections.
456    NEXT_AFTER is the element after the last one to sort.
457    The result is a pointer to the last element's "next" pointer.  */
459 static lang_statement_union_type **
460 sort_sections_1 (lang_statement_union_type **startptr,
461                  lang_statement_union_type *next_after,
462                  int count,
463                  int (*sort_func) (const void *, const void *))
465   lang_statement_union_type **vec;
466   lang_statement_union_type *p;
467   int i;
468   lang_statement_union_type **ret;
470   if (count == 0)
471     return startptr;
473   vec = ((lang_statement_union_type **)
474          xmalloc (count * sizeof (lang_statement_union_type *)));
476   for (p = *startptr, i = 0; i < count; i++, p = p->header.next)
477     vec[i] = p;
479   qsort (vec, count, sizeof (vec[0]), sort_func);
481   /* Fill in the next pointers again. */
482   *startptr = vec[0];
483   for (i = 0; i < count - 1; i++)
484     vec[i]->header.next = vec[i + 1];
485   vec[i]->header.next = next_after;
486   ret = &vec[i]->header.next;
487   free (vec);
488   return ret;
491 /* Sort the .idata\$foo input sections of archives into filename order.
492    The reason is so dlltool can arrange to have the pe dll import information
493    generated correctly - the head of the list goes into dh.o, the tail into
494    dt.o, and the guts into ds[nnnn].o.  Note that this is only needed for the
495    .idata section.
496    FIXME: This may no longer be necessary with grouped sections.  Instead of
497    sorting on dh.o, ds[nnnn].o, dt.o, one could, for example, have dh.o use
498    .idata\$4h, have ds[nnnn].o use .idata\$4s[nnnn], and have dt.o use .idata\$4t.
499    This would have to be elaborated upon to handle multiple dll's
500    [assuming such an eloboration is possible of course].
502    We also sort sections in '\$' wild statements.  These are created by the
503    place_orphans routine to implement grouped sections.  */
505 static void
506 sort_sections (lang_statement_union_type *s)
508   for (; s ; s = s->header.next)
509     switch (s->header.type)
510       {
511       case lang_output_section_statement_enum:
512         sort_sections (s->output_section_statement.children.head);
513         break;
514       case lang_wild_statement_enum:
515         {
516           lang_statement_union_type **p = &s->wild_statement.children.head;
517           struct wildcard_list *sec;
519           for (sec = s->wild_statement.section_list; sec; sec = sec->next)
520             {
521               /* Is this the .idata section?  */
522               if (sec->spec.name != NULL
523                   && startswith (sec->spec.name, ".idata"))
524                 {
525                   /* Sort the children.  We want to sort any objects in
526                      the same archive.  In order to handle the case of
527                      including a single archive multiple times, we sort
528                      all the children by archive name and then by object
529                      name.  After sorting them, we re-thread the pointer
530                      chain.  */
532                   while (*p)
533                     {
534                       lang_statement_union_type *start = *p;
535                       if (start->header.type != lang_input_section_enum
536                           || !start->input_section.section->owner->my_archive)
537                         p = &(start->header.next);
538                       else
539                         {
540                           lang_statement_union_type *end;
541                           int count;
543                           for (end = start, count = 0;
544                                end && (end->header.type
545                                        == lang_input_section_enum);
546                                end = end->header.next)
547                             count++;
549                           p = sort_sections_1 (p, end, count,
550                                                sort_by_file_name);
551                         }
552                     }
553                   break;
554                 }
556               /* If this is a collection of grouped sections, sort them.
557                  The linker script must explicitly mention "*(.foo\$)" or
558                  "*(.foo\$*)".  Don't sort them if \$ is not the last
559                  character (not sure if this is really useful, but it
560                  allows explicitly mentioning some \$ sections and letting
561                  the linker handle the rest).  */
562               if (sec->spec.name != NULL)
563                 {
564                   char *q = strchr (sec->spec.name, '\$');
566                   if (q != NULL
567                       && (q[1] == '\0'
568                           || (q[1] == '*' && q[2] == '\0')))
569                     {
570                       lang_statement_union_type *end;
571                       int count;
573                       for (end = *p, count = 0; end; end = end->header.next)
574                         {
575                           if (end->header.type != lang_input_section_enum)
576                             abort ();
577                           count++;
578                         }
579                       (void) sort_sections_1 (p, end, count,
580                                               sort_by_section_name);
581                     }
582                   break;
583                 }
584             }
585         }
586         break;
587       default:
588         break;
589       }
592 static void
593 gld${EMULATION_NAME}_before_allocation (void)
595 #ifdef TARGET_IS_armpe
596   /* FIXME: we should be able to set the size of the interworking stub
597      section.
599      Here we rummage through the found bfds to collect glue
600      information.  FIXME: should this be based on a command line
601      option?  krk@cygnus.com */
602   {
603     LANG_FOR_EACH_INPUT_STATEMENT (is)
604     {
605       if (!arm_process_before_allocation (is->the_bfd, & link_info))
606         {
607           einfo (_("%P: errors encountered processing file %s\n"),
608                  is->filename);
609         }
610     }
611   }
613   /* We have seen it all. Allocate it, and carry on */
614   arm_allocate_interworking_sections (& link_info);
615 #endif /* TARGET_IS_armpe */
617   sort_sections (stat_ptr->head);
619   before_allocation_default ();
622 /* Place an orphan section.  We use this to put sections with a '\$' in them
623    into the right place.  Any section with a '\$' in them (e.g. .text\$foo)
624    gets mapped to the output section with everything from the '\$' on stripped
625    (e.g. .text).
626    See the Microsoft Portable Executable and Common Object File Format
627    Specification 4.1, section 4.2, Grouped Sections.
629    FIXME: This is now handled by the linker script using wildcards,
630    but I'm leaving this here in case we want to enable it for sections
631    which are not mentioned in the linker script.  */
633 static lang_output_section_statement_type *
634 gld${EMULATION_NAME}_place_orphan (asection *s,
635                                    const char *secname,
636                                    int constraint)
638   char *output_secname, *ps;
639   lang_output_section_statement_type *os;
640   lang_statement_union_type *l;
642   if ((s->flags & SEC_ALLOC) == 0)
643     return NULL;
645   /* Don't process grouped sections unless doing a final link.
646      If they're marked as COMDAT sections, we don't want .text\$foo to
647      end up in .text and then have .text disappear because it's marked
648      link-once-discard.  */
649   if (bfd_link_relocatable (&link_info))
650     return NULL;
652   /* Everything from the '\$' on gets deleted so don't allow '\$' as the
653      first character.  */
654   if (*secname == '\$')
655     einfo (_("%F%P: section %s has '\$' as first character\n"), secname);
656   if (strchr (secname + 1, '\$') == NULL)
657     return NULL;
659   /* Look up the output section.  The Microsoft specs say sections names in
660      image files never contain a '\$'.  Fortunately, lang_..._lookup creates
661      the section if it doesn't exist.  */
662   output_secname = xstrdup (secname);
663   ps = strchr (output_secname + 1, '\$');
664   *ps = 0;
665   os = lang_output_section_statement_lookup (output_secname, constraint, true);
667   /* Find the '\$' wild statement for this section.  We currently require the
668      linker script to explicitly mention "*(.foo\$)".  */
670   ps[0] = '\$';
671   ps[1] = 0;
672   for (l = os->children.head; l; l = l->header.next)
673     if (l->header.type == lang_wild_statement_enum)
674       {
675         struct wildcard_list *sec;
677         for (sec = l->wild_statement.section_list; sec; sec = sec->next)
678           if (sec->spec.name && strcmp (sec->spec.name, output_secname) == 0)
679             break;
680         if (sec)
681           break;
682       }
683   ps[0] = 0;
684   if (l == NULL)
685     einfo (_("%F%P: *(%s\$) missing from linker script\n"), output_secname);
687   /* Link the input section in and we're done for now.
688      The sections still have to be sorted, but that has to wait until
689      all such sections have been processed by us.  The sorting is done by
690      sort_sections.  */
691   lang_add_section (&l->wild_statement.children, s, NULL, NULL, os);
693   return os;
696 static char *
697 gld${EMULATION_NAME}_get_script (int *isfile)
700 if test x"$COMPILE_IN" = xyes
701 then
702 # Scripts compiled in.
704 # sed commands to quote an ld script as a C string.
705 sc="-f ${srcdir}/emultempl/stringify.sed"
707 fragment <<EOF
709   *isfile = 0;
711   if (bfd_link_relocatable (&link_info) && config.build_constructors)
712     return
714 sed $sc ldscripts/${EMULATION_NAME}.xu                 >> e${EMULATION_NAME}.c
715 echo '  ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
716 sed $sc ldscripts/${EMULATION_NAME}.xr                 >> e${EMULATION_NAME}.c
717 echo '  ; else if (!config.text_read_only) return'     >> e${EMULATION_NAME}.c
718 sed $sc ldscripts/${EMULATION_NAME}.xbn                >> e${EMULATION_NAME}.c
719 echo '  ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
720 sed $sc ldscripts/${EMULATION_NAME}.xn                 >> e${EMULATION_NAME}.c
721 echo '  ; else return'                                 >> e${EMULATION_NAME}.c
722 sed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
723 echo '; }'                                             >> e${EMULATION_NAME}.c
725 else
726 # Scripts read from the filesystem.
728 fragment <<EOF
730   *isfile = 1;
732   if (bfd_link_relocatable (&link_info) && config.build_constructors)
733     return "ldscripts/${EMULATION_NAME}.xu";
734   else if (bfd_link_relocatable (&link_info))
735     return "ldscripts/${EMULATION_NAME}.xr";
736   else if (!config.text_read_only)
737     return "ldscripts/${EMULATION_NAME}.xbn";
738   else if (!config.magic_demand_paged)
739     return "ldscripts/${EMULATION_NAME}.xn";
740   else
741     return "ldscripts/${EMULATION_NAME}.x";
746 LDEMUL_AFTER_OPEN=gld${EMULATION_NAME}_after_open
747 LDEMUL_BEFORE_ALLOCATION=gld${EMULATION_NAME}_before_allocation
748 LDEMUL_PLACE_ORPHAN=gld${EMULATION_NAME}_place_orphan
749 LDEMUL_SET_SYMBOLS=gld${EMULATION_NAME}_set_symbols
750 LDEMUL_ADD_OPTIONS=gld${EMULATION_NAME}_add_options
751 LDEMUL_HANDLE_OPTION=gld${EMULATION_NAME}_handle_option
753 source_em ${srcdir}/emultempl/emulation.em