mpw-eppcmac.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,226 行 · 第 1/2 页
C
1,226 行
/* _text */ oname = ".text"; start = true; break; case 1: /* _etext */ oname = ".text"; start = false; break; case 2: /* _data */ oname = ".data"; start = true; break; case 3: /* _edata */ oname = ".data"; start = false; break; case 4: case 5: /* _end and end */ oname = ".bss"; start = false; break; } os = lang_output_section_find (oname); if (start) { is->header.next = os->children.head; os->children.head = (lang_statement_union_type *) is; } else { is->header.next = NULL; lang_statement_append (&os->children, (lang_statement_union_type *) is, &is->header.next); } }}/* Read an import or export file. For an import file, this is called by the before_allocation emulation routine. For an export file, this is called by the parse_args emulation routine. */static voidgldppcmacos_read_file (filename, import) const char *filename; boolean import;{ struct obstack *o; FILE *f; int lineno; int c; boolean keep; const char *imppath; const char *impfile; const char *impmember; o = (struct obstack *) xmalloc (sizeof (struct obstack)); obstack_specify_allocation (o, 0, 0, xmalloc, gldppcmacos_free); f = fopen (filename, FOPEN_RT); if (f == NULL) { bfd_set_error (bfd_error_system_call); einfo ("%F%s: %E\n", filename); } keep = false; imppath = NULL; impfile = NULL; impmember = NULL; lineno = 0; while ((c = getc (f)) != EOF) { char *s; char *symname; boolean syscall; bfd_vma address; struct bfd_link_hash_entry *h; if (c != '\n') { obstack_1grow (o, c); continue; } obstack_1grow (o, '\0'); ++lineno; s = (char *) obstack_base (o); while (isspace ((unsigned char) *s)) ++s; if (*s == '\0' || *s == '*' || (*s == '#' && s[1] == ' ') || (! import && *s == '#' && s[1] == '!')) { obstack_free (o, obstack_base (o)); continue; } if (*s == '#' && s[1] == '!') { s += 2; while (isspace ((unsigned char) *s)) ++s; if (*s == '\0') { imppath = NULL; impfile = NULL; impmember = NULL; obstack_free (o, obstack_base (o)); } else if (*s == '(') einfo (_("%F%s%d: #! ([member]) is not supported in import files\n"), filename, lineno); else { char cs; char *file; (void) obstack_finish (o); keep = true; imppath = s; file = NULL; while (! isspace ((unsigned char) *s) && *s != '(' && *s != '\0') { if (*s == '/') file = s + 1; ++s; } if (file != NULL) { file[-1] = '\0'; impfile = file; if (imppath == file - 1) imppath = "/"; } else { impfile = imppath; imppath = ""; } cs = *s; *s = '\0'; while (isspace ((unsigned char) cs)) { ++s; cs = *s; } if (cs != '(') { impmember = ""; if (cs != '\0') einfo (_("%s:%d: warning: syntax error in import file\n"), filename, lineno); } else { ++s; impmember = s; while (*s != ')' && *s != '\0') ++s; if (*s == ')') *s = '\0'; else einfo (_("%s:%d: warning: syntax error in import file\n"), filename, lineno); } } continue; } /* This is a symbol to be imported or exported. */ symname = s; syscall = false; address = (bfd_vma) -1; while (! isspace ((unsigned char) *s) && *s != '\0') ++s; if (*s != '\0') { char *se; *s++ = '\0'; while (isspace ((unsigned char) *s)) ++s; se = s; while (! isspace ((unsigned char) *se) && *se != '\0') ++se; if (*se != '\0') { *se++ = '\0'; while (isspace ((unsigned char) *se)) ++se; if (*se != '\0') einfo (_("%s%d: warning: syntax error in import/export file\n"), filename, lineno); } if (strcasecmp (s, "svc") == 0 || strcasecmp (s, "syscall") == 0) syscall = true; else { char *end; address = strtoul (s, &end, 0); if (*end != '\0') einfo (_("%s:%d: warning: syntax error in import/export file\n"), filename, lineno); } } if (! import) { struct export_symbol_list *n; ldlang_add_undef (symname); n = ((struct export_symbol_list *) xmalloc (sizeof (struct export_symbol_list))); n->next = export_symbols; n->name = xstrdup (symname); n->syscall = syscall; export_symbols = n; } else { h = bfd_link_hash_lookup (link_info.hash, symname, false, false, true); if (h == NULL || h->type == bfd_link_hash_new) { /* We can just ignore attempts to import an unreferenced symbol. */ } else { if (! bfd_xcoff_import_symbol (output_bfd, &link_info, h, address, imppath, impfile, impmember)) einfo (_("%X%s:%d: failed to import symbol %s: %E\n"), filename, lineno, symname); } } obstack_free (o, obstack_base (o)); } if (obstack_object_size (o) > 0) { einfo (_("%s:%d: warning: ignoring unterminated last line\n"), filename, lineno); obstack_free (o, obstack_base (o)); } if (! keep) { obstack_free (o, NULL); free (o); }}/* This routine saves us from worrying about declaring free. */static voidgldppcmacos_free (p) PTR p;{ free (p);}/* This is called by the before_allocation routine via lang_for_each_statement. It looks for relocations and assignments to symbols. */static voidgldppcmacos_find_relocs (s) lang_statement_union_type *s;{ if (s->header.type == lang_reloc_statement_enum) { lang_reloc_statement_type *rs; rs = &s->reloc_statement; if (rs->name == NULL) einfo (_("%F%P: only relocations against symbols are permitted\n")); if (! bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name)) einfo (_("%F%P: bfd_xcoff_link_count_reloc failed: %E\n")); } if (s->header.type == lang_assignment_statement_enum) gldppcmacos_find_exp_assignment (s->assignment_statement.exp);}/* Look through an expression for an assignment statement. */static voidgldppcmacos_find_exp_assignment (exp) etree_type *exp;{ struct bfd_link_hash_entry *h; switch (exp->type.node_class) { case etree_provide: h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst, false, false, false); if (h == NULL) break; /* Fall through. */ case etree_assign: if (strcmp (exp->assign.dst, ".") != 0) { if (! bfd_xcoff_record_link_assignment (output_bfd, &link_info, exp->assign.dst)) einfo (_("%P%F: failed to record assignment to %s: %E\n"), exp->assign.dst); } gldppcmacos_find_exp_assignment (exp->assign.src); break; case etree_binary: gldppcmacos_find_exp_assignment (exp->binary.lhs); gldppcmacos_find_exp_assignment (exp->binary.rhs); break; case etree_trinary: gldppcmacos_find_exp_assignment (exp->trinary.cond); gldppcmacos_find_exp_assignment (exp->trinary.lhs); gldppcmacos_find_exp_assignment (exp->trinary.rhs); break; case etree_unary: gldppcmacos_find_exp_assignment (exp->unary.child); break; default: break; }}static char *gldppcmacos_get_script(isfile) int *isfile;{ *isfile = 0; if (link_info.relocateable == true && config.build_constructors == true) return"OUTPUT_FORMAT(\"xcoff-powermac\")\n\OUTPUT_ARCH(powerpc)\n\ENTRY(__start)\n\SECTIONS\n\{\n\ .pad 0 : { *(.pad) }\n\ .text 0 : {\n\ *(.text)\n\ *(.pr)\n\ *(.ro)\n\ *(.db)\n\ *(.gl)\n\ *(.xo)\n\ *(.ti)\n\ *(.tb)\n\ }\n\ .data 0 : {\n\ *(.data)\n\ *(.rw)\n\ *(.sv)\n\ *(.ua)\n\ . = ALIGN(4);\n\ CONSTRUCTORS\n\ *(.ds)\n\ *(.tc0)\n\ *(.tc)\n\ *(.td)\n\ }\n\ .bss : {\n\ *(.bss)\n\ *(.bs)\n\ *(.uc)\n\ *(COMMON)\n\ }\n\ .loader 0 : {\n\ *(.loader)\n\ }\n\ .debug 0 : {\n\ *(.debug)\n\ }\n\}\n\n" ; else if (link_info.relocateable == true) return"OUTPUT_FORMAT(\"xcoff-powermac\")\n\OUTPUT_ARCH(powerpc)\n\ENTRY(__start)\n\SECTIONS\n\{\n\ .pad 0 : { *(.pad) }\n\ .text 0 : {\n\ *(.text)\n\ *(.pr)\n\ *(.ro)\n\ *(.db)\n\ *(.gl)\n\ *(.xo)\n\ *(.ti)\n\ *(.tb)\n\ }\n\ .data 0 : {\n\ *(.data)\n\ *(.rw)\n\ *(.sv)\n\ *(.ua)\n\ . = ALIGN(4);\n\ *(.ds)\n\ *(.tc0)\n\ *(.tc)\n\ *(.td)\n\ }\n\ .bss : {\n\ *(.bss)\n\ *(.bs)\n\ *(.uc)\n\ *(COMMON)\n\ }\n\ .loader 0 : {\n\ *(.loader)\n\ }\n\ .debug 0 : {\n\ *(.debug)\n\ }\n\}\n\n" ; else if (!config.text_read_only) return"OUTPUT_FORMAT(\"xcoff-powermac\")\n\OUTPUT_ARCH(powerpc)\n\ SEARCH_DIR(/usr/local/powerpc-apple-macos/lib);\n\ENTRY(__start)\n\SECTIONS\n\{\n\ .pad 0 : { *(.pad) }\n\ .text : {\n\ PROVIDE (_text = .);\n\ *(.text)\n\ *(.pr)\n\ *(.ro)\n\ *(.db)\n\ *(.gl)\n\ *(.xo)\n\ *(.ti)\n\ *(.tb)\n\ PROVIDE (_etext = .);\n\ }\n\ .data 0 : {\n\ PROVIDE (_data = .);\n\ *(.data)\n\ *(.rw)\n\ *(.sv)\n\ *(.ua)\n\ . = ALIGN(4);\n\ CONSTRUCTORS\n\ *(.ds)\n\ *(.tc0)\n\ *(.tc)\n\ *(.td)\n\ PROVIDE (_edata = .);\n\ }\n\ .bss : {\n\ *(.bss)\n\ *(.bs)\n\ *(.uc)\n\ *(COMMON)\n\ PROVIDE (_end = .);\n\ PROVIDE (end = .);\n\ }\n\ .loader 0 : {\n\ *(.loader)\n\ }\n\ .debug 0 : {\n\ *(.debug)\n\ }\n\}\n\n" ; else if (!config.magic_demand_paged) return"OUTPUT_FORMAT(\"xcoff-powermac\")\n\OUTPUT_ARCH(powerpc)\n\ SEARCH_DIR(/usr/local/powerpc-apple-macos/lib);\n\ENTRY(__start)\n\SECTIONS\n\{\n\ .pad 0 : { *(.pad) }\n\ .text : {\n\ PROVIDE (_text = .);\n\ *(.text)\n\ *(.pr)\n\ *(.ro)\n\ *(.db)\n\ *(.gl)\n\ *(.xo)\n\ *(.ti)\n\ *(.tb)\n\ PROVIDE (_etext = .);\n\ }\n\ .data 0 : {\n\ PROVIDE (_data = .);\n\ *(.data)\n\ *(.rw)\n\ *(.sv)\n\ *(.ua)\n\ . = ALIGN(4);\n\ CONSTRUCTORS\n\ *(.ds)\n\ *(.tc0)\n\ *(.tc)\n\ *(.td)\n\ PROVIDE (_edata = .);\n\ }\n\ .bss : {\n\ *(.bss)\n\ *(.bs)\n\ *(.uc)\n\ *(COMMON)\n\ PROVIDE (_end = .);\n\ PROVIDE (end = .);\n\ }\n\ .loader 0 : {\n\ *(.loader)\n\ }\n\ .debug 0 : {\n\ *(.debug)\n\ }\n\}\n\n" ; else return"OUTPUT_FORMAT(\"xcoff-powermac\")\n\OUTPUT_ARCH(powerpc)\n\ SEARCH_DIR(/usr/local/powerpc-apple-macos/lib);\n\ENTRY(__start)\n\SECTIONS\n\{\n\ .pad 0 : { *(.pad) }\n\ .text : {\n\ PROVIDE (_text = .);\n\ *(.text)\n\ *(.pr)\n\ *(.ro)\n\ *(.db)\n\ *(.gl)\n\ *(.xo)\n\ *(.ti)\n\ *(.tb)\n\ PROVIDE (_etext = .);\n\ }\n\ .data 0 : {\n\ PROVIDE (_data = .);\n\ *(.data)\n\ *(.rw)\n\ *(.sv)\n\ *(.ua)\n\ . = ALIGN(4);\n\ CONSTRUCTORS\n\ *(.ds)\n\ *(.tc0)\n\ *(.tc)\n\ *(.td)\n\ PROVIDE (_edata = .);\n\ }\n\ .bss : {\n\ *(.bss)\n\ *(.bs)\n\ *(.uc)\n\ *(COMMON)\n\ PROVIDE (_end = .);\n\ PROVIDE (end = .);\n\ }\n\ .loader 0 : {\n\ *(.loader)\n\ }\n\ .debug 0 : {\n\ *(.debug)\n\ }\n\}\n\n"; }struct ld_emulation_xfer_struct ld_ppcmacos_emulation = { gldppcmacos_before_parse, syslib_default, hll_default, after_parse_default, gldppcmacos_after_open, after_allocation_default, set_output_arch_default, ldemul_default_target, gldppcmacos_before_allocation, gldppcmacos_get_script, "ppcmacos", "xcoff-powermac", 0, /* finish */ 0, /* create_output_section_statements */ 0, /* open_dynamic_archive */ 0, /* place_orphan */ 0, /* set_symbols */ gldppcmacos_parse_args, gldppcmacos_unrecognized_file};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?