aix.em

来自「基于4个mips核的noc设计」· EM 代码 · 共 1,057 行 · 第 1/2 页

EM
1,057
字号
# This shell script emits a C file. -*- C -*-# It does some substitutions.cat >e${EMULATION_NAME}.c <<EOF/* This file is is generated by a shell script.  DO NOT EDIT! *//* AIX emulation code for ${EMULATION_NAME}   Copyright 1991, 1993, 1995, 1996, 1997, 1998, 2000, 2001   Free Software Foundation, Inc.   Written by Steve Chamberlain <sac@cygnus.com>   AIX support by Ian Lance Taylor <ian@cygnus.com>This file is part of GLD, the Gnu Linker.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */#define TARGET_IS_${EMULATION_NAME}#include "bfd.h"#include "sysdep.h"#include "libiberty.h"#include "getopt.h"#include "obstack.h"#include "bfdlink.h"#include <ctype.h>#include "ld.h"#include "ldmain.h"#include "ldmisc.h"#include "ldexp.h"#include "ldlang.h"#include "ldfile.h"#include "ldemul.h"#include "ldctor.h"#include "ldgram.h"static void gld${EMULATION_NAME}_before_parse PARAMS ((void));static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **));static void gld${EMULATION_NAME}_after_open PARAMS ((void));static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));static void gld${EMULATION_NAME}_read_file PARAMS ((const char *, boolean));static void gld${EMULATION_NAME}_free PARAMS ((PTR));static void gld${EMULATION_NAME}_find_relocs  PARAMS ((lang_statement_union_type *));static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *));static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));/* The file alignment required for each section.  */static unsigned long file_align;/* The maximum size the stack is permitted to grow.  This is stored in   the a.out header.  */static unsigned long maxstack;/* The maximum data size.  This is stored in the a.out header.  */static unsigned long maxdata;/* Whether to perform garbage collection.  */static int gc = 1;/* The module type to use.  */static unsigned short modtype = ('1' << 8) | 'L';/* Whether the .text section must be read-only (i.e., no relocs   permitted).  */static int textro;/* Whether to implement Unix like linker semantics.  */static int unix_ld;/* Structure used to hold import file list.  */struct filelist{  struct filelist *next;  const char *name;};/* List of import files.  */static struct filelist *import_files;/* List of export symbols read from the export files.  */struct export_symbol_list{  struct export_symbol_list *next;  const char *name;  boolean syscall;};static struct export_symbol_list *export_symbols;/* This routine is called before anything else is done.  */static voidgld${EMULATION_NAME}_before_parse(){#ifndef TARGET_			/* I.e., if not generic.  */  ldfile_output_architecture = bfd_arch_${ARCH};#endif /* not TARGET_ */  config.has_shared = true;}/* Handle AIX specific options.  */static intgld${EMULATION_NAME}_parse_args (argc, argv)     int argc;     char **argv;{  int prevoptind = optind;  int prevopterr = opterr;  int indx;  int longind;  int optc;  long val;  char *end;#define OPTION_IGNORE (300)#define OPTION_AUTOIMP (OPTION_IGNORE + 1)#define OPTION_ERNOTOK (OPTION_AUTOIMP + 1)#define OPTION_EROK (OPTION_ERNOTOK + 1)#define OPTION_EXPORT (OPTION_EROK + 1)#define OPTION_IMPORT (OPTION_EXPORT + 1)#define OPTION_LOADMAP (OPTION_IMPORT + 1)#define OPTION_MAXDATA (OPTION_LOADMAP + 1)#define OPTION_MAXSTACK (OPTION_MAXDATA + 1)#define OPTION_MODTYPE (OPTION_MAXSTACK + 1)#define OPTION_NOAUTOIMP (OPTION_MODTYPE + 1)#define OPTION_NOSTRCMPCT (OPTION_NOAUTOIMP + 1)#define OPTION_PD (OPTION_NOSTRCMPCT + 1)#define OPTION_PT (OPTION_PD + 1)#define OPTION_STRCMPCT (OPTION_PT + 1)#define OPTION_UNIX (OPTION_STRCMPCT + 1)  static struct option longopts[] = {    {"basis", no_argument, NULL, OPTION_IGNORE},    {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},    {"bcomprld", no_argument, NULL, OPTION_IGNORE},    {"bcrld", no_argument, NULL, OPTION_IGNORE},    {"bcror31", no_argument, NULL, OPTION_IGNORE},    {"bD", required_argument, NULL, OPTION_MAXDATA},    {"bE", required_argument, NULL, OPTION_EXPORT},    {"bernotok", no_argument, NULL, OPTION_ERNOTOK},    {"berok", no_argument, NULL, OPTION_EROK},    {"berrmsg", no_argument, NULL, OPTION_IGNORE},    {"bexport", required_argument, NULL, OPTION_EXPORT},    {"bf", no_argument, NULL, OPTION_ERNOTOK},    {"bgc", no_argument, &gc, 1},    {"bh", required_argument, NULL, OPTION_IGNORE},    {"bhalt", required_argument, NULL, OPTION_IGNORE},    {"bI", required_argument, NULL, OPTION_IMPORT},    {"bimport", required_argument, NULL, OPTION_IMPORT},    {"bl", required_argument, NULL, OPTION_LOADMAP},    {"bloadmap", required_argument, NULL, OPTION_LOADMAP},    {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},    {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},    {"bM", required_argument, NULL, OPTION_MODTYPE},    {"bmodtype", required_argument, NULL, OPTION_MODTYPE},    {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},    {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},    {"bnoentry", no_argument, NULL, OPTION_IGNORE},    {"bnogc", no_argument, &gc, 0},    {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},    {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},    {"bnotextro", no_argument, &textro, 0},    {"bnro", no_argument, &textro, 0},    {"bpD", required_argument, NULL, OPTION_PD},    {"bpT", required_argument, NULL, OPTION_PT},    {"bro", no_argument, &textro, 1},    {"bS", required_argument, NULL, OPTION_MAXSTACK},    {"bso", no_argument, NULL, OPTION_AUTOIMP},    {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},    {"btextro", no_argument, &textro, 1},    {"static", no_argument, NULL, OPTION_NOAUTOIMP},    {"unix", no_argument, NULL, OPTION_UNIX},    {NULL, no_argument, NULL, 0}  };  /* Options supported by the AIX linker which we do not support: -f,     -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,     -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,     -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,     -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,     -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,     -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,     -bx, -bX, -bxref.  */  /* If the current option starts with -b, change the first : to an =.     The AIX linker uses : to separate the option from the argument;     changing it to = lets us treat it as a getopt option.  */  indx = optind;  if (indx == 0)    indx = 1;  if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)    {      char *s;      for (s = argv[indx]; *s != '\0'; s++)	{	  if (*s == ':')	    {	      *s = '=';	      break;	    }	}    }  /* We add s and u so to the short options list so that -s and -u on     the command line do not match -static and -unix.  */  opterr = 0;  optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);  opterr = prevopterr;  switch (optc)    {    case 's':    case 'u':    default:      optind = prevoptind;      return 0;    case 0:      /* Long option which just sets a flag.  */      break;    case 'D':      val = strtol (optarg, &end, 0);      if (*end != '\0')	einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);      else if (val != -1)	lang_section_start (".data", exp_intop (val));      break;    case 'H':      val = strtoul (optarg, &end, 0);      if (*end != '\0'	  || (val & (val - 1)) != 0)	einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);      else	file_align = val;      break;    case 'K':    case 'z':      /* FIXME: This should use the page size for the target system.  */      file_align = 4096;      break;    case 'T':      /* On AIX this is the same as GNU ld -Ttext.  When we see -T         number, we assume the AIX option is intended.  Otherwise, we         assume the usual GNU ld -T option is intended.  We can't just         ignore the AIX option, because gcc passes it to the linker.  */      val = strtoul (optarg, &end, 0);      if (*end != '\0')	{	  optind = prevoptind;	  return 0;	}      lang_section_start (".text", exp_intop (val));      break;    case OPTION_IGNORE:      break;    case OPTION_AUTOIMP:      link_info.static_link = false;      break;    case OPTION_ERNOTOK:      force_make_executable = false;      break;    case OPTION_EROK:      force_make_executable = true;      break;    case OPTION_EXPORT:      gld${EMULATION_NAME}_read_file (optarg, false);      break;    case OPTION_IMPORT:      {	struct filelist *n;	struct filelist **flpp;	n = (struct filelist *) xmalloc (sizeof (struct filelist));	n->next = NULL;	n->name = optarg;	flpp = &import_files;	while (*flpp != NULL)	  flpp = &(*flpp)->next;	*flpp = n;      }      break;    case OPTION_LOADMAP:      config.map_filename = optarg;      break;    case OPTION_MAXDATA:      val = strtoul (optarg, &end, 0);      if (*end != '\0')	einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n",	       optarg);      else	maxdata = val;      break;    case OPTION_MAXSTACK:      val = strtoul (optarg, &end, 0);      if (*end != '\0')	einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",	       optarg);      else	maxstack = val;      break;    case OPTION_MODTYPE:      if (*optarg == 'S')	{	  link_info.shared = true;	  ++optarg;	}      if (*optarg == '\0' || optarg[1] == '\0')	einfo ("%P: warning: ignoring invalid module type %s\n", optarg);      else	modtype = (*optarg << 8) | optarg[1];      break;    case OPTION_NOAUTOIMP:      link_info.static_link = true;      break;    case OPTION_NOSTRCMPCT:      link_info.traditional_format = true;      break;    case OPTION_PD:      /* This sets the page that the .data section is supposed to         start on.  The offset within the page should still be the         offset within the file, so we need to build an appropriate         expression.  */      val = strtoul (optarg, &end, 0);      if (*end != '\0')	einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);      else	{	  etree_type *t;	  t = exp_binop ('+',			 exp_intop (val),			 exp_binop ('&',				    exp_nameop (NAME, "."),				    exp_intop (0xfff)));	  t = exp_binop ('&',			 exp_binop ('+', t, exp_intop (31)),			 exp_intop (~ (bfd_vma) 31));	  lang_section_start (".data", t);	}      break;    case OPTION_PT:      /* This set the page that the .text section is supposed to start         on.  The offset within the page should still be the offset         within the file.  */      val = strtoul (optarg, &end, 0);      if (*end != '\0')	einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);      else	{	  etree_type *t;	  t = exp_binop ('+',			 exp_intop (val),			 exp_nameop (SIZEOF_HEADERS, NULL));	  t = exp_binop ('&',			 exp_binop ('+', t, exp_intop (31)),			 exp_intop (~ (bfd_vma) 31));	  lang_section_start (".text", t);	}      break;    case OPTION_STRCMPCT:      link_info.traditional_format = false;      break;    case OPTION_UNIX:      unix_ld = true;      break;    }  return 1;}/* This is called when an input file can not be recognized as a BFD   object or an archive.  If the file starts with #!, we must treat it   as an import file.  This is for AIX compatibility.  */static booleangld${EMULATION_NAME}_unrecognized_file (entry)     lang_input_statement_type *entry;{  FILE *e;  boolean ret;  e = fopen (entry->filename, FOPEN_RT);  if (e == NULL)    return false;  ret = false;  if (getc (e) == '#' && getc (e) == '!')    {      struct filelist *n;      struct filelist **flpp;      n = (struct filelist *) xmalloc (sizeof (struct filelist));      n->next = NULL;      n->name = entry->filename;      flpp = &import_files;      while (*flpp != NULL)	flpp = &(*flpp)->next;      *flpp = n;      ret = true;      entry->loaded = true;    }  fclose (e);  return ret;}/* This is called after the input files have been opened.  */static voidgld${EMULATION_NAME}_after_open (){  boolean r;  struct set_info *p;  /* Call ldctor_build_sets, after pretending that this is a     relocateable link.  We do this because AIX requires relocation     entries for all references to symbols, even in a final     executable.  Of course, we only want to do this if we are     producing an XCOFF output file.  */  r = link_info.relocateable;  if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)    link_info.relocateable = true;  ldctor_build_sets ();  link_info.relocateable = r;  /* For each set, record the size, so that the XCOFF backend can     output the correct csect length.  */  for (p = sets; p != (struct set_info *) NULL; p = p->next)    {      bfd_size_type size;      /* If the symbol is defined, we may have been invoked from	 collect, and the sets may already have been built, so we do	 not do anything.  */      if (p->h->type == bfd_link_hash_defined	  || p->h->type == bfd_link_hash_defweak)	continue;      if (p->reloc != BFD_RELOC_CTOR)	{	  /* Handle this if we need to.  */	  abort ();	}      size = (p->count + 2) * 4;      if (! bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))	einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");    }}/* This is called after the sections have been attached to output   sections, but before any sizes or addresses have been set.  */static voidgld${EMULATION_NAME}_before_allocation (){  struct filelist *fl;  struct export_symbol_list *el;  char *libpath;  asection *special_sections[6];  int i;  /* Handle the import and export files, if any.  */  for (fl = import_files; fl != NULL; fl = fl->next)    gld${EMULATION_NAME}_read_file (fl->name, true);  for (el = export_symbols; el != NULL; el = el->next)    {      struct bfd_link_hash_entry *h;      h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);      if (h == NULL)	einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");      if (! bfd_xcoff_export_symbol (output_bfd, &link_info, h, el->syscall))	einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");    }  /* Track down all relocations called for by the linker script (these     are typically constructor/destructor entries created by     CONSTRUCTORS) and let the backend know it will need to create     .loader relocs for them.  */  lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);  /* We need to build LIBPATH from the -L arguments.  If any -rpath     arguments were used, though, we use -rpath instead, as a GNU     extension.  */  if (command_line.rpath != NULL)    libpath = command_line.rpath;

⌨️ 快捷键说明

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