Accept 16-bit addresses.
[deliverable/binutils-gdb.git] / ld / emultempl / pe.em
CommitLineData
252b5132
RH
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
361d94e7
ILT
3rm -f e${EMULATION_NAME}.c
4(echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
c6c37250 5cat >>e${EMULATION_NAME}.c <<EOF
252b5132 6/* This file is part of GLD, the Gnu Linker.
870df5dc 7 Copyright 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
252b5132
RH
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
23/* For WINDOWS_NT */
24/* The original file generated returned different default scripts depending
25 on whether certain switches were set, but these switches pertain to the
26 Linux system and that particular version of coff. In the NT case, we
27 only determine if the subsystem is console or windows in order to select
28 the correct entry point by default. */
29
30#include "bfd.h"
31#include "sysdep.h"
32#include "bfdlink.h"
33#include "getopt.h"
34#include "libiberty.h"
35#include "ld.h"
36#include "ldmain.h"
37#include "ldgram.h"
38#include "ldexp.h"
39#include "ldlang.h"
40#include "ldemul.h"
41#include "ldlex.h"
42#include "ldmisc.h"
43#include "ldctor.h"
44#include "ldfile.h"
45#include "coff/internal.h"
71add731
ILT
46
47/* FIXME: This is a BFD internal header file, and we should not be
48 using it here. */
252b5132 49#include "../bfd/libcoff.h"
71add731 50
252b5132 51#include "deffile.h"
1069dd8d 52#include "pe-dll.h"
252b5132
RH
53
54#define TARGET_IS_${EMULATION_NAME}
55
2be9b2c7
ILT
56/* Permit the emulation parameters to override the default section
57 alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
58 it seem that include/coff/internal.h should not define
59 PE_DEF_SECTION_ALIGNMENT. */
60#if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
61#undef PE_DEF_SECTION_ALIGNMENT
62#define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
63#endif
64
c6c37250
DD
65#if defined(TARGET_IS_i386pe)
66#define DLL_SUPPORT
67#endif
68
69#define PE_DEF_SUBSYSTEM 3
70
434d1125
NC
71#ifdef TARGET_IS_arm_epoc_pe
72#define bfd_arm_pe_allocate_interworking_sections \
73 bfd_arm_epoc_pe_allocate_interworking_sections
74#define bfd_arm_pe_get_bfd_for_interworking \
75 bfd_arm_epoc_pe_get_bfd_for_interworking
76#define bfd_arm_pe_process_before_allocation \
77 bfd_arm_epoc_pe_process_before_allocation
78#endif
79
252b5132
RH
80static void gld_${EMULATION_NAME}_set_symbols PARAMS ((void));
81static void gld_${EMULATION_NAME}_after_open PARAMS ((void));
82static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
83static void gld_${EMULATION_NAME}_after_parse PARAMS ((void));
84static void gld_${EMULATION_NAME}_before_allocation PARAMS ((void));
85static boolean gld_${EMULATION_NAME}_place_orphan
86 PARAMS ((lang_input_statement_type *, asection *));
87static void gld${EMULATION_NAME}_place_section
88 PARAMS ((lang_statement_union_type *));
89static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
90static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
6f798e5c 91static void gld_${EMULATION_NAME}_finish PARAMS ((void));
252b5132
RH
92
93static struct internal_extra_pe_aouthdr pe;
94static int dll;
95static int support_old_code = 0;
6f798e5c 96static char * thumb_entry_symbol = NULL;
252b5132
RH
97static lang_assignment_statement_type *image_base_statement = 0;
98
99static char *pe_out_def_filename = 0;
252b5132
RH
100static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable */
101static char *pe_implib_filename = 0;
102
103extern const char *output_filename;
104
105static void
106gld_${EMULATION_NAME}_before_parse()
107{
2be9b2c7 108 output_filename = "${EXECUTABLE_NAME:-a.exe}";
252b5132 109 ldfile_output_architecture = bfd_arch_${ARCH};
c6c37250 110#ifdef DLL_SUPPORT
252b5132
RH
111 config.has_shared = 1;
112#endif
113}
114\f
115/* PE format extra command line options. */
116
117/* Used for setting flags in the PE header. */
118#define OPTION_BASE_FILE (300 + 1)
119#define OPTION_DLL (OPTION_BASE_FILE + 1)
120#define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1)
121#define OPTION_IMAGE_BASE (OPTION_FILE_ALIGNMENT + 1)
122#define OPTION_MAJOR_IMAGE_VERSION (OPTION_IMAGE_BASE + 1)
123#define OPTION_MAJOR_OS_VERSION (OPTION_MAJOR_IMAGE_VERSION + 1)
124#define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1)
125#define OPTION_MINOR_IMAGE_VERSION (OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
126#define OPTION_MINOR_OS_VERSION (OPTION_MINOR_IMAGE_VERSION + 1)
127#define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
128#define OPTION_SECTION_ALIGNMENT (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
129#define OPTION_STACK (OPTION_SECTION_ALIGNMENT + 1)
130#define OPTION_SUBSYSTEM (OPTION_STACK + 1)
131#define OPTION_HEAP (OPTION_SUBSYSTEM + 1)
132#define OPTION_SUPPORT_OLD_CODE (OPTION_HEAP + 1)
133#define OPTION_OUT_DEF (OPTION_SUPPORT_OLD_CODE + 1)
134#define OPTION_EXPORT_ALL (OPTION_OUT_DEF + 1)
135#define OPTION_EXCLUDE_SYMBOLS (OPTION_EXPORT_ALL + 1)
136#define OPTION_KILL_ATS (OPTION_EXCLUDE_SYMBOLS + 1)
137#define OPTION_STDCALL_ALIASES (OPTION_KILL_ATS + 1)
138#define OPTION_ENABLE_STDCALL_FIXUP (OPTION_STDCALL_ALIASES + 1)
139#define OPTION_DISABLE_STDCALL_FIXUP (OPTION_ENABLE_STDCALL_FIXUP + 1)
140#define OPTION_IMPLIB_FILENAME (OPTION_DISABLE_STDCALL_FIXUP + 1)
6f798e5c 141#define OPTION_THUMB_ENTRY (OPTION_IMPLIB_FILENAME + 1)
870df5dc
NC
142#define OPTION_WARN_DUPLICATE_EXPORTS (OPTION_THUMB_ENTRY + 1)
143#define OPTION_IMP_COMPAT (OPTION_WARN_DUPLICATE_EXPORTS + 1)
252b5132
RH
144
145static struct option longopts[] =
146{
147 /* PE options */
148 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
149 {"dll", no_argument, NULL, OPTION_DLL},
150 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
151 {"heap", required_argument, NULL, OPTION_HEAP},
152 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
153 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
154 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
155 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
156 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
157 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
158 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
159 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
160 {"stack", required_argument, NULL, OPTION_STACK},
161 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
162 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
6f798e5c 163 {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
c6c37250 164#ifdef DLL_SUPPORT
252b5132
RH
165 /* getopt allows abbreviations, so we do this to stop it from treating -o
166 as an abbreviation for this option */
167 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
168 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
169 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
170 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
171 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
172 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
173 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
174 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
175 {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},
870df5dc
NC
176 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
177 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
252b5132
RH
178#endif
179 {NULL, no_argument, NULL, 0}
180};
181
182
183/* PE/WIN32; added routines to get the subsystem type, heap and/or stack
184 parameters which may be input from the command line */
185
186typedef struct
187{
188 void *ptr;
189 int size;
190 int value;
191 char *symbol;
192 int inited;
193} definfo;
194
195#define D(field,symbol,def) {&pe.field,sizeof(pe.field), def, symbol,0}
196
197static definfo init[] =
198{
199 /* imagebase must be first */
200#define IMAGEBASEOFF 0
201 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE),
202#define DLLOFF 1
1069dd8d 203 {&dll, sizeof(dll), 0, "__dll__", 0},
252b5132
RH
204 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),
205 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
206 D(MajorOperatingSystemVersion,"__major_os_version__", 4),
207 D(MinorOperatingSystemVersion,"__minor_os_version__", 0),
208 D(MajorImageVersion,"__major_image_version__", 1),
209 D(MinorImageVersion,"__minor_image_version__", 0),
210 D(MajorSubsystemVersion,"__major_subsystem_version__", 4),
211 D(MinorSubsystemVersion,"__minor_subsystem_version__", 0),
2be9b2c7 212 D(Subsystem,"__subsystem__", ${SUBSYSTEM}),
252b5132
RH
213 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x2000000),
214 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000),
215 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000),
216 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000),
217 D(LoaderFlags,"__loader_flags__", 0x0),
218 { NULL, 0, 0, NULL, 0 }
219};
220
221static void
222gld_${EMULATION_NAME}_list_options (file)
223 FILE * file;
224{
225 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
226 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
227 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
228 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
229 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
230 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
231 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
232 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
233 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
234 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
235 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
236 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
237 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
238 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
239 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
6f798e5c 240 fprintf (file, _(" --thumb-entry=<symbol> Set the entry point to be Thumb <symbol>\n"));
c6c37250 241#ifdef DLL_SUPPORT
252b5132
RH
242 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
243 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
244 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
245 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
246 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
247 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
248 fprintf (file, _(" --out-implib <file> Generate import library\n"));
249 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
0752a404
NC
250 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n"));
251 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n"));
252 fprintf (file, _(" create __imp_<SYMBOL> as well.\n"));
252b5132
RH
253#endif
254}
255
256static void
257set_pe_name (name, val)
258 char *name;
259 long val;
260{
261 int i;
262 /* Find the name and set it. */
263 for (i = 0; init[i].ptr; i++)
264 {
265 if (strcmp (name, init[i].symbol) == 0)
266 {
267 init[i].value = val;
268 init[i].inited = 1;
269 return;
270 }
271 }
272 abort();
273}
274
275
276static void
277set_pe_subsystem ()
278{
279 const char *sver;
280 int len;
281 int i;
282 static const struct
283 {
284 const char *name;
285 const int value;
286 const char *entry;
287 }
288 v[] =
289 {
2be9b2c7
ILT
290 { "native", 1, "NtProcessStartup" },
291 { "windows", 2, "WinMainCRTStartup" },
292 { "console", 3, "mainCRTStartup" },
252b5132
RH
293#if 0
294 /* The Microsoft linker does not recognize this. */
295 { "os2", 5, "" },
296#endif
2be9b2c7 297 { "posix", 7, "__PosixProcessStartup"},
252b5132
RH
298 { 0, 0, 0 }
299 };
300
301 sver = strchr (optarg, ':');
302 if (sver == NULL)
303 len = strlen (optarg);
304 else
305 {
306 char *end;
307
308 len = sver - optarg;
309 set_pe_name ("__major_subsystem_version__",
310 strtoul (sver + 1, &end, 0));
311 if (*end == '.')
312 set_pe_name ("__minor_subsystem_version__",
313 strtoul (end + 1, &end, 0));
314 if (*end != '\0')
315 einfo (_("%P: warning: bad version number in -subsystem option\n"));
316 }
317
318 for (i = 0; v[i].name; i++)
319 {
320 if (strncmp (optarg, v[i].name, len) == 0
321 && v[i].name[len] == '\0')
322 {
2be9b2c7
ILT
323 const char *initial_symbol_char;
324 const char *entry;
325
252b5132
RH
326 set_pe_name ("__subsystem__", v[i].value);
327
2be9b2c7
ILT
328 initial_symbol_char = ${INITIAL_SYMBOL_CHAR};
329 if (*initial_symbol_char == '\0')
330 entry = v[i].entry;
331 else
332 {
333 char *alc_entry;
334
335 /* lang_add_entry expects its argument to be permanently
336 allocated, so we don't free this string. */
337 alc_entry = xmalloc (strlen (initial_symbol_char)
338 + strlen (v[i].entry)
339 + 1);
340 strcpy (alc_entry, initial_symbol_char);
341 strcat (alc_entry, v[i].entry);
342 entry = alc_entry;
343 }
344
345 lang_add_entry (entry, 1);
252b5132
RH
346
347 return;
348 }
349 }
350
351 einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
352}
353
354
355
356static void
357set_pe_value (name)
358 char *name;
359
360{
361 char *end;
362
363 set_pe_name (name, strtoul (optarg, &end, 0));
364
365 if (end == optarg)
366 einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
367
368 optarg = end;
369}
370
371static void
372set_pe_stack_heap (resname, comname)
373 char *resname;
374 char *comname;
375{
376 set_pe_value (resname);
377
378 if (*optarg == ',')
379 {
380 optarg++;
381 set_pe_value (comname);
382 }
383 else if (*optarg)
384 einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
385}
386
387
388
389static int
390gld_${EMULATION_NAME}_parse_args(argc, argv)
391 int argc;
392 char **argv;
393{
394 int longind;
395 int optc;
396 int prevoptind = optind;
397 int prevopterr = opterr;
398 int wanterror;
399 static int lastoptind = -1;
400
401 if (lastoptind != optind)
402 opterr = 0;
403 wanterror = opterr;
404
405 lastoptind = optind;
406
407 optc = getopt_long_only (argc, argv, "-", longopts, &longind);
408 opterr = prevopterr;
409
410 switch (optc)
411 {
412 default:
413 if (wanterror)
414 xexit (1);
415 optind = prevoptind;
416 return 0;
417
418 case OPTION_BASE_FILE:
419 link_info.base_file = (PTR) fopen (optarg, FOPEN_WB);
420 if (link_info.base_file == NULL)
421 {
422 /* xgettext:c-format */
423 fprintf (stderr, _("%s: Can't open base file %s\n"),
424 program_name, optarg);
425 xexit (1);
426 }
427 break;
428
429 /* PE options */
430 case OPTION_HEAP:
431 set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
432 break;
433 case OPTION_STACK:
434 set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
435 break;
436 case OPTION_SUBSYSTEM:
437 set_pe_subsystem ();
438 break;
439 case OPTION_MAJOR_OS_VERSION:
440 set_pe_value ("__major_os_version__");
441 break;
442 case OPTION_MINOR_OS_VERSION:
443 set_pe_value ("__minor_os_version__");
444 break;
445 case OPTION_MAJOR_SUBSYSTEM_VERSION:
446 set_pe_value ("__major_subsystem_version__");
447 break;
448 case OPTION_MINOR_SUBSYSTEM_VERSION:
449 set_pe_value ("__minor_subsystem_version__");
450 break;
451 case OPTION_MAJOR_IMAGE_VERSION:
452 set_pe_value ("__major_image_version__");
453 break;
454 case OPTION_MINOR_IMAGE_VERSION:
455 set_pe_value ("__minor_image_version__");
456 break;
457 case OPTION_FILE_ALIGNMENT:
458 set_pe_value ("__file_alignment__");
459 break;
460 case OPTION_SECTION_ALIGNMENT:
461 set_pe_value ("__section_alignment__");
462 break;
463 case OPTION_DLL:
464 set_pe_name ("__dll__", 1);
465 break;
466 case OPTION_IMAGE_BASE:
467 set_pe_value ("__image_base__");
468 break;
469 case OPTION_SUPPORT_OLD_CODE:
470 support_old_code = 1;
471 break;
6f798e5c
NC
472 case OPTION_THUMB_ENTRY:
473 thumb_entry_symbol = optarg;
474 break;
c6c37250 475#ifdef DLL_SUPPORT
252b5132
RH
476 case OPTION_OUT_DEF:
477 pe_out_def_filename = xstrdup (optarg);
478 break;
479 case OPTION_EXPORT_ALL:
480 pe_dll_export_everything = 1;
481 break;
482 case OPTION_EXCLUDE_SYMBOLS:
252b5132 483 pe_dll_add_excludes (optarg);
252b5132
RH
484 break;
485 case OPTION_KILL_ATS:
486 pe_dll_kill_ats = 1;
487 break;
488 case OPTION_STDCALL_ALIASES:
489 pe_dll_stdcall_aliases = 1;
490 break;
491 case OPTION_ENABLE_STDCALL_FIXUP:
492 pe_enable_stdcall_fixup = 1;
493 break;
494 case OPTION_DISABLE_STDCALL_FIXUP:
495 pe_enable_stdcall_fixup = 0;
496 break;
497 case OPTION_IMPLIB_FILENAME:
498 pe_implib_filename = xstrdup (optarg);
499 break;
870df5dc
NC
500 case OPTION_WARN_DUPLICATE_EXPORTS:
501 pe_dll_warn_dup_exports = 1;
502 break;
503 case OPTION_IMP_COMPAT:
504 pe_dll_compat_implib = 1;
505 break;
c6c37250 506#endif
252b5132
RH
507 }
508 return 1;
509}
510\f
511/* Assign values to the special symbols before the linker script is
512 read. */
513
514static void
515gld_${EMULATION_NAME}_set_symbols ()
516{
517 /* Run through and invent symbols for all the
518 names and insert the defaults. */
519 int j;
520 lang_statement_list_type *save;
521
522 if (!init[IMAGEBASEOFF].inited)
523 {
524 if (link_info.relocateable)
525 init[IMAGEBASEOFF].value = 0;
526 else if (init[DLLOFF].value || link_info.shared)
527 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
528 else
529 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
530 }
531
532 /* Don't do any symbol assignments if this is a relocateable link. */
533 if (link_info.relocateable)
534 return;
535
536 /* Glue the assignments into the abs section */
537 save = stat_ptr;
538
539 stat_ptr = &(abs_output_section->children);
540
541 for (j = 0; init[j].ptr; j++)
542 {
543 long val = init[j].value;
544 lang_assignment_statement_type *rv;
545 rv = lang_add_assignment (exp_assop ('=' ,init[j].symbol, exp_intop (val)));
546 if (init[j].size == sizeof(short))
547 *(short *)init[j].ptr = val;
548 else if (init[j].size == sizeof(int))
549 *(int *)init[j].ptr = val;
550 else if (init[j].size == sizeof(long))
551 *(long *)init[j].ptr = val;
552 /* This might be a long long or other special type. */
553 else if (init[j].size == sizeof(bfd_vma))
554 *(bfd_vma *)init[j].ptr = val;
555 else abort();
556 if (j == IMAGEBASEOFF)
557 image_base_statement = rv;
558 }
559 /* Restore the pointer. */
560 stat_ptr = save;
561
562 if (pe.FileAlignment >
563 pe.SectionAlignment)
564 {
565 einfo (_("%P: warning, file alignment > section alignment.\n"));
566 }
567}
568
569/* This is called after the linker script and the command line options
570 have been read. */
571
572static void
573gld_${EMULATION_NAME}_after_parse ()
574{
575 /* The Windows libraries are designed for the linker to treat the
576 entry point as an undefined symbol. Otherwise, the .obj that
577 defines mainCRTStartup is brought in because it is the first
578 encountered in libc.lib and it has other symbols in it which will
579 be pulled in by the link process. To avoid this, we act as
580 though the user specified -u with the entry point symbol.
581
582 This function is called after the linker script and command line
583 options have been read, so at this point we know the right entry
584 point. This function is called before the input files are
585 opened, so registering the symbol as undefined will make a
586 difference. */
587
2a275620 588 if (! link_info.relocateable && entry_symbol != NULL)
252b5132
RH
589 ldlang_add_undef (entry_symbol);
590}
591
592static struct bfd_link_hash_entry *pe_undef_found_sym;
593
594static boolean
595pe_undef_cdecl_match (h, string)
596 struct bfd_link_hash_entry *h;
597 PTR string;
598{
599 int sl = strlen (string);
600 if (h->type == bfd_link_hash_defined
601 && strncmp (h->root.string, string, sl) == 0
602 && h->root.string[sl] == '@')
603 {
604 pe_undef_found_sym = h;
605 return false;
606 }
607 return true;
608}
609
610static void
611pe_fixup_stdcalls ()
612{
613 static int gave_warning_message = 0;
614 struct bfd_link_hash_entry *undef, *sym;
615 char *at;
616 for (undef = link_info.hash->undefs; undef; undef=undef->next)
617 if (undef->type == bfd_link_hash_undefined)
618 {
619 at = strchr (undef->root.string, '@');
620 if (at)
621 {
622 /* The symbol is a stdcall symbol, so let's look for a cdecl
623 symbol with the same name and resolve to that */
624 char *cname = xstrdup (undef->root.string);
625 at = strchr (cname, '@');
626 *at = 0;
627 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
628 if (sym && sym->type == bfd_link_hash_defined)
629 {
630 undef->type = bfd_link_hash_defined;
631 undef->u.def.value = sym->u.def.value;
632 undef->u.def.section = sym->u.def.section;
633 if (pe_enable_stdcall_fixup == -1)
634 {
635 einfo (_("Warning: resolving %s by linking to %s\n"),
636 undef->root.string, cname);
637 if (! gave_warning_message)
638 {
639 gave_warning_message = 1;
640 einfo(_("Use --enable-stdcall-fixup to disable these warnings\n"));
641 einfo(_("Use --disable-stdcall-fixup to disable these fixups\n"));
642 }
643 }
644 }
645 }
646 else
647 {
648 /* The symbol is a cdecl symbol, so we look for stdcall
649 symbols - which means scanning the whole symbol table */
650 pe_undef_found_sym = 0;
651 bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match,
652 (PTR) undef->root.string);
653 sym = pe_undef_found_sym;
654 if (sym)
655 {
656 undef->type = bfd_link_hash_defined;
657 undef->u.def.value = sym->u.def.value;
658 undef->u.def.section = sym->u.def.section;
659 if (pe_enable_stdcall_fixup == -1)
660 {
661 einfo (_("Warning: resolving %s by linking to %s\n"),
662 undef->root.string, sym->root.string);
663 if (! gave_warning_message)
664 {
665 gave_warning_message = 1;
666 einfo(_("Use --enable-stdcall-fixup to disable these warnings\n"));
667 einfo(_("Use --disable-stdcall-fixup to disable these fixups\n"));
668 }
669 }
670 }
671 }
672 }
673}
674
675static void
676gld_${EMULATION_NAME}_after_open ()
677{
678 /* Pass the wacky PE command line options into the output bfd.
679 FIXME: This should be done via a function, rather than by
680 including an internal BFD header. */
681
682 if (!coff_data (output_bfd)->pe)
683 einfo (_("%F%P: PE operations on non PE file.\n"));
684
685 pe_data (output_bfd)->pe_opthdr = pe;
686 pe_data (output_bfd)->dll = init[DLLOFF].value;
687
c6c37250 688#ifdef DLL_SUPPORT
252b5132
RH
689 if (pe_enable_stdcall_fixup) /* -1=warn or 1=disable */
690 pe_fixup_stdcalls ();
691
692 pe_process_import_defs(output_bfd, &link_info);
693 if (link_info.shared)
694 pe_dll_build_sections (output_bfd, &link_info);
695#endif
696
626e0105 697#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
f11523b0
NC
698 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
699 {
700 /* The arm backend needs special fields in the output hash structure.
701 These will only be created if the output format is an arm format,
702 hence we do not support linking and changing output formats at the
703 same time. Use a link followed by objcopy to change output formats. */
704 einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
705 return;
706 }
252b5132
RH
707 {
708 /* Find a BFD that can hold the interworking stubs. */
709 LANG_FOR_EACH_INPUT_STATEMENT (is)
710 {
46d23b7c 711 if (bfd_arm_pe_get_bfd_for_interworking (is->the_bfd, & link_info))
252b5132
RH
712 break;
713 }
714 }
715#endif
c6c37250
DD
716
717 {
c6c37250 718 int is_ms_arch;
1069dd8d 719 bfd *cur_arch = 0;
c6c37250 720 lang_input_statement_type *is2;
1069dd8d 721
c6c37250
DD
722 /* Careful - this is a shell script. Watch those dollar signs! */
723 /* Microsoft import libraries have every member named the same,
724 and not in the right order for us to link them correctly. We
725 must detect these and rename the members so that they'll link
726 correctly. There are three types of objects: the head, the
727 thunks, and the sentinel(s). The head is easy; it's the one
728 with idata2. We assume that the sentinels won't have relocs,
729 and the thunks will. It's easier than checking the symbol
1069dd8d 730 table for external references. */
c6c37250
DD
731 LANG_FOR_EACH_INPUT_STATEMENT (is)
732 {
733 if (is->the_bfd->my_archive)
734 {
735 bfd *arch = is->the_bfd->my_archive;
736 if (cur_arch != arch)
737 {
738 cur_arch = arch;
739 is_ms_arch = 1;
740 for (is2 = is;
741 is2 && is2->the_bfd->my_archive == arch;
742 is2 = (lang_input_statement_type *)is2->next)
743 {
744 if (strcmp (is->the_bfd->filename, is2->the_bfd->filename))
745 is_ms_arch = 0;
746 }
747 }
748
749 if (is_ms_arch)
750 {
1069dd8d 751 int idata2 = 0, reloc_count=0;
c6c37250
DD
752 asection *sec;
753 char *new_name, seq;
1069dd8d 754
c6c37250
DD
755 for (sec = is->the_bfd->sections; sec; sec = sec->next)
756 {
757 if (strcmp (sec->name, ".idata\$2") == 0)
758 idata2 = 1;
759 reloc_count += sec->reloc_count;
760 }
761
762 if (idata2) /* .idata2 is the TOC */
763 seq = 'a';
764 else if (reloc_count > 0) /* thunks */
765 seq = 'b';
766 else /* sentinel */
767 seq = 'c';
768
e4e24acb 769 new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
c6c37250
DD
770 sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
771 is->the_bfd->filename = new_name;
772
e4e24acb 773 new_name = xmalloc (strlen(is->filename) + 3);
c6c37250
DD
774 sprintf (new_name, "%s.%c", is->filename, seq);
775 is->filename = new_name;
776 }
777 }
778 }
779 }
252b5132
RH
780}
781\f
782static void
783gld_${EMULATION_NAME}_before_allocation()
784{
785#ifdef TARGET_IS_ppcpe
786 /* Here we rummage through the found bfds to collect toc information */
787 {
788 LANG_FOR_EACH_INPUT_STATEMENT (is)
789 {
790 if (!ppc_process_before_allocation (is->the_bfd, &link_info))
791 {
792 /* xgettext:c-format */
793 einfo (_("Errors encountered processing file %s\n"), is->filename);
794 }
795 }
796 }
797
798 /* We have seen it all. Allocate it, and carry on */
799 ppc_allocate_toc_section (&link_info);
800#endif /* TARGET_IS_ppcpe */
801
626e0105 802#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
252b5132
RH
803 /* FIXME: we should be able to set the size of the interworking stub
804 section.
805
806 Here we rummage through the found bfds to collect glue
807 information. FIXME: should this be based on a command line
808 option? krk@cygnus.com */
809 {
810 LANG_FOR_EACH_INPUT_STATEMENT (is)
811 {
46d23b7c 812 if (! bfd_arm_pe_process_before_allocation
252b5132
RH
813 (is->the_bfd, & link_info, support_old_code))
814 {
815 /* xgettext:c-format */
816 einfo (_("Errors encountered processing file %s for interworking"),
817 is->filename);
818 }
819 }
820 }
821
822 /* We have seen it all. Allocate it, and carry on */
46d23b7c 823 bfd_arm_pe_allocate_interworking_sections (& link_info);
252b5132
RH
824#endif /* TARGET_IS_armpe */
825}
826\f
827
828/* This is called when an input file isn't recognized as a BFD. We
829 check here for .DEF files and pull them in automatically. */
830
831static int
832saw_option(char *option)
833{
834 int i;
835 for (i=0; init[i].ptr; i++)
836 if (strcmp (init[i].symbol, option) == 0)
837 return init[i].inited;
838 return 0;
839}
840
841static boolean
842gld_${EMULATION_NAME}_unrecognized_file(entry)
843 lang_input_statement_type *entry;
844{
c6c37250 845#ifdef DLL_SUPPORT
252b5132
RH
846 const char *ext = entry->filename + strlen (entry->filename) - 4;
847
848 if (strcmp (ext, ".def") == 0 || strcmp (ext, ".DEF") == 0)
849 {
850 if (pe_def_file == 0)
851 pe_def_file = def_file_empty ();
852 def_file_parse (entry->filename, pe_def_file);
853 if (pe_def_file)
854 {
855 int i, buflen=0, len;
856 char *buf;
857 for (i=0; i<pe_def_file->num_exports; i++)
858 {
859 len = strlen(pe_def_file->exports[i].internal_name);
860 if (buflen < len+2)
861 buflen = len+2;
862 }
863 buf = (char *) xmalloc (buflen);
864 for (i=0; i<pe_def_file->num_exports; i++)
865 {
866 struct bfd_link_hash_entry *h;
867 sprintf(buf, "_%s", pe_def_file->exports[i].internal_name);
868
869 h = bfd_link_hash_lookup (link_info.hash, buf, true, true, true);
870 if (h == (struct bfd_link_hash_entry *) NULL)
871 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
872 if (h->type == bfd_link_hash_new)
873 {
874 h->type = bfd_link_hash_undefined;
875 h->u.undef.abfd = NULL;
876 bfd_link_add_undef (link_info.hash, h);
877 }
878 }
879 free (buf);
880
881 /* def_file_print (stdout, pe_def_file); */
882 if (pe_def_file->is_dll == 1)
883 link_info.shared = 1;
884
885 if (pe_def_file->base_address != (bfd_vma)(-1))
886 {
887 pe.ImageBase =
888 pe_data (output_bfd)->pe_opthdr.ImageBase =
889 init[IMAGEBASEOFF].value = pe_def_file->base_address;
890 init[IMAGEBASEOFF].inited = 1;
891 if (image_base_statement)
892 image_base_statement->exp =
893 exp_assop ('=', "__image_base__", exp_intop (pe.ImageBase));
894 }
895
896#if 0
897 /* Not sure if these *should* be set */
898 if (pe_def_file->version_major != -1)
899 {
900 pe.MajorImageVersion = pe_def_file->version_major;
901 pe.MinorImageVersion = pe_def_file->version_minor;
902 }
903#endif
904 if (pe_def_file->stack_reserve != -1
905 && ! saw_option ("__size_of_stack_reserve__"))
906 {
907 pe.SizeOfStackReserve = pe_def_file->stack_reserve;
908 if (pe_def_file->stack_commit != -1)
909 pe.SizeOfStackCommit = pe_def_file->stack_commit;
910 }
911 if (pe_def_file->heap_reserve != -1
912 && ! saw_option ("__size_of_heap_reserve__"))
913 {
914 pe.SizeOfHeapReserve = pe_def_file->heap_reserve;
915 if (pe_def_file->heap_commit != -1)
916 pe.SizeOfHeapCommit = pe_def_file->heap_commit;
917 }
918 return true;
919 }
920 }
921#endif
922 return false;
923
924}
925
926static boolean
927gld_${EMULATION_NAME}_recognized_file(entry)
928 lang_input_statement_type *entry;
929{
c6c37250 930#ifdef DLL_SUPPORT
252b5132 931#ifdef TARGET_IS_i386pe
c6c37250
DD
932 pe_dll_id_target ("pei-i386");
933#endif
252b5132
RH
934 if (bfd_get_format (entry->the_bfd) == bfd_object)
935 {
936 const char *ext = entry->filename + strlen (entry->filename) - 4;
937 if (strcmp (ext, ".dll") == 0 || strcmp (ext, ".DLL") == 0)
938 return pe_implied_import_dll (entry->filename);
939 }
940#endif
941 return false;
942}
943
944static void
945gld_${EMULATION_NAME}_finish ()
946{
6f798e5c
NC
947#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
948 struct bfd_link_hash_entry * h;
949
950 if (thumb_entry_symbol != NULL)
951 {
952 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol, false, false, true);
953
954 if (h != (struct bfd_link_hash_entry *) NULL
955 && (h->type == bfd_link_hash_defined
956 || h->type == bfd_link_hash_defweak)
957 && h->u.def.section->output_section != NULL)
958 {
959 static char buffer[32];
960 bfd_vma val;
961
962 /* Special procesing is required for a Thumb entry symbol. The
963 bottom bit of its address must be set. */
964 val = (h->u.def.value
965 + bfd_get_section_vma (output_bfd,
966 h->u.def.section->output_section)
967 + h->u.def.section->output_offset);
968
969 val |= 1;
970
971 /* Now convert this value into a string and store it in entry_symbol
972 where the lang_finish() function will pick it up. */
973 buffer[0] = '0';
974 buffer[1] = 'x';
975
976 sprintf_vma (buffer + 2, val);
977
978 if (entry_symbol != NULL && entry_from_cmdline)
979 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
980 thumb_entry_symbol, entry_symbol);
981 entry_symbol = buffer;
982 }
983 else
984 einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
985 }
986#endif /* defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe) */
987
c6c37250 988#ifdef DLL_SUPPORT
252b5132
RH
989 if (link_info.shared)
990 {
991 pe_dll_fill_sections (output_bfd, &link_info);
992 if (pe_implib_filename)
993 pe_dll_generate_implib (pe_def_file, pe_implib_filename);
994 }
995 if (pe_out_def_filename)
996 pe_dll_generate_def_file (pe_out_def_filename);
997#endif
998}
999
1000\f
1001/* Place an orphan section.
1002
1003 We use this to put sections in a reasonable place in the file, and
1004 to ensure that they are aligned as required.
1005
1006 We handle grouped sections here as well. A section named .foo$nn
1007 goes into the output section .foo. All grouped sections are sorted
1008 by name.
1009
1010 Grouped sections for the default sections are handled by the
1011 default linker script using wildcards, and are sorted by
1012 sort_sections. */
1013
1014static asection *hold_section;
1015static char *hold_section_name;
1016static lang_output_section_statement_type *hold_use;
1017static lang_output_section_statement_type *hold_text;
1018static lang_output_section_statement_type *hold_rdata;
1019static lang_output_section_statement_type *hold_data;
1020static lang_output_section_statement_type *hold_bss;
1021
1022/* Place an orphan section. We use this to put random SHF_ALLOC
1023 sections in the right segment. */
1024
1025/*ARGSUSED*/
1026static boolean
1027gld_${EMULATION_NAME}_place_orphan (file, s)
1028 lang_input_statement_type *file;
1029 asection *s;
1030{
1031 const char *secname;
1032 char *dollar;
1033
1034 if ((s->flags & SEC_ALLOC) == 0)
1035 return false;
1036
1037 secname = bfd_get_section_name (s->owner, s);
1038
1039 /* Look through the script to see where to place this section. */
1040
1041 hold_section = s;
1042
1043 hold_section_name = xstrdup (secname);
6eec49fc
DD
1044 if (!link_info.relocateable)
1045 {
1046 dollar = strchr (hold_section_name, '$');
1047 if (dollar != NULL)
1048 *dollar = '\0';
1049 }
252b5132
RH
1050
1051 hold_use = NULL;
1052 lang_for_each_statement (gld${EMULATION_NAME}_place_section);
1053
1054 if (hold_use == NULL)
1055 {
1056 lang_output_section_statement_type *place;
1057 char *outsecname;
1058 asection *snew, **pps;
1059 lang_statement_list_type *old;
1060 lang_statement_list_type add;
1061 etree_type *address;
1062
1063 /* Try to put the new output section in a reasonable place based
1064 on the section name and section flags. */
1065 place = NULL;
1066 if ((s->flags & SEC_HAS_CONTENTS) == 0
1067 && hold_bss != NULL)
1068 place = hold_bss;
1069 else if ((s->flags & SEC_READONLY) == 0
1070 && hold_data != NULL)
1071 place = hold_data;
1072 else if ((s->flags & SEC_CODE) == 0
1073 && (s->flags & SEC_READONLY) != 0
1074 && hold_rdata != NULL)
1075 place = hold_rdata;
1076 else if ((s->flags & SEC_READONLY) != 0
1077 && hold_text != NULL)
1078 place = hold_text;
1079
1080 /* Choose a unique name for the section. This will be needed if
1081 the same section name appears in the input file with
1082 different loadable or allocateable characteristics. */
1083 outsecname = xstrdup (hold_section_name);
1084 if (bfd_get_section_by_name (output_bfd, outsecname) != NULL)
1085 {
1086 unsigned int len;
1087 char *newname;
1088 unsigned int i;
1089
1090 len = strlen (outsecname);
1091 newname = xmalloc (len + 5);
1092 strcpy (newname, outsecname);
1093 i = 0;
1094 do
1095 {
1096 sprintf (newname + len, "%d", i);
1097 ++i;
1098 }
1099 while (bfd_get_section_by_name (output_bfd, newname) != NULL);
1100
1101 free (outsecname);
1102 outsecname = newname;
1103 }
1104
1105 /* We don't want to free OUTSECNAME, as it may get attached to
1106 the output section statement. */
1107
1108 /* Create the section in the output file, and put it in the
1109 right place. This shuffling is to make the output file look
1110 neater. */
1111 snew = bfd_make_section (output_bfd, outsecname);
1112 if (snew == NULL)
1113 einfo ("%P%F: output format %s cannot represent section called %s\n",
1114 output_bfd->xvec->name, outsecname);
1115 if (place != NULL && place->bfd_section != NULL)
1116 {
1117 for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next)
1118 ;
1119 *pps = snew->next;
1120 snew->next = place->bfd_section->next;
1121 place->bfd_section->next = snew;
1122 }
1123
1124 /* Start building a list of statements for this section. */
1125 old = stat_ptr;
1126 stat_ptr = &add;
1127 lang_list_init (stat_ptr);
1128
1129 if (link_info.relocateable)
1130 address = NULL;
1131 else
1132 {
1133 /* All sections in an executable must be aligned to a page
1134 boundary. */
1135 address = exp_unop (ALIGN_K,
1136 exp_nameop (NAME, "__section_alignment__"));
1137 }
1138
1139 lang_enter_output_section_statement (outsecname, address, 0,
1140 (bfd_vma) 0,
1141 (etree_type *) NULL,
1142 (etree_type *) NULL,
1143 (etree_type *) NULL);
1144
1145 hold_use = lang_output_section_statement_lookup (outsecname);
1146
1147 lang_leave_output_section_statement
1148 ((bfd_vma) 0, "*default*",
562d3460
TW
1149 (struct lang_output_section_phdr_list *) NULL,
1150 "*default*");
252b5132
RH
1151
1152 /* Now stick the new statement list right after PLACE. */
1153 if (place != NULL)
1154 {
1155 *add.tail = place->header.next;
1156 place->header.next = add.head;
1157 }
1158
1159 stat_ptr = old;
1160 }
1161
1162 if (dollar == NULL)
1163 wild_doit (&hold_use->children, s, hold_use, file);
1164 else
1165 {
1166 lang_statement_union_type **pl;
1167 boolean found_dollar;
1168 lang_statement_list_type list;
1169
1170 /* The section name has a '$'. Sort it with the other '$'
1171 sections. */
1172
1173 found_dollar = false;
1174 for (pl = &hold_use->children.head; *pl != NULL; pl = &(*pl)->next)
1175 {
1176 lang_input_section_type *ls;
1177 const char *lname;
1178
1179 if ((*pl)->header.type != lang_input_section_enum)
1180 continue;
1181
1182 ls = &(*pl)->input_section;
1183
1184 lname = bfd_get_section_name (ls->ifile->the_bfd, ls->section);
1185 if (strchr (lname, '$') == NULL)
1186 {
1187 if (found_dollar)
1188 break;
1189 }
1190 else
1191 {
1192 found_dollar = true;
1193 if (strcmp (secname, lname) < 0)
1194 break;
1195 }
1196 }
1197
1198 lang_list_init (&list);
1199 wild_doit (&list, s, hold_use, file);
1200 if (list.head != NULL)
1201 {
1202 ASSERT (list.head->next == NULL);
1203 list.head->next = *pl;
1204 *pl = list.head;
1205 }
1206 }
1207
1208 free (hold_section_name);
1209
1210 return true;
1211}
1212
1213static void
1214gld${EMULATION_NAME}_place_section (s)
1215 lang_statement_union_type *s;
1216{
1217 lang_output_section_statement_type *os;
1218
1219 if (s->header.type != lang_output_section_statement_enum)
1220 return;
1221
1222 os = &s->output_section_statement;
1223
1224 if (strcmp (os->name, hold_section_name) == 0
1225 && os->bfd_section != NULL
1226 && ((hold_section->flags & (SEC_LOAD | SEC_ALLOC))
1227 == (os->bfd_section->flags & (SEC_LOAD | SEC_ALLOC))))
1228 hold_use = os;
1229
1230 if (strcmp (os->name, ".text") == 0)
1231 hold_text = os;
1232 else if (strcmp (os->name, ".rdata") == 0)
1233 hold_rdata = os;
1234 else if (strcmp (os->name, ".data") == 0)
1235 hold_data = os;
1236 else if (strcmp (os->name, ".bss") == 0)
1237 hold_bss = os;
1238}
1239\f
1240static char *
1241gld_${EMULATION_NAME}_get_script(isfile)
1242 int *isfile;
1243EOF
1244# Scripts compiled in.
1245# sed commands to quote an ld script as a C string.
597e2591 1246sc="-f stringify.sed"
252b5132
RH
1247
1248cat >>e${EMULATION_NAME}.c <<EOF
1249{
1250 *isfile = 0;
1251
1252 if (link_info.relocateable == true && config.build_constructors == true)
1253 return
1254EOF
1255sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1256echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1257sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1258echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1259sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1260echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1261sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1262echo ' ; else return' >> e${EMULATION_NAME}.c
1263sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1264echo '; }' >> e${EMULATION_NAME}.c
1265
1266cat >>e${EMULATION_NAME}.c <<EOF
1267
1268
1269struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1270{
1271 gld_${EMULATION_NAME}_before_parse,
1272 syslib_default,
1273 hll_default,
1274 gld_${EMULATION_NAME}_after_parse,
1275 gld_${EMULATION_NAME}_after_open,
1276 after_allocation_default,
1277 set_output_arch_default,
1278 ldemul_default_target,
1279 gld_${EMULATION_NAME}_before_allocation,
1280 gld_${EMULATION_NAME}_get_script,
1281 "${EMULATION_NAME}",
1282 "${OUTPUT_FORMAT}",
1283 gld_${EMULATION_NAME}_finish, /* finish */
1284 NULL, /* create output section statements */
1285 NULL, /* open dynamic archive */
1286 gld_${EMULATION_NAME}_place_orphan,
1287 gld_${EMULATION_NAME}_set_symbols,
1288 gld_${EMULATION_NAME}_parse_args,
1289 gld_${EMULATION_NAME}_unrecognized_file,
1290 gld_${EMULATION_NAME}_list_options,
1291 gld_${EMULATION_NAME}_recognized_file
1292};
1293EOF
This page took 0.138168 seconds and 4 git commands to generate.