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