dlltool.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,503 行 · 第 1/5 页

C
2,503
字号
#ifdef DLLTOOL_PPC/* the glue instruction, picks up the toc from the stw in *//* the above code: "lwz r2,4(r1)"                         */static bfd_vma ppc_glue_insn = 0x80410004;#endifstruct mac  {    const char *type;    const char *how_byte;    const char *how_short;    const char *how_long;    const char *how_asciz;    const char *how_comment;    const char *how_jump;    const char *how_global;    const char *how_space;    const char *how_align_short;    const char *how_align_long;    const char *how_default_as_switches;    const char *how_bfd_target;    enum bfd_architecture how_bfd_arch;    const unsigned char *how_jtab;    int how_jtab_size; /* size of the jtab entry */    int how_jtab_roff; /* offset into it for the ind 32 reloc into idata 5 */  };static const struct macmtable[] ={  {#define MARM 0    "arm", ".byte", ".short", ".long", ".asciz", "@",    "ldr\tip,[pc]\n\tldr\tpc,[ip]\n\t.long",    ".global", ".space", ".align\t2",".align\t4", "-mapcs-32",    "pe-arm-little", bfd_arch_arm,    arm_jtab, sizeof (arm_jtab), 8  }  ,  {#define M386 1    "i386", ".byte", ".short", ".long", ".asciz", "#",    "jmp *", ".global", ".space", ".align\t2",".align\t4", "",    "pe-i386",bfd_arch_i386,    i386_jtab, sizeof (i386_jtab), 2  }  ,  {#define MPPC 2    "ppc", ".byte", ".short", ".long", ".asciz", "#",    "jmp *", ".global", ".space", ".align\t2",".align\t4", "",    "pe-powerpcle",bfd_arch_powerpc,    ppc_jtab, sizeof (ppc_jtab), 0  }  ,  {#define MTHUMB 3    "thumb", ".byte", ".short", ".long", ".asciz", "@",    "push\t{r6}\n\tldr\tr6, [pc, #8]\n\tldr\tr6, [r6]\n\tmov\tip, r6\n\tpop\t{r6}\n\tbx\tip",    ".global", ".space", ".align\t2",".align\t4", "-mthumb-interwork",    "pe-arm-little", bfd_arch_arm,    thumb_jtab, sizeof (thumb_jtab), 12  }  ,#define MARM_INTERWORK 4  {    "arm_interwork", ".byte", ".short", ".long", ".asciz", "@",    "ldr\tip,[pc]\n\tldr\tip,[ip]\n\tbx\tip\n\t.long",    ".global", ".space", ".align\t2",".align\t4", "-mthumb-interwork",    "pe-arm-little", bfd_arch_arm,    arm_interwork_jtab, sizeof (arm_interwork_jtab), 12  }  ,  {#define MMCORE_BE 5    "mcore-be", ".byte", ".short", ".long", ".asciz", "//",    "lrw r1,[1f]\n\tld.w r1,(r1,0)\n\tjmp r1\n\tnop\n1:.long",    ".global", ".space", ".align\t2",".align\t4", "",    "pe-mcore-big", bfd_arch_mcore,    mcore_be_jtab, sizeof (mcore_be_jtab), 8  }  ,  {#define MMCORE_LE 6    "mcore-le", ".byte", ".short", ".long", ".asciz", "//",    "lrw r1,[1f]\n\tld.w r1,(r1,0)\n\tjmp r1\n\tnop\n1:.long",    ".global", ".space", ".align\t2",".align\t4", "-EL",    "pe-mcore-little", bfd_arch_mcore,    mcore_le_jtab, sizeof (mcore_le_jtab), 8  }  ,  {#define MMCORE_ELF 7    "mcore-elf-be", ".byte", ".short", ".long", ".asciz", "//",    "lrw r1,[1f]\n\tld.w r1,(r1,0)\n\tjmp r1\n\tnop\n1:.long",    ".global", ".space", ".align\t2",".align\t4", "",    "elf32-mcore-big", bfd_arch_mcore,    mcore_be_jtab, sizeof (mcore_be_jtab), 8  }  ,  {#define MMCORE_ELF_LE 8    "mcore-elf-le", ".byte", ".short", ".long", ".asciz", "//",    "lrw r1,[1f]\n\tld.w r1,(r1,0)\n\tjmp r1\n\tnop\n1:.long",    ".global", ".space", ".align\t2",".align\t4", "-EL",    "elf32-mcore-little", bfd_arch_mcore,    mcore_le_jtab, sizeof (mcore_le_jtab), 8  }  ,  {#define MARM_EPOC 9    "arm-epoc", ".byte", ".short", ".long", ".asciz", "@",    "ldr\tip,[pc]\n\tldr\tpc,[ip]\n\t.long",    ".global", ".space", ".align\t2",".align\t4", "",    "epoc-pe-arm-little", bfd_arch_arm,    arm_jtab, sizeof (arm_jtab), 8  }  ,  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }};typedef struct dlist{  char *text;  struct dlist *next;}dlist_type;typedef struct export  {    const char *name;    const char *internal_name;    int ordinal;    int constant;    int noname;    int data;    int hint;    struct export *next;  }export_type;/* A list of symbols which we should not export.  */ struct string_list{  struct string_list *next;  char *string;};static struct string_list *excludes;static const char *rvaafter PARAMS ((int));static const char *rvabefore PARAMS ((int));static const char *asm_prefix PARAMS ((int));static void append_import PARAMS ((const char *, const char *, int));static void run PARAMS ((const char *, char *));static void scan_drectve_symbols PARAMS ((bfd *));static void scan_filtered_symbols PARAMS ((bfd *, PTR, long, unsigned int));static void add_excludes PARAMS ((const char *));static boolean match_exclude PARAMS ((const char *));static void set_default_excludes PARAMS ((void));static long filter_symbols PARAMS ((bfd *, PTR, long, unsigned int));static void scan_all_symbols PARAMS ((bfd *));static void scan_open_obj_file PARAMS ((bfd *));static void scan_obj_file PARAMS ((const char *));static void dump_def_info PARAMS ((FILE *));static int sfunc PARAMS ((const void *, const void *));static void flush_page PARAMS ((FILE *, long *, int, int));static void gen_def_file PARAMS ((void));static void generate_idata_ofile PARAMS ((FILE *));static void gen_exp_file PARAMS ((void));static const char *xlate PARAMS ((const char *));#if 0static void dump_iat PARAMS ((FILE *, export_type *));#endifstatic char *make_label PARAMS ((const char *, const char *));static bfd *make_one_lib_file PARAMS ((export_type *, int));static bfd *make_head PARAMS ((void));static bfd *make_tail PARAMS ((void));static void gen_lib_file PARAMS ((void));static int pfunc PARAMS ((const void *, const void *));static int nfunc PARAMS ((const void *, const void *));static void remove_null_names PARAMS ((export_type **));static void dtab PARAMS ((export_type **));static void process_duplicates PARAMS ((export_type **));static void fill_ordinals PARAMS ((export_type **));static int alphafunc PARAMS ((const void *, const void *));static void mangle_defs PARAMS ((void));static void usage PARAMS ((FILE *, int));static void inform PARAMS ((const char *, ...));static void#ifdef __STDC__inform (const char * message, ...)#elseinform (message, va_alist)     const char * message;     va_dcl#endif{  va_list args;    if (!verbose)    return;#ifdef __STDC__  va_start (args, message);#else  va_start (args);#endif  report (message, args);    va_end (args);}static const char *rvaafter (machine)     int machine;{  switch (machine)    {    case MARM:    case M386:    case MPPC:    case MTHUMB:    case MARM_INTERWORK:    case MMCORE_BE:    case MMCORE_LE:    case MMCORE_ELF:    case MMCORE_ELF_LE:    case MARM_EPOC:      break;    default:      /* xgettext:c-format */      fatal (_("Internal error: Unknown machine type: %d"), machine);      break;    }  return "";}static const char *rvabefore (machine)     int machine;{  switch (machine)    {    case MARM:    case M386:    case MPPC:    case MTHUMB:    case MARM_INTERWORK:    case MMCORE_BE:    case MMCORE_LE:    case MMCORE_ELF:    case MMCORE_ELF_LE:    case MARM_EPOC:      return ".rva\t";    default:      /* xgettext:c-format */      fatal (_("Internal error: Unknown machine type: %d"), machine);      break;    }  return "";}static const char *asm_prefix (machine)     int machine;{  switch (machine)    {    case MARM:    case MPPC:    case MTHUMB:    case MARM_INTERWORK:    case MMCORE_BE:    case MMCORE_LE:    case MMCORE_ELF:    case MMCORE_ELF_LE:    case MARM_EPOC:      break;    case M386:      return "_";    default:      /* xgettext:c-format */      fatal (_("Internal error: Unknown machine type: %d"), machine);      break;    }  return "";}#define ASM_BYTE 	mtable[machine].how_byte#define ASM_SHORT 	mtable[machine].how_short#define ASM_LONG	mtable[machine].how_long#define ASM_TEXT	mtable[machine].how_asciz#define ASM_C 		mtable[machine].how_comment#define ASM_JUMP 	mtable[machine].how_jump#define ASM_GLOBAL	mtable[machine].how_global#define ASM_SPACE	mtable[machine].how_space#define ASM_ALIGN_SHORT mtable[machine].how_align_short#define ASM_RVA_BEFORE 	rvabefore(machine)#define ASM_RVA_AFTER  	rvaafter(machine)#define ASM_PREFIX	asm_prefix(machine)#define ASM_ALIGN_LONG  mtable[machine].how_align_long#define HOW_BFD_READ_TARGET  0  /* always default*/#define HOW_BFD_WRITE_TARGET mtable[machine].how_bfd_target#define HOW_BFD_ARCH    mtable[machine].how_bfd_arch#define HOW_JTAB        mtable[machine].how_jtab#define HOW_JTAB_SIZE   mtable[machine].how_jtab_size#define HOW_JTAB_ROFF   mtable[machine].how_jtab_roff#define ASM_SWITCHES    mtable[machine].how_default_as_switchesstatic char **oav;voidprocess_def_file (name)     const char *name;{  FILE *f = fopen (name, FOPEN_RT);    if (!f)    /* xgettext:c-format */    fatal (_("Can't open def file: %s"), name);  yyin = f;  /* xgettext:c-format */  inform (_("Processing def file: %s"), name);    yyparse ();  inform (_("Processed def file"));}/**********************************************************************//* Communications with the parser */static const char *d_name;	/* Arg to NAME or LIBRARY */static int d_nfuncs;		/* Number of functions exported */static int d_named_nfuncs;	/* Number of named functions exported */static int d_low_ord;		/* Lowest ordinal index */static int d_high_ord;		/* Highest ordinal index */static export_type *d_exports;	/*list of exported functions */static export_type **d_exports_lexically;	/* vector of exported functions in alpha order */static dlist_type *d_list;	/* Descriptions */static dlist_type *a_list;	/* Stuff to go in directives */static int d_is_dll;static int d_is_exe;intyyerror (err)     const char * err ATTRIBUTE_UNUSED;{  /* xgettext:c-format */  non_fatal (_("Syntax error in def file %s:%d"), def_file, linenumber);    return 0;}voiddef_exports (name, internal_name, ordinal, noname, constant, data)     const char *name;     const char *internal_name;     int ordinal;     int noname;     int constant;     int data;{  struct export *p = (struct export *) xmalloc (sizeof (*p));  p->name = name;  p->internal_name = internal_name ? internal_name : name;  p->ordinal = ordinal;  p->constant = constant;  p->noname = noname;  p->data = data;  p->next = d_exports;  d_exports = p;  d_nfuncs++;}voiddef_name (name, base)     const char *name;     int base;{  /* xgettext:c-format */  inform (_("NAME: %s base: %x"), name, base);    if (d_is_dll)    non_fatal (_("Can't have LIBRARY and NAME"));    d_name = name;  /* if --dllname not provided, use the one in the DEF file.     FIXME: Is this appropriate for executables? */  if (! dll_name)    dll_name = xstrdup (name);  d_is_exe = 1;}voiddef_library (name, base)     const char *name;     int base;{  /* xgettext:c-format */  inform (_("LIBRARY: %s base: %x"), name, base);    if (d_is_exe)    non_fatal (_("Can't have LIBRARY and NAME"));    d_name = name;  /* if --dllname not provided, use the one in the DEF file. */  if (! dll_name)    dll_name = xstrdup (name);  d_is_dll = 1;}voiddef_description (desc)     const char *desc;{  dlist_type *d = (dlist_type *) xmalloc (sizeof (dlist_type));  d->text = xstrdup (desc);  d->next = d_list;  d_list = d;}voidnew_directive (dir)     char *dir;{  dlist_type *d = (dlist_type *) xmalloc (sizeof (dlist_type));  d->text = xstrdup (dir);  d->next = a_list;  a_list = d;}voiddef_heapsize (reserve, commit)     int reserve;     int commit;{  char b[200];  if (commit > 0)    sprintf (b, "-heap 0x%x,0x%x ", reserve, commit);  else    sprintf (b, "-heap 0x%x ", reserve);  new_directive (xstrdup (b));}voiddef_stacksize (reserve, commit)     int reserve;     int commit;{  char b[200];  if (commit > 0)    sprintf (b, "-stack 0x%x,0x%x ", reserve, commit);  else    sprintf (b, "-stack 0x%x ", reserve);  new_directive (xstrdup (b));}/* append_import simply adds the given import definition to the global   import_list.  It is used by def_import.  */static voidappend_import (symbol_name, dll_name, func_ordinal)     const char *symbol_name;     const char *dll_name;     int func_ordinal;{  iheadtype **pq;  iheadtype *q;  for (pq = &import_list; *pq != NULL; pq = &(*pq)->next)    {      if (strcmp ((*pq)->dllname, dll_name) == 0)	{	  q = *pq;	  q->functail->next = xmalloc (sizeof (ifunctype));	  q->functail = q->functail->next;	  q->functail->ord  = func_ordinal;	  q->functail->name = xstrdup (symbol_name);	  q->functail->next = NULL;	  q->nfuncs++;	  return;	}    }  q = xmalloc (sizeof (iheadtype));  q->dllname = xstrdup (dll_name);  q->nfuncs = 1;  q->funchead = xmalloc (sizeof (ifunctype));  q->functail = q->funchead;  q->next = NULL;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?