X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=ld%2Femultempl%2Fbeos.em;h=732abfdcfa8ebf6103363074ad5c3ac4f012d2b0;hb=0cdcdbf8dbadc70194d46b4c3400ba8cc2a10fc0;hp=7e76f6911394981cf12070cd07f9bc0b7f4b68bd;hpb=b34976b65aea8f33690229600bbf4527ec3118e1;p=deliverable%2Fbinutils-gdb.git diff --git a/ld/emultempl/beos.em b/ld/emultempl/beos.em index 7e76f69113..732abfdcfa 100644 --- a/ld/emultempl/beos.em +++ b/ld/emultempl/beos.em @@ -5,24 +5,27 @@ if [ -z "$MACHINE" ]; then else OUTPUT_ARCH=${ARCH}:${MACHINE} fi -cat >e${EMULATION_NAME}.c <arch; - ldfile_output_machine = arch->mach; - ldfile_output_machine_name = arch->printable_name; - } - else - ldfile_output_architecture = bfd_arch_${ARCH}; + ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`); output_filename = "a.exe"; } @@ -110,8 +85,14 @@ gld_${EMULATION_NAME}_before_parse() #define OPTION_SUBSYSTEM (OPTION_STACK + 1) #define OPTION_HEAP (OPTION_SUBSYSTEM + 1) -static struct option longopts[] = { - /* PE options */ +static void +gld${EMULATION_NAME}_add_options + (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl, + struct option **longopts, int nrl ATTRIBUTE_UNUSED, + struct option **really_longopts ATTRIBUTE_UNUSED) +{ + static const struct option xtra_long[] = { + /* PE options */ {"base-file", required_argument, NULL, OPTION_BASE_FILE}, {"dll", no_argument, NULL, OPTION_DLL}, {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT}, @@ -126,9 +107,14 @@ static struct option longopts[] = { {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT}, {"stack", required_argument, NULL, OPTION_STACK}, {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM}, - {NULL, no_argument, NULL, 0} + {NULL, no_argument, NULL, 0} }; + *longopts = (struct option *) + xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long)); + memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long)); +} + /* PE/WIN32; added routines to get the subsystem type, heap and/or stack parameters which may be input from the command line */ @@ -169,9 +155,7 @@ static definfo init[] = static void -set_pe_name (name, val) - char *name; - long val; +set_pe_name (char *name, long val) { int i; /* Find the name and set it. */ @@ -189,7 +173,7 @@ set_pe_name (name, val) static void -set_pe_subsystem () +set_pe_subsystem (void) { const char *sver; int len; @@ -207,10 +191,6 @@ set_pe_subsystem () { "wwindows", 2, "_wWinMainCRTStartup" }, { "console", 3, "_mainCRTStartup" }, { "wconsole", 3, "_wmainCRTStartup" }, -#if 0 - /* The Microsoft linker does not recognize this. */ - { "os2", 5, "" }, -#endif { "posix", 7, "___PosixProcessStartup"}, { 0, 0, 0 } }; @@ -240,23 +220,8 @@ set_pe_subsystem () set_pe_name ("__subsystem__", v[i].value); /* If the subsystem is windows, we use a different entry - point. We also register the entry point as an undefined - symbol. from lang_add_entry() The reason we do - this is so that the user - doesn't have to because they would have to use the -u - switch if they were specifying an entry point other than - _mainCRTStartup. Specifically, if creating a windows - application, entry point _WinMainCRTStartup must be - specified. What I have found for non console - applications (entry not _mainCRTStartup) is that the .obj - that contains mainCRTStartup is brought in since it is - the first encountered in libc.lib and it has other - symbols in it which will be pulled in by the link - process. To avoid this, adding -u with the entry point - name specified forces the correct .obj to be used. We - can avoid making the user do this by always adding the - entry point name as an undefined symbol. */ - lang_add_entry (v[i].entry, 1); + point. */ + lang_default_entry (v[i].entry); return; } @@ -265,11 +230,8 @@ set_pe_subsystem () } - static void -set_pe_value (name) - char *name; - +set_pe_value (char *name) { char *end; set_pe_name (name, strtoul (optarg, &end, 0)); @@ -282,9 +244,7 @@ set_pe_value (name) } static void -set_pe_stack_heap (resname, comname) - char *resname; - char *comname; +set_pe_stack_heap (char *resname, char *comname) { set_pe_value (resname); if (*optarg == ',') @@ -299,44 +259,18 @@ set_pe_stack_heap (resname, comname) } - -static int -gld_${EMULATION_NAME}_parse_args(argc, argv) - int argc; - char **argv; +static bfd_boolean +gld${EMULATION_NAME}_handle_option (int optc) { - int longind; - int optc; - int prevoptind = optind; - int prevopterr = opterr; - int wanterror; - static int lastoptind = -1; - - if (lastoptind != optind) - opterr = 0; - wanterror = opterr; - - lastoptind = optind; - - optc = getopt_long_only (argc, argv, "-", longopts, &longind); - opterr = prevopterr; - switch (optc) { default: - if (wanterror) - xexit (1); - optind = prevoptind; - return 0; + return FALSE; case OPTION_BASE_FILE: - link_info.base_file = (PTR) fopen (optarg, FOPEN_WB); + link_info.base_file = fopen (optarg, FOPEN_WB); if (link_info.base_file == NULL) - { - fprintf (stderr, "%s: Can't open base file %s\n", - program_name, optarg); - xexit (1); - } + einfo (_("%F%P: cannot open base file %s\n"), optarg); break; /* PE options */ @@ -380,23 +314,22 @@ gld_${EMULATION_NAME}_parse_args(argc, argv) set_pe_value ("__image_base__"); break; } - return 1; + return TRUE; } /* Assign values to the special symbols before the linker script is read. */ static void -gld_${EMULATION_NAME}_set_symbols() +gld_${EMULATION_NAME}_set_symbols (void) { /* Run through and invent symbols for all the names and insert the defaults. */ int j; - lang_statement_list_type *save; if (!init[IMAGEBASEOFF].inited) { - if (link_info.relocateable) + if (link_info.relocatable) init[IMAGEBASEOFF].value = 0; else if (init[DLLOFF].value) init[IMAGEBASEOFF].value = BEOS_DLL_IMAGE_BASE; @@ -404,19 +337,18 @@ gld_${EMULATION_NAME}_set_symbols() init[IMAGEBASEOFF].value = BEOS_EXE_IMAGE_BASE; } - /* Don't do any symbol assignments if this is a relocateable link. */ - if (link_info.relocateable) + /* Don't do any symbol assignments if this is a relocatable link. */ + if (link_info.relocatable) return; /* Glue the assignments into the abs section */ - save = stat_ptr; - - stat_ptr = &(abs_output_section->children); + push_stat_ptr (&abs_output_section->children); for (j = 0; init[j].ptr; j++) { long val = init[j].value; - lang_add_assignment (exp_assop ('=', init[j].symbol, exp_intop (val))); + lang_add_assignment (exp_assign (init[j].symbol, exp_intop (val), + FALSE)); if (init[j].size == sizeof(short)) *(short *)init[j].ptr = val; else if (init[j].size == sizeof(int)) @@ -429,7 +361,7 @@ gld_${EMULATION_NAME}_set_symbols() else abort(); } /* Restore the pointer. */ - stat_ptr = save; + pop_stat_ptr (); if (pe.FileAlignment > pe.SectionAlignment) @@ -439,39 +371,39 @@ gld_${EMULATION_NAME}_set_symbols() } static void -gld_${EMULATION_NAME}_after_open() +gld_${EMULATION_NAME}_after_open (void) { + after_open_default (); + /* Pass the wacky PE command line options into the output bfd. FIXME: This should be done via a function, rather than by including an internal BFD header. */ - if (!coff_data(output_bfd)->pe) + if (!coff_data(link_info.output_bfd)->pe) { einfo ("%F%P: PE operations on non PE file.\n"); } - pe_data(output_bfd)->pe_opthdr = pe; - pe_data(output_bfd)->dll = init[DLLOFF].value; + pe_data(link_info.output_bfd)->pe_opthdr = pe; + pe_data(link_info.output_bfd)->dll = init[DLLOFF].value; } /* Callback functions for qsort in sort_sections. */ static int -sort_by_file_name (a, b) - const PTR a; - const PTR b; +sort_by_file_name (const void *a, const void *b) { const lang_statement_union_type *const *ra = a; const lang_statement_union_type *const *rb = b; int i, a_sec, b_sec; - i = strcmp ((*ra)->input_section.ifile->the_bfd->my_archive->filename, - (*rb)->input_section.ifile->the_bfd->my_archive->filename); + i = filename_cmp ((*ra)->input_section.section->owner->my_archive->filename, + (*rb)->input_section.section->owner->my_archive->filename); if (i != 0) return i; - i = strcmp ((*ra)->input_section.ifile->filename, - (*rb)->input_section.ifile->filename); + i = filename_cmp ((*ra)->input_section.section->owner->filename, + (*rb)->input_section.section->owner->filename); if (i != 0) return i; /* the tail idata4/5 are the only ones without relocs to an @@ -495,15 +427,15 @@ sort_by_file_name (a, b) if ( (strcmp( (*ra)->input_section.section->name, ".idata$6") == 0) ) return 0; /* don't sort .idata$6 or .idata$7 FIXME dlltool eliminate .idata$7 */ - if (! bfd_get_section_contents ((*ra)->input_section.ifile->the_bfd, + if (! bfd_get_section_contents ((*ra)->input_section.section->owner, (*ra)->input_section.section, &a_sec, (file_ptr) 0, (bfd_size_type)sizeof(a_sec))) einfo ("%F%B: Can't read contents of section .idata: %E\n", - (*ra)->input_section.ifile->the_bfd); + (*ra)->input_section.section->owner); - if (! bfd_get_section_contents ((*rb)->input_section.ifile->the_bfd, + if (! bfd_get_section_contents ((*rb)->input_section.section->owner, (*rb)->input_section.section, &b_sec, (file_ptr) 0, (bfd_size_type)sizeof(b_sec) )) einfo ("%F%B: Can't read contents of section .idata: %E\n", - (*rb)->input_section.ifile->the_bfd); + (*rb)->input_section.section->owner); i = ((a_sec < b_sec) ? -1 : 0); if ( i != 0) @@ -514,24 +446,21 @@ return 0; } static int -sort_by_section_name (a, b) - const PTR a; - const PTR b; +sort_by_section_name (const void *a, const void *b) { const lang_statement_union_type *const *ra = a; const lang_statement_union_type *const *rb = b; int i; i = strcmp ((*ra)->input_section.section->name, - (*rb)->input_section.section->name); -/* this is a hack to make .stab and .stabstr last, so we don't have - to fix strip/objcopy for .reloc sections. - FIXME stripping images with a .rsrc section still needs to be fixed */ - if ( i != 0) + (*rb)->input_section.section->name); + /* This is a hack to make .stab and .stabstr last, so we don't have + to fix strip/objcopy for .reloc sections. + FIXME stripping images with a .rsrc section still needs to be fixed. */ + if (i != 0) { - if ((strncmp ((*ra)->input_section.section->name, ".stab", 5) == 0) - && (strncmp ((*rb)->input_section.section->name, ".stab", 5) != 0)) + if ((CONST_STRNEQ ((*ra)->input_section.section->name, ".stab")) + && (! CONST_STRNEQ ((*rb)->input_section.section->name, ".stab"))) return 1; - return i; } return i; } @@ -541,10 +470,10 @@ sort_by_section_name (a, b) The result is a pointer to the last element's "next" pointer. */ static lang_statement_union_type ** -sort_sections_1 (startptr, next_after, count, sort_func) - lang_statement_union_type **startptr,*next_after; - int count; - int (*sort_func) PARAMS ((const PTR, const PTR)); +sort_sections_1 (lang_statement_union_type **startptr, + lang_statement_union_type *next_after, + int count, + int (*sort_func) (const void *, const void *)) { lang_statement_union_type **vec; lang_statement_union_type *p; @@ -587,8 +516,7 @@ sort_sections_1 (startptr, next_after, count, sort_func) place_orphans routine to implement grouped sections. */ static void -sort_sections (s) - lang_statement_union_type *s; +sort_sections (lang_statement_union_type *s) { for (; s ; s = s->header.next) switch (s->header.type) @@ -605,7 +533,7 @@ sort_sections (s) { /* Is this the .idata section? */ if (sec->spec.name != NULL - && strncmp (sec->spec.name, ".idata", 6) == 0) + && CONST_STRNEQ (sec->spec.name, ".idata")) { /* Sort the children. We want to sort any objects in the same archive. In order to handle the case of @@ -618,7 +546,7 @@ sort_sections (s) { lang_statement_union_type *start = *p; if (start->header.type != lang_input_section_enum - || !start->input_section.ifile->the_bfd->my_archive) + || !start->input_section.section->owner->my_archive) p = &(start->header.next); else { @@ -675,10 +603,8 @@ sort_sections (s) } static void -gld_${EMULATION_NAME}_before_allocation() +gld_${EMULATION_NAME}_before_allocation (void) { - extern lang_statement_list_type *stat_ptr; - #ifdef TARGET_IS_ppcpe /* Here we rummage through the found bfds to collect toc information */ { @@ -717,6 +643,8 @@ gld_${EMULATION_NAME}_before_allocation() #endif /* TARGET_IS_ppcpe */ sort_sections (stat_ptr->head); + + before_allocation_default (); } /* Place an orphan section. We use this to put sections with a '\$' in them @@ -730,35 +658,31 @@ gld_${EMULATION_NAME}_before_allocation() but I'm leaving this here in case we want to enable it for sections which are not mentioned in the linker script. */ -/*ARGSUSED*/ -static bfd_boolean -gld${EMULATION_NAME}_place_orphan (file, s) - lang_input_statement_type *file; - asection *s; +static lang_output_section_statement_type * +gld${EMULATION_NAME}_place_orphan (asection *s, + const char *secname, + int constraint) { - const char *secname; char *output_secname, *ps; lang_output_section_statement_type *os; lang_statement_union_type *l; if ((s->flags & SEC_ALLOC) == 0) - return FALSE; + return NULL; /* Don't process grouped sections unless doing a final link. If they're marked as COMDAT sections, we don't want .text\$foo to end up in .text and then have .text disappear because it's marked link-once-discard. */ - if (link_info.relocateable) - return FALSE; - - secname = bfd_get_section_name (s->owner, s); + if (link_info.relocatable) + return NULL; /* Everything from the '\$' on gets deleted so don't allow '\$' as the first character. */ if (*secname == '\$') einfo ("%P%F: section %s has '\$' as first character\n", secname); if (strchr (secname + 1, '\$') == NULL) - return FALSE; + return NULL; /* Look up the output section. The Microsoft specs say sections names in image files never contain a '\$'. Fortunately, lang_..._lookup creates @@ -766,7 +690,7 @@ gld${EMULATION_NAME}_place_orphan (file, s) output_secname = xstrdup (secname); ps = strchr (output_secname + 1, '\$'); *ps = 0; - os = lang_output_section_statement_lookup (output_secname); + os = lang_output_section_statement_lookup (output_secname, constraint, TRUE); /* Find the '\$' wild statement for this section. We currently require the linker script to explicitly mention "*(.foo\$)". @@ -788,57 +712,33 @@ gld${EMULATION_NAME}_place_orphan (file, s) } ps[0] = 0; if (l == NULL) -#if 1 einfo ("%P%F: *(%s\$) missing from linker script\n", output_secname); -#else /* FIXME: This block is untried. It exists to convey the intent, - should one decide to not require *(.foo\$) to appear in the linker - script. */ - { - lang_wild_statement_type *new; - struct wildcard_list *tmp; - - tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); - tmp->next = NULL; - tmp->spec.name = xmalloc (strlen (output_secname) + 2); - sprintf (tmp->spec.name, "%s\$", output_secname); - tmp->spec.exclude_name_list = NULL; - tmp->sorted = FALSE; - new = new_stat (lang_wild_statement, &os->children); - new->filename = NULL; - new->filenames_sorted = FALSE; - new->section_list = tmp; - new->keep_sections = FALSE; - lang_list_init (&new->children); - l = new; - } -#endif /* Link the input section in and we're done for now. The sections still have to be sorted, but that has to wait until all such sections have been processed by us. The sorting is done by sort_sections. */ - lang_add_section (&l->wild_statement.children, s, os, file); + lang_add_section (&l->wild_statement.children, s, NULL, os); - return TRUE; + return os; } static char * -gld_${EMULATION_NAME}_get_script(isfile) - int *isfile; +gld_${EMULATION_NAME}_get_script (int *isfile) EOF # Scripts compiled in. # sed commands to quote an ld script as a C string. sc="-f stringify.sed" -cat >>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c -echo ' ; else if (link_info.relocateable) return' >> e${EMULATION_NAME}.c +echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c @@ -848,7 +748,7 @@ echo ' ; else return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c echo '; }' >> e${EMULATION_NAME}.c -cat >>e${EMULATION_NAME}.c <