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