pe.em
来自「基于4个mips核的noc设计」· EM 代码 · 共 1,678 行 · 第 1/4 页
EM
1,678 行
/*ARGSUSED*/static booleangld_${EMULATION_NAME}_place_orphan (file, s) lang_input_statement_type *file; asection *s;{ const char *secname; char *hold_section_name; char *dollar = NULL; const char *ps = NULL; lang_output_section_statement_type *os; lang_statement_list_type add_child; secname = bfd_get_section_name (s->owner, s); /* Look through the script to see where to place this section. */ hold_section_name = xstrdup (secname); if (!link_info.relocateable) { dollar = strchr (hold_section_name, '$'); if (dollar != NULL) *dollar = '\0'; } os = lang_output_section_find (hold_section_name); lang_list_init (&add_child); if (os != NULL && os->bfd_section != NULL && ((s->flags ^ os->bfd_section->flags) & (SEC_LOAD | SEC_ALLOC)) == 0) { wild_doit (&add_child, s, os, file); } else { struct orphan_save *place; static struct orphan_save hold_text; static struct orphan_save hold_rdata; static struct orphan_save hold_data; static struct orphan_save hold_bss; char *outsecname; lang_statement_list_type *old; lang_statement_list_type add; etree_type *address; /* Try to put the new output section in a reasonable place based on the section name and section flags. */#define HAVE_SECTION(hold, name) \(hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL) place = NULL; if ((s->flags & SEC_ALLOC) == 0) ; else if ((s->flags & SEC_HAS_CONTENTS) == 0 && HAVE_SECTION (hold_bss, ".bss")) place = &hold_bss; else if ((s->flags & SEC_READONLY) == 0 && HAVE_SECTION (hold_data, ".data")) place = &hold_data; else if ((s->flags & SEC_CODE) == 0 && (s->flags & SEC_READONLY) != 0 && HAVE_SECTION (hold_rdata, ".rdata")) place = &hold_rdata; else if ((s->flags & SEC_READONLY) != 0 && HAVE_SECTION (hold_text, ".text")) place = &hold_text;#undef HAVE_SECTION /* Choose a unique name for the section. This will be needed if the same section name appears in the input file with different loadable or allocateable characteristics. */ outsecname = xstrdup (hold_section_name); if (bfd_get_section_by_name (output_bfd, outsecname) != NULL) { unsigned int len; char *newname; unsigned int i; len = strlen (outsecname); newname = xmalloc (len + 5); strcpy (newname, outsecname); i = 0; do { sprintf (newname + len, "%d", i); ++i; } while (bfd_get_section_by_name (output_bfd, newname) != NULL); free (outsecname); outsecname = newname; } /* Start building a list of statements for this section. */ old = stat_ptr; stat_ptr = &add; lang_list_init (stat_ptr); if (config.build_constructors) { /* If the name of the section is representable in C, then create symbols to mark the start and the end of the section. */ for (ps = outsecname; *ps != '\0'; ps++) if (! isalnum ((unsigned char) *ps) && *ps != '_') break; if (*ps == '\0') { char *symname; etree_type *e_align; symname = (char *) xmalloc (ps - outsecname + sizeof "___start_"); sprintf (symname, "___start_%s", outsecname); e_align = exp_unop (ALIGN_K, exp_intop ((bfd_vma) 1 << s->alignment_power)); lang_add_assignment (exp_assop ('=', symname, e_align)); } } if (link_info.relocateable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0) address = exp_intop ((bfd_vma) 0); else { /* All sections in an executable must be aligned to a page boundary. */ address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__")); } os = lang_enter_output_section_statement (outsecname, address, 0, (bfd_vma) 0, (etree_type *) NULL, (etree_type *) NULL, (etree_type *) NULL); wild_doit (&add_child, s, os, file); lang_leave_output_section_statement ((bfd_vma) 0, "*default*", (struct lang_output_section_phdr_list *) NULL, "*default*"); if (config.build_constructors && *ps == '\0') { char *symname; /* lang_leave_ouput_section_statement resets stat_ptr. Put stat_ptr back where we want it. */ if (place != NULL) stat_ptr = &add; symname = (char *) xmalloc (ps - outsecname + sizeof "___stop_"); sprintf (symname, "___stop_%s", outsecname); lang_add_assignment (exp_assop ('=', symname, exp_nameop (NAME, "."))); } stat_ptr = old; if (place != NULL) { asection *snew, **pps; snew = os->bfd_section; if (place->os->bfd_section != NULL || place->section != NULL) { /* Shuffle the section to make the output file look neater. */ if (place->section == NULL) {#if 0 /* Finding the end of the list is a little tricky. We make a wild stab at it by comparing section flags. */ flagword first_flags = place->os->bfd_section->flags; for (pps = &place->os->bfd_section->next; *pps != NULL && (*pps)->flags == first_flags; pps = &(*pps)->next) ; place->section = pps;#else /* Put orphans after the first section on the list. */ place->section = &place->os->bfd_section->next;#endif } /* Unlink the section. */ for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next) ; *pps = snew->next; /* Now tack it on to the "place->os" section list. */ snew->next = *place->section; *place->section = snew; } place->section = &snew->next; /* Save the end of this list. */ if (place->stmt == NULL) { /* Put the new statement list right at the head. */ *add.tail = place->os->header.next; place->os->header.next = add.head; } else { /* Put it after the last orphan statement we added. */ *add.tail = *place->stmt; *place->stmt = add.head; } place->stmt = add.tail; /* Save the end of this list. */ } } { lang_statement_union_type **pl = &os->children.head; if (dollar != NULL) { boolean found_dollar; /* The section name has a '$'. Sort it with the other '$' sections. */ found_dollar = false; for ( ; *pl != NULL; pl = &(*pl)->next) { lang_input_section_type *ls; const char *lname; if ((*pl)->header.type != lang_input_section_enum) continue; ls = &(*pl)->input_section; lname = bfd_get_section_name (ls->ifile->the_bfd, ls->section); if (strchr (lname, '$') == NULL) { if (found_dollar) break; } else { found_dollar = true; if (strcmp (secname, lname) < 0) break; } } } if (add_child.head != NULL) { add_child.head->next = *pl; *pl = add_child.head; } } free (hold_section_name); return true;}static booleangld_${EMULATION_NAME}_open_dynamic_archive (arch, search, entry) const char * arch ATTRIBUTE_UNUSED; search_dirs_type * search; lang_input_statement_type * entry;{ const char * filename; char * string; if (! entry->is_archive) return false; filename = entry->filename; string = (char *) xmalloc (strlen (search->name) + strlen (filename) + sizeof "/lib.a.dll"#ifdef DLL_SUPPORT + (pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0)#endif + 1); /* Try "libfoo.dll.a" first (preferred explicit import library for dll's */ sprintf (string, "%s/lib%s.dll.a", search->name, filename); if (! ldfile_try_open_bfd (string, entry)) { /* Try "foo.dll.a" next (alternate explicit import library for dll's */ sprintf (string, "%s/%s.dll.a", search->name, filename); if (! ldfile_try_open_bfd (string, entry)) {/* Try libfoo.a next. Normally, this would be interpreted as a static library, but it *could* be an import library. For backwards compatibility, libfoo.a needs to ==precede== libfoo.dll and foo.dll in the search, or sometimes errors occur when building legacy packages. Putting libfoo.a here means that in a failure case (i.e. the library -lfoo is not found) we will search for libfoo.a twice before giving up -- once here, and once when searching for a "static" lib. for a "static" lib.*/ /* Try "libfoo.a" (import lib, or static lib, but must take precedence over dll's) */ sprintf (string, "%s/lib%s.a", search->name, filename); if (! ldfile_try_open_bfd (string, entry)) {#ifdef DLL_SUPPORT if (pe_dll_search_prefix) { /* Try "<prefix>foo.dll" (preferred dll name, if specified) */ sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, filename); if (! ldfile_try_open_bfd (string, entry)) { /* Try "libfoo.dll" (default preferred dll name) */ sprintf (string, "%s/lib%s.dll", search->name, filename); if (! ldfile_try_open_bfd (string, entry)) { /* Finally, try "foo.dll" (alternate dll name) */ sprintf (string, "%s/%s.dll", search->name, filename); if (! ldfile_try_open_bfd (string, entry)) { free (string); return false; } } } } else /* pe_dll_search_prefix not specified */#endif { /* Try "libfoo.dll" (preferred dll name) */ sprintf (string, "%s/lib%s.dll", search->name, filename); if (! ldfile_try_open_bfd (string, entry)) { /* Finally, try "foo.dll" (alternate dll name) */ sprintf (string, "%s/%s.dll", search->name, filename); if (! ldfile_try_open_bfd (string, entry)) { free (string); return false; } } } } } } entry->filename = string; return true;}static intgld_${EMULATION_NAME}_find_potential_libraries (name, entry) char * name; lang_input_statement_type * entry;{ return ldfile_open_file_search (name, entry, "", ".lib");}static char *gld_${EMULATION_NAME}_get_script(isfile) 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 <<EOF{ *isfile = 0; if (link_info.relocateable == true && config.build_constructors == true) returnEOFsed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.cecho ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.csed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.cecho ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.csed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.cecho ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.csed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.cecho ' ; else return' >> e${EMULATION_NAME}.csed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.cecho '; }' >> e${EMULATION_NAME}.ccat >>e${EMULATION_NAME}.c <<EOFstruct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = { gld_${EMULATION_NAME}_before_parse, syslib_default, hll_default, gld_${EMULATION_NAME}_after_parse, gld_${EMULATION_NAME}_after_open, after_allocation_default, set_output_arch_default, ldemul_default_target, gld_${EMULATION_NAME}_before_allocation, gld_${EMULATION_NAME}_get_script, "${EMULATION_NAME}", "${OUTPUT_FORMAT}", gld_${EMULATION_NAME}_finish, /* finish */ NULL, /* create output section statements */ gld_${EMULATION_NAME}_open_dynamic_archive, gld_${EMULATION_NAME}_place_orphan, gld_${EMULATION_NAME}_set_symbols, gld_${EMULATION_NAME}_parse_args, gld_${EMULATION_NAME}_unrecognized_file, gld_${EMULATION_NAME}_list_options, gld_${EMULATION_NAME}_recognized_file, gld_${EMULATION_NAME}_find_potential_libraries};EOF
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?