github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/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 typedef struct Segment Segment; 37 typedef struct Section Section; 38 39 struct Segment 40 { 41 uchar rwx; // permission as usual unix bits (5 = r-x etc) 42 uvlong vaddr; // virtual address 43 uvlong len; // length in memory 44 uvlong fileoff; // file offset 45 uvlong filelen; // length on disk 46 Section* sect; 47 }; 48 49 #pragma incomplete struct Elf64_Shdr 50 51 struct Section 52 { 53 uchar rwx; 54 int16 extnum; 55 int32 align; 56 char *name; 57 uvlong vaddr; 58 uvlong len; 59 Section *next; // in segment list 60 Segment *seg; 61 struct Elf64_Shdr *elfsect; 62 uvlong reloff; 63 uvlong rellen; 64 }; 65 66 extern char symname[]; 67 68 EXTERN char* INITENTRY; 69 extern char* thestring; 70 extern LinkArch* thelinkarch; 71 EXTERN char* outfile; 72 EXTERN int ndynexp; 73 EXTERN LSym** dynexp; 74 EXTERN int nldflag; 75 EXTERN char** ldflag; 76 EXTERN int havedynamic; 77 EXTERN int funcalign; 78 EXTERN int iscgo; 79 EXTERN int elfglobalsymndx; 80 EXTERN char* flag_installsuffix; 81 EXTERN int flag_race; 82 EXTERN int flag_shared; 83 EXTERN char* tracksym; 84 EXTERN char* interpreter; 85 EXTERN char* tmpdir; 86 EXTERN char* extld; 87 EXTERN char* extldflags; 88 EXTERN int debug_s; // backup old value of debug['s'] 89 EXTERN Link* ctxt; 90 EXTERN int32 HEADR; 91 EXTERN int32 HEADTYPE; 92 EXTERN int32 INITRND; 93 EXTERN int64 INITTEXT; 94 EXTERN int64 INITDAT; 95 EXTERN char* INITENTRY; /* entry point */ 96 EXTERN char* noname; 97 EXTERN char* paramspace; 98 EXTERN int nerrors; 99 100 EXTERN int linkmode; 101 EXTERN int64 liveness; 102 103 // for dynexport field of LSym 104 enum 105 { 106 CgoExportDynamic = 1<<0, 107 CgoExportStatic = 1<<1, 108 }; 109 110 EXTERN Segment segtext; 111 EXTERN Segment segrodata; 112 EXTERN Segment segdata; 113 EXTERN Segment segdwarf; 114 115 typedef struct Endian Endian; 116 struct Endian 117 { 118 uint16 (*e16)(uchar*); 119 uint32 (*e32)(uchar*); 120 uint64 (*e64)(uchar*); 121 }; 122 123 extern Endian be, le; 124 125 /* set by call to mywhatsys() */ 126 extern char* goroot; 127 extern char* goarch; 128 extern char* goos; 129 130 /* whence for ldpkg */ 131 enum { 132 FileObj = 0, 133 ArchiveObj, 134 Pkgdef 135 }; 136 137 typedef struct Header Header; 138 struct Header { 139 char *name; 140 int val; 141 }; 142 143 EXTERN char* headstring; 144 extern Header headers[]; 145 146 #pragma varargck type "Y" LSym* 147 #pragma varargck type "Z" char* 148 #pragma varargck type "i" char* 149 150 // buffered output 151 152 EXTERN Biobuf bso; 153 154 EXTERN struct 155 { 156 char cbuf[MAXIO]; /* output buffer */ 157 } buf; 158 159 EXTERN int cbc; 160 EXTERN char* cbp; 161 EXTERN char* cbpmax; 162 163 #define cput(c)\ 164 { *cbp++ = c;\ 165 if(--cbc <= 0)\ 166 cflush(); } 167 168 void Lflag(char *arg); 169 int Yconv(Fmt *fp); 170 int Zconv(Fmt *fp); 171 void addexport(void); 172 void address(void); 173 Section*addsection(Segment *seg, char *name, int rwx); 174 void addstrdata(char *name, char *value); 175 vlong addstring(LSym *s, char *str); 176 void asmelfsym(void); 177 void asmplan9sym(void); 178 uint16 be16(uchar *b); 179 uint32 be32(uchar *b); 180 uint64 be64(uchar *b); 181 void callgraph(void); 182 void cflush(void); 183 void codeblk(int32 addr, int32 size); 184 vlong cpos(void); 185 void cseek(vlong p); 186 void cwrite(void *buf, int n); 187 void datblk(int32 addr, int32 size); 188 int datcmp(LSym *s1, LSym *s2); 189 vlong datoff(vlong addr); 190 void deadcode(void); 191 LSym* decodetype_arrayelem(LSym *s); 192 vlong decodetype_arraylen(LSym *s); 193 LSym* decodetype_chanelem(LSym *s); 194 int decodetype_funcdotdotdot(LSym *s); 195 int decodetype_funcincount(LSym *s); 196 LSym* decodetype_funcintype(LSym *s, int i); 197 int decodetype_funcoutcount(LSym *s); 198 LSym* decodetype_funcouttype(LSym *s, int i); 199 LSym* decodetype_gc(LSym *s); 200 vlong decodetype_ifacemethodcount(LSym *s); 201 uint8 decodetype_kind(LSym *s); 202 LSym* decodetype_mapkey(LSym *s); 203 LSym* decodetype_mapvalue(LSym *s); 204 LSym* decodetype_ptrelem(LSym *s); 205 vlong decodetype_size(LSym *s); 206 int decodetype_structfieldcount(LSym *s); 207 char* decodetype_structfieldname(LSym *s, int i); 208 vlong decodetype_structfieldoffs(LSym *s, int i); 209 LSym* decodetype_structfieldtype(LSym *s, int i); 210 void dodata(void); 211 void dostkcheck(void); 212 void dostkoff(void); 213 void dosymtype(void); 214 void doversion(void); 215 void doweak(void); 216 void dynreloc(void); 217 void dynrelocsym(LSym *s); 218 vlong entryvalue(void); 219 void errorexit(void); 220 void follow(void); 221 void genasmsym(void (*put)(LSym*, char*, int, vlong, vlong, int, LSym*)); 222 void growdatsize(vlong *datsizep, LSym *s); 223 char* headstr(int v); 224 int headtype(char *name); 225 void hostlink(void); 226 void hostobjs(void); 227 int iconv(Fmt *fp); 228 void importcycles(void); 229 void linkarchinit(void); 230 void ldelf(Biobuf *f, char *pkg, int64 len, char *pn); 231 void ldhostobj(void (*ld)(Biobuf*, char*, int64, char*), Biobuf *f, char *pkg, int64 len, char *pn, char *file); 232 void ldmacho(Biobuf *f, char *pkg, int64 len, char *pn); 233 void ldobj(Biobuf *f, char *pkg, int64 len, char *pn, char *file, int whence); 234 void ldpe(Biobuf *f, char *pkg, int64 len, char *pn); 235 void ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence); 236 uint16 le16(uchar *b); 237 uint32 le32(uchar *b); 238 uint64 le64(uchar *b); 239 void libinit(void); 240 LSym* listsort(LSym *l, int (*cmp)(LSym*, LSym*), int off); 241 void loadinternal(char *name); 242 void loadlib(void); 243 void lputb(int32 l); 244 void lputl(int32 l); 245 void* mal(uint32 n); 246 void mark(LSym *s); 247 void mywhatsys(void); 248 struct ar_hdr; 249 void objfile(char *file, char *pkg); 250 void patch(void); 251 int pathchar(void); 252 void pcln(void); 253 void pclntab(void); 254 void putelfsectionsym(LSym* s, int shndx); 255 void putelfsymshndx(vlong sympos, int shndx); 256 void putsymb(LSym *s, char *name, int t, vlong v, vlong size, int ver, LSym *typ); 257 int rbyoff(const void *va, const void *vb); 258 void reloc(void); 259 void relocsym(LSym *s); 260 void setheadtype(char *s); 261 void setinterp(char *s); 262 void setlinkmode(char *arg); 263 void span(void); 264 void strnput(char *s, int n); 265 vlong symaddr(LSym *s); 266 void symtab(void); 267 void textaddress(void); 268 void undef(void); 269 void unmal(void *v, uint32 n); 270 void usage(void); 271 void vputb(uint64 v); 272 int valuecmp(LSym *a, LSym *b); 273 void vputl(uint64 v); 274 void wputb(ushort w); 275 void wputl(ushort w); 276 void xdefine(char *p, int t, vlong v); 277 void zerosig(char *sp); 278 void archinit(void); 279 void diag(char *fmt, ...); 280 281 #pragma varargck argpos diag 1