elf32.em
来自「基于4个mips核的noc设计」· EM 代码 · 共 1,533 行 · 第 1/3 页
EM
1,533 行
{ /* We have already placed a section with this name. */ wild_doit (&os->children, s, os, file); return true; } } if (hold_text.os == NULL) hold_text.os = lang_output_section_find (".text"); /* If this is a final link, then always put .gnu.warning.SYMBOL sections into the .text section to get them out of the way. */ if (! link_info.shared && ! link_info.relocateable && strncmp (secname, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0 && hold_text.os != NULL) { wild_doit (&hold_text.os->children, s, hold_text.os, file); return true; } /* Decide which segment the section should go in based on the section name and section flags. We put loadable .note sections right after the .interp section, so that the PT_NOTE segment is stored right after the program headers where the OS can read it in the first page. */#define HAVE_SECTION(hold, name) \(hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL) if (s->flags & SEC_EXCLUDE) return false; place = NULL; if ((s->flags & SEC_ALLOC) == 0) ; else if ((s->flags & SEC_LOAD) != 0 && strncmp (secname, ".note", 5) == 0 && HAVE_SECTION (hold_interp, ".interp")) place = &hold_interp; else if ((s->flags & SEC_HAS_CONTENTS) == 0 && HAVE_SECTION (hold_bss, ".bss")) place = &hold_bss; else if ((s->flags & SEC_SMALL_DATA) != 0 && HAVE_SECTION (hold_sdata, ".sdata")) place = &hold_sdata; else if ((s->flags & SEC_READONLY) == 0 && HAVE_SECTION (hold_data, ".data")) place = &hold_data; else if (strncmp (secname, ".rel", 4) == 0 && (hold_rel.os != NULL || (hold_rel.os = output_rel_find ()) != NULL)) place = &hold_rel; else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY && HAVE_SECTION (hold_rodata, ".rodata")) place = &hold_rodata; else if ((s->flags & (SEC_CODE | SEC_READONLY)) == (SEC_CODE | SEC_READONLY) && hold_text.os != NULL) 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 allocatable characteristics. */ outsecname = secname; if (bfd_get_section_by_name (output_bfd, outsecname) != NULL) { outsecname = bfd_get_unique_section_name (output_bfd, outsecname, &count); if (outsecname == NULL) einfo ("%F%P: place_orphan failed: %E\n"); } /* Start building a list of statements for this section. First save the current statement pointer. */ old = stat_ptr; /* If we have found an appropriate place for the output section statements for this orphan, add them to our own private list, inserting them later into the global statement list. */ if (place != NULL) { 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 address = NULL; os = lang_enter_output_section_statement (outsecname, address, 0, (bfd_vma) 0, (etree_type *) NULL, (etree_type *) NULL, (etree_type *) NULL); wild_doit (&os->children, 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, "."))); } /* Restore the global list pointer. */ stat_ptr = old; if (place != NULL) { asection *snew, **pps; snew = os->bfd_section; if (place->section != NULL || (place->os->bfd_section != NULL && place->os->bfd_section != snew)) { /* Shuffle the section to make the output file look neater. This is really only cosmetic. */ 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 (add.head != NULL) { /* We try to put the output statements in some sort of reasonable order here, because they determine the final load addresses of the orphan sections. */ 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; } /* Fix the global list pointer if we happened to tack our new list at the tail. */ if (*old->tail == add.head) old->tail = add.tail; /* Save the end of this list. */ place->stmt = add.tail; } } return true;}EOFfiif test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; thencat >>e${EMULATION_NAME}.c <<EOFstatic char *gld${EMULATION_NAME}_get_script (isfile) int *isfile;EOFif test -n "$COMPILE_IN"then# 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}.cif test -n "$GENERATE_SHLIB_SCRIPT" ; thenecho ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.csed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.cfiecho ' ; else return' >> e${EMULATION_NAME}.csed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.cecho '; }' >> e${EMULATION_NAME}.celse# Scripts read from the filesystem.cat >>e${EMULATION_NAME}.c <<EOF{ *isfile = 1; if (link_info.relocateable == true && config.build_constructors == true) return "ldscripts/${EMULATION_NAME}.xu"; else if (link_info.relocateable == true) return "ldscripts/${EMULATION_NAME}.xr"; else if (!config.text_read_only) return "ldscripts/${EMULATION_NAME}.xbn"; else if (!config.magic_demand_paged) return "ldscripts/${EMULATION_NAME}.xn"; else if (link_info.shared) return "ldscripts/${EMULATION_NAME}.xs"; else return "ldscripts/${EMULATION_NAME}.x";}EOFfifiif test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; thenif test x"$LDEMUL_PARSE_ARGS" != xgld"$EMULATION_NAME"_parse_args; thenif test -n "$PARSE_AND_LIST_PROLOGUE" ; thencat >>e${EMULATION_NAME}.c <<EOF $PARSE_AND_LIST_PROLOGUEEOFficat >>e${EMULATION_NAME}.c <<EOF#include "getopt.h"#define OPTION_DISABLE_NEW_DTAGS (400)#define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1)#define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1)static struct option longopts[] ={EOFif test x"$GENERATE_SHLIB_SCRIPT" = xyes; thencat >>e${EMULATION_NAME}.c <<EOF /* getopt allows abbreviations, so we do this to stop it from treating -d/-e as abbreviations for these options. */ {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS}, {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS}, {"Bgroup", no_argument, NULL, OPTION_GROUP}, {"Bgroup", no_argument, NULL, OPTION_GROUP},EOFfiif test -n "$PARSE_AND_LIST_LONGOPTS" ; thencat >>e${EMULATION_NAME}.c <<EOF $PARSE_AND_LIST_LONGOPTSEOFficat >>e${EMULATION_NAME}.c <<EOF {NULL, no_argument, NULL, 0}};static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **));static intgld${EMULATION_NAME}_parse_args (argc, argv) int argc; char ** argv;{ int longind; int optc; static int prevoptind = -1; int prevopterr = opterr; int wanterror; if (prevoptind != optind) opterr = 0; wanterror = opterr; prevoptind = optind; optc = getopt_long_only (argc, argv, "-${PARSE_AND_LIST_SHORTOPTS}z:", longopts, &longind); opterr = prevopterr; switch (optc) { default: if (wanterror) xexit (1); optind = prevoptind; return 0;EOFif test x"$GENERATE_SHLIB_SCRIPT" = xyes; thencat >>e${EMULATION_NAME}.c <<EOF case OPTION_DISABLE_NEW_DTAGS: link_info.new_dtags = false; break; case OPTION_ENABLE_NEW_DTAGS: link_info.new_dtags = true; break; case OPTION_GROUP: link_info.flags_1 |= (bfd_vma) DF_1_GROUP; /* Groups must be self-contained. */ link_info.no_undefined = true; break; case 'z': if (strcmp (optarg, "initfirst") == 0) link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST; else if (strcmp (optarg, "interpose") == 0) link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE; else if (strcmp (optarg, "loadfltr") == 0) link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR; else if (strcmp (optarg, "nodefaultlib") == 0) link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB; else if (strcmp (optarg, "nodelete") == 0) link_info.flags_1 |= (bfd_vma) DF_1_NODELETE; else if (strcmp (optarg, "nodlopen") == 0) link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN; else if (strcmp (optarg, "nodump") == 0) link_info.flags_1 |= (bfd_vma) DF_1_NODUMP; else if (strcmp (optarg, "now") == 0) { link_info.flags |= (bfd_vma) DF_BIND_NOW; link_info.flags_1 |= (bfd_vma) DF_1_NOW; } else if (strcmp (optarg, "origin") == 0) { link_info.flags |= (bfd_vma) DF_ORIGIN; link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN; } else if (strcmp (optarg, "defs") == 0) link_info.no_undefined = true; /* What about the other Solaris -z options? FIXME. */ break;EOFfiif test -n "$PARSE_AND_LIST_ARGS_CASES" ; thencat >>e${EMULATION_NAME}.c <<EOF $PARSE_AND_LIST_ARGS_CASESEOFficat >>e${EMULATION_NAME}.c <<EOF } return 1;}EOFfiif test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; thencat >>e${EMULATION_NAME}.c <<EOFstatic void gld${EMULATION_NAME}_list_options PARAMS ((FILE * file));static voidgld${EMULATION_NAME}_list_options (file) FILE * file;{EOFif test x"$GENERATE_SHLIB_SCRIPT" = xyes; thencat >>e${EMULATION_NAME}.c <<EOF fprintf (file, _(" -Bgroup\t\tSelects group name lookup rules for DSO\n")); fprintf (file, _(" --disable-new-dtags\tDisable new dynamic tags\n")); fprintf (file, _(" --enable-new-dtags\tEnable new dynamic tags\n")); fprintf (file, _(" -z defs\t\tDisallows undefined symbols\n")); fprintf (file, _(" -z initfirst\t\tMark DSO to be initialized first at runtime\n")); fprintf (file, _(" -z interpose\t\tMark object to interpose all DSOs but executable\n")); fprintf (file, _(" -z loadfltr\t\tMark object requiring immediate process\n")); fprintf (file, _(" -z nodefaultlib\tMark object not to use default search paths\n")); fprintf (file, _(" -z nodelete\t\tMark DSO non-deletable at runtime\n")); fprintf (file, _(" -z nodlopen\t\tMark DSO not available to dlopen\n")); fprintf (file, _(" -z nodump\t\tMark DSO not available to dldump\n")); fprintf (file, _(" -z now\t\tMark object non-lazy runtime binding\n")); fprintf (file, _(" -z origin\t\tMark object requiring immediate \$ORIGIN processing\n")); fprintf (file, _("\t\t\t at runtime\n")); fprintf (file, _(" -z KEYWORD\t\tIgnored for Solaris compatibility\n"));EOFfiif test -n "$PARSE_AND_LIST_OPTIONS" ; thencat >>e${EMULATION_NAME}.c <<EOF $PARSE_AND_LIST_OPTIONSEOFficat >>e${EMULATION_NAME}.c <<EOF}EOFif test -n "$PARSE_AND_LIST_EPILOGUE" ; thencat >>e${EMULATION_NAME}.c <<EOF $PARSE_AND_LIST_EPILOGUEEOFfifielseif test x"$LDEMUL_PARSE_ARGS" != xgld"$EMULATION_NAME"_parse_args; thencat >>e${EMULATION_NAME}.c <<EOF#define gld${EMULATION_NAME}_parse_args NULLEOFfiif test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; thencat >>e${EMULATION_NAME}.c <<EOF#define gld${EMULATION_NAME}_list_options NULLEOFfificat >>e${EMULATION_NAME}.c <<EOFstruct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation ={ ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse}, ${LDEMUL_SYSLIB-syslib_default}, ${LDEMUL_HLL-hll_default}, ${LDEMUL_AFTER_PARSE-after_parse_default}, ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open}, ${LDEMUL_AFTER_ALLOCATION-after_allocation_default}, ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default}, ${LDEMUL_CHOOSE_TARGET-ldemul_default_target}, ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}, ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script}, "${EMULATION_NAME}", "${OUTPUT_FORMAT}", ${LDEMUL_FINISH-NULL}, ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL}, ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive}, ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan}, ${LDEMUL_SET_SYMBOLS-NULL}, ${LDEMUL_PARSE_ARGS-gld${EMULATION_NAME}_parse_args}, ${LDEMUL_UNRECOGNIZED_FILE-NULL}, ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options}, ${LDEMUL_RECOGNIZED_FILE-NULL}, ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},};EOF
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?