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