github.com/yanyiwu/go@v0.0.0-20150106053140-03d6637dbb7f/src/cmd/ld/lib.h (about)

     1  // Derived from Inferno utils/6l/l.h
     2  // http://code.google.com/p/inferno-os/source/browse/utils/6l/l.h
     3  //
     4  //	Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
     5  //	Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
     6  //	Portions Copyright © 1997-1999 Vita Nuova Limited
     7  //	Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
     8  //	Portions Copyright © 2004,2006 Bruce Ellis
     9  //	Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
    10  //	Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
    11  //	Portions Copyright © 2009 The Go Authors.  All rights reserved.
    12  //
    13  // Permission is hereby granted, free of charge, to any person obtaining a copy
    14  // of this software and associated documentation files (the "Software"), to deal
    15  // in the Software without restriction, including without limitation the rights
    16  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    17  // copies of the Software, and to permit persons to whom the Software is
    18  // furnished to do so, subject to the following conditions:
    19  //
    20  // The above copyright notice and this permission notice shall be included in
    21  // all copies or substantial portions of the Software.
    22  //
    23  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    24  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    25  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    26  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    27  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    28  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    29  // THE SOFTWARE.
    30  
    31  // Terrible but standard terminology.
    32  // A segment describes a block of file to load into memory.
    33  // A section further describes the pieces of that block for
    34  // use in debuggers and such.
    35  
    36  enum {
    37  	MAXIO		= 8192,
    38  };
    39  
    40  typedef struct Segment Segment;
    41  typedef struct Section Section;
    42  
    43  struct Segment
    44  {
    45  	uchar	rwx;		// permission as usual unix bits (5 = r-x etc)
    46  	uvlong	vaddr;	// virtual address
    47  	uvlong	len;		// length in memory
    48  	uvlong	fileoff;	// file offset
    49  	uvlong	filelen;	// length on disk
    50  	Section*	sect;
    51  };
    52  
    53  #pragma incomplete struct Elf64_Shdr
    54  
    55  struct Section
    56  {
    57  	uchar	rwx;
    58  	int16	extnum;
    59  	int32	align;
    60  	char	*name;
    61  	uvlong	vaddr;
    62  	uvlong	len;
    63  	Section	*next;	// in segment list
    64  	Segment	*seg;
    65  	struct Elf64_Shdr *elfsect;
    66  	uvlong	reloff;
    67  	uvlong	rellen;
    68  };
    69  
    70  extern	char	symname[];
    71  
    72  EXTERN	char*	INITENTRY;
    73  extern	char*	thestring;
    74  extern	LinkArch*	thelinkarch;
    75  EXTERN	char*	outfile;
    76  EXTERN	int	ndynexp;
    77  EXTERN	LSym**	dynexp;
    78  EXTERN	int	nldflag;
    79  EXTERN	char**	ldflag;
    80  EXTERN	int	havedynamic;
    81  EXTERN	int	funcalign;
    82  EXTERN	int	iscgo;
    83  EXTERN	int	elfglobalsymndx;
    84  EXTERN	char*	flag_installsuffix;
    85  EXTERN	int	flag_race;
    86  EXTERN	int flag_shared;
    87  EXTERN	char*	tracksym;
    88  EXTERN	char*	interpreter;
    89  EXTERN	char*	tmpdir;
    90  EXTERN	char*	extld;
    91  EXTERN	char*	extldflags;
    92  EXTERN	int	debug_s; // backup old value of debug['s']
    93  EXTERN	Link*	ctxt;
    94  EXTERN	int32	HEADR;
    95  EXTERN	int32	HEADTYPE;
    96  EXTERN	int32	INITRND;
    97  EXTERN	int64	INITTEXT;
    98  EXTERN	int64	INITDAT;
    99  EXTERN	char*	INITENTRY;		/* entry point */
   100  EXTERN	char*	noname;
   101  EXTERN	char*	paramspace;
   102  EXTERN	int	nerrors;
   103  
   104  EXTERN	int	linkmode;
   105  EXTERN	int64	liveness;
   106  
   107  // for dynexport field of LSym
   108  enum
   109  {
   110  	CgoExportDynamic = 1<<0,
   111  	CgoExportStatic = 1<<1,
   112  };
   113  
   114  EXTERN	Segment	segtext;
   115  EXTERN	Segment	segrodata;
   116  EXTERN	Segment	segdata;
   117  EXTERN	Segment	segdwarf;
   118  
   119  typedef struct Endian Endian;
   120  struct Endian
   121  {
   122  	uint16	(*e16)(uchar*);
   123  	uint32	(*e32)(uchar*);
   124  	uint64	(*e64)(uchar*);
   125  };
   126  
   127  extern Endian be, le;
   128  
   129  /* set by call to mywhatsys() */
   130  extern	char*	goroot;
   131  extern	char*	goarch;
   132  extern	char*	goos;
   133  
   134  /* whence for ldpkg */
   135  enum {
   136  	FileObj = 0,
   137  	ArchiveObj,
   138  	Pkgdef
   139  };
   140  
   141  typedef struct Header Header;
   142  struct Header {
   143  	char *name;
   144  	int val;
   145  };
   146  
   147  EXTERN	char*	headstring;
   148  extern	Header	headers[];
   149  
   150  #pragma	varargck	type	"Y"	LSym*
   151  #pragma	varargck	type	"Z"	char*
   152  #pragma	varargck	type	"i"	char*
   153  
   154  // buffered output
   155  
   156  EXTERN	Biobuf	bso;
   157  
   158  EXTERN struct
   159  {
   160  	char	cbuf[MAXIO];	/* output buffer */
   161  } buf;
   162  
   163  EXTERN	int	cbc;
   164  EXTERN	char*	cbp;
   165  EXTERN	char*	cbpmax;
   166  
   167  #define	cput(c)\
   168  	{ *cbp++ = c;\
   169  	if(--cbc <= 0)\
   170  		cflush(); }
   171  
   172  void	Lflag(char *arg);
   173  int	Yconv(Fmt *fp);
   174  int	Zconv(Fmt *fp);
   175  void	addexport(void);
   176  void	address(void);
   177  Section*addsection(Segment *seg, char *name, int rwx);
   178  void	addstrdata(char *name, char *value);
   179  vlong	addstring(LSym *s, char *str);
   180  void	asmelfsym(void);
   181  void	asmplan9sym(void);
   182  uint16	be16(uchar *b);
   183  uint32	be32(uchar *b);
   184  uint64	be64(uchar *b);
   185  void	callgraph(void);
   186  void	checkgo(void);
   187  void	cflush(void);
   188  void	codeblk(int64 addr, int64 size);
   189  vlong	cpos(void);
   190  void	cseek(vlong p);
   191  void	cwrite(void *buf, int n);
   192  void	datblk(int64 addr, int64 size);
   193  int	datcmp(LSym *s1, LSym *s2);
   194  vlong	datoff(vlong addr);
   195  void	deadcode(void);
   196  LSym*	decodetype_arrayelem(LSym *s);
   197  vlong	decodetype_arraylen(LSym *s);
   198  LSym*	decodetype_chanelem(LSym *s);
   199  int	decodetype_funcdotdotdot(LSym *s);
   200  int	decodetype_funcincount(LSym *s);
   201  LSym*	decodetype_funcintype(LSym *s, int i);
   202  int	decodetype_funcoutcount(LSym *s);
   203  LSym*	decodetype_funcouttype(LSym *s, int i);
   204  LSym*	decodetype_gcprog(LSym *s);
   205  uint8*	decodetype_gcmask(LSym *s);
   206  vlong	decodetype_ifacemethodcount(LSym *s);
   207  uint8	decodetype_kind(LSym *s);
   208  uint8	decodetype_noptr(LSym *s);
   209  uint8	decodetype_usegcprog(LSym *s);
   210  LSym*	decodetype_mapkey(LSym *s);
   211  LSym*	decodetype_mapvalue(LSym *s);
   212  LSym*	decodetype_ptrelem(LSym *s);
   213  vlong	decodetype_size(LSym *s);
   214  int	decodetype_structfieldcount(LSym *s);
   215  char*	decodetype_structfieldname(LSym *s, int i);
   216  vlong	decodetype_structfieldoffs(LSym *s, int i);
   217  LSym*	decodetype_structfieldtype(LSym *s, int i);
   218  void	dodata(void);
   219  void	dostkcheck(void);
   220  void	dostkoff(void);
   221  void	dosymtype(void);
   222  void	doversion(void);
   223  void	doweak(void);
   224  void	dynreloc(void);
   225  void	dynrelocsym(LSym *s);
   226  vlong	entryvalue(void);
   227  void	errorexit(void);
   228  void	follow(void);
   229  void	genasmsym(void (*put)(LSym*, char*, int, vlong, vlong, int, LSym*));
   230  void	gentext(void);
   231  void	growdatsize(vlong *datsizep, LSym *s);
   232  char*	headstr(int v);
   233  int	headtype(char *name);
   234  void	hostlink(void);
   235  void	hostobjs(void);
   236  int	iconv(Fmt *fp);
   237  void	importcycles(void);
   238  void	linkarchinit(void);
   239  void	ldelf(Biobuf *f, char *pkg, int64 len, char *pn);
   240  void	ldhostobj(void (*ld)(Biobuf*, char*, int64, char*), Biobuf *f, char *pkg, int64 len, char *pn, char *file);
   241  void	ldmacho(Biobuf *f, char *pkg, int64 len, char *pn);
   242  void	ldobj(Biobuf *f, char *pkg, int64 len, char *pn, char *file, int whence);
   243  void	ldpe(Biobuf *f, char *pkg, int64 len, char *pn);
   244  void	ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence);
   245  uint16	le16(uchar *b);
   246  uint32	le32(uchar *b);
   247  uint64	le64(uchar *b);
   248  void	libinit(void);
   249  LSym*	listsort(LSym *l, int (*cmp)(LSym*, LSym*), int off);
   250  void	loadinternal(char *name);
   251  void	loadlib(void);
   252  void	lputb(int32 l);
   253  void	lputl(int32 l);
   254  void*	mal(uint32 n);
   255  void	mark(LSym *s);
   256  void	mywhatsys(void);
   257  struct ar_hdr;
   258  void	objfile(char *file, char *pkg);
   259  void	patch(void);
   260  int	pathchar(void);
   261  void	pcln(void);
   262  void	pclntab(void);
   263  void	putelfsectionsym(LSym* s, int shndx);
   264  void	putelfsymshndx(vlong sympos, int shndx);
   265  void	putsymb(LSym *s, char *name, int t, vlong v, vlong size, int ver, LSym *typ);
   266  int	rbyoff(const void *va, const void *vb);
   267  void	reloc(void);
   268  void	relocsym(LSym *s);
   269  void	setheadtype(char *s);
   270  void	setinterp(char *s);
   271  void	setlinkmode(char *arg);
   272  void	span(void);
   273  void	strnput(char *s, int n);
   274  vlong	symaddr(LSym *s);
   275  void	symtab(void);
   276  void	textaddress(void);
   277  void	undef(void);
   278  void	unmal(void *v, uint32 n);
   279  void	usage(void);
   280  void	vputb(uint64 v);
   281  int	valuecmp(LSym *a, LSym *b);
   282  void	vputl(uint64 v);
   283  void	wputb(ushort w);
   284  void	wputl(ushort w);
   285  void	xdefine(char *p, int t, vlong v);
   286  void	zerosig(char *sp);
   287  void	archinit(void);
   288  void	diag(char *fmt, ...);
   289  
   290  #pragma	varargck	argpos	diag	1