github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/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 enum 32 { 33 Sxxx, 34 35 /* order here is order in output file */ 36 /* readonly, executable */ 37 STEXT, 38 SELFRXSECT, 39 40 /* readonly, non-executable */ 41 STYPE, 42 SSTRING, 43 SGOSTRING, 44 SGOFUNC, 45 SRODATA, 46 SFUNCTAB, 47 STYPELINK, 48 SSYMTAB, // TODO: move to unmapped section 49 SPCLNTAB, 50 SELFROSECT, 51 52 /* writable, non-executable */ 53 SMACHOPLT, 54 SELFSECT, 55 SMACHO, /* Mach-O __nl_symbol_ptr */ 56 SMACHOGOT, 57 SNOPTRDATA, 58 SINITARR, 59 SDATA, 60 SWINDOWS, 61 SBSS, 62 SNOPTRBSS, 63 STLSBSS, 64 65 /* not mapped */ 66 SXREF, 67 SMACHOSYMSTR, 68 SMACHOSYMTAB, 69 SMACHOINDIRECTPLT, 70 SMACHOINDIRECTGOT, 71 SFILE, 72 SFILEPATH, 73 SCONST, 74 SDYNIMPORT, 75 SHOSTOBJ, 76 77 SSUB = 1<<8, /* sub-symbol, linked from parent via ->sub list */ 78 SMASK = SSUB - 1, 79 SHIDDEN = 1<<9, // hidden or local symbol 80 81 NHASH = 100003, 82 }; 83 84 typedef struct Library Library; 85 struct Library 86 { 87 char *objref; // object where we found the reference 88 char *srcref; // src file where we found the reference 89 char *file; // object file 90 char *pkg; // import path 91 }; 92 93 // Terrible but standard terminology. 94 // A segment describes a block of file to load into memory. 95 // A section further describes the pieces of that block for 96 // use in debuggers and such. 97 98 typedef struct Segment Segment; 99 typedef struct Section Section; 100 101 struct Segment 102 { 103 uchar rwx; // permission as usual unix bits (5 = r-x etc) 104 uvlong vaddr; // virtual address 105 uvlong len; // length in memory 106 uvlong fileoff; // file offset 107 uvlong filelen; // length on disk 108 Section* sect; 109 }; 110 111 #pragma incomplete struct Elf64_Shdr 112 113 struct Section 114 { 115 uchar rwx; 116 int16 extnum; 117 int32 align; 118 char *name; 119 uvlong vaddr; 120 uvlong len; 121 Section *next; // in segment list 122 Segment *seg; 123 struct Elf64_Shdr *elfsect; 124 uvlong reloff; 125 uvlong rellen; 126 }; 127 128 typedef struct Hist Hist; 129 130 #pragma incomplete struct Hist 131 132 extern char symname[]; 133 extern char **libdir; 134 extern int nlibdir; 135 extern int version; 136 137 EXTERN char* INITENTRY; 138 EXTERN char* thestring; 139 EXTERN Library* library; 140 EXTERN int libraryp; 141 EXTERN int nlibrary; 142 EXTERN Sym* hash[NHASH]; 143 EXTERN Sym* allsym; 144 EXTERN Sym* histfrog[MAXHIST]; 145 EXTERN uchar fnuxi8[8]; 146 EXTERN uchar fnuxi4[4]; 147 EXTERN int histfrogp; 148 EXTERN int histgen; 149 EXTERN uchar inuxi1[1]; 150 EXTERN uchar inuxi2[2]; 151 EXTERN uchar inuxi4[4]; 152 EXTERN uchar inuxi8[8]; 153 EXTERN char* outfile; 154 EXTERN int32 nsymbol; 155 EXTERN char* thestring; 156 EXTERN int ndynexp; 157 EXTERN Sym** dynexp; 158 EXTERN int nldflag; 159 EXTERN char** ldflag; 160 EXTERN int havedynamic; 161 EXTERN int iscgo; 162 EXTERN int elfglobalsymndx; 163 EXTERN int flag_race; 164 EXTERN int flag_shared; 165 EXTERN char* tracksym; 166 EXTERN char* interpreter; 167 EXTERN char* tmpdir; 168 EXTERN char* extld; 169 EXTERN char* extldflags; 170 EXTERN int debug_s; // backup old value of debug['s'] 171 172 enum 173 { 174 LinkAuto = 0, 175 LinkInternal, 176 LinkExternal, 177 }; 178 EXTERN int linkmode; 179 180 // for dynexport field of Sym 181 enum 182 { 183 CgoExportDynamic = 1<<0, 184 CgoExportStatic = 1<<1, 185 }; 186 187 EXTERN Segment segtext; 188 EXTERN Segment segrodata; 189 EXTERN Segment segdata; 190 EXTERN Segment segdwarf; 191 192 void setlinkmode(char*); 193 void addlib(char *src, char *obj); 194 void addlibpath(char *srcref, char *objref, char *file, char *pkg); 195 Section* addsection(Segment*, char*, int); 196 void copyhistfrog(char *buf, int nbuf); 197 void addhist(int32 line, int type); 198 void savehist(int32 line, int32 off); 199 Hist* gethist(void); 200 void getline(Hist*, int32 line, int32 *f, int32 *l); 201 void asmlc(void); 202 void histtoauto(void); 203 void collapsefrog(Sym *s); 204 Sym* newsym(char *symb, int v); 205 Sym* lookup(char *symb, int v); 206 Sym* rlookup(char *symb, int v); 207 void nuxiinit(void); 208 int find1(int32 l, int c); 209 int find2(int32 l, int c); 210 int32 ieeedtof(Ieee *e); 211 double ieeedtod(Ieee *e); 212 void undefsym(Sym *s); 213 void zerosig(char *sp); 214 void readundefs(char *f, int t); 215 void loadlib(void); 216 void errorexit(void); 217 void mangle(char*); 218 void objfile(char *file, char *pkg); 219 void libinit(void); 220 void pclntab(void); 221 void symtab(void); 222 void Lflag(char *arg); 223 void usage(void); 224 void adddynrel(Sym*, Reloc*); 225 void adddynrela(Sym*, Sym*, Reloc*); 226 void ldobj1(Biobuf *f, char*, int64 len, char *pn); 227 void ldobj(Biobuf*, char*, int64, char*, char*, int); 228 void ldelf(Biobuf*, char*, int64, char*); 229 void ldmacho(Biobuf*, char*, int64, char*); 230 void ldpe(Biobuf*, char*, int64, char*); 231 void ldpkg(Biobuf*, char*, int64, char*, int); 232 void mark(Sym *s); 233 void mkfwd(void); 234 char* expandpkg(char*, char*); 235 void deadcode(void); 236 Reloc* addrel(Sym*); 237 void codeblk(int32, int32); 238 void datblk(int32, int32); 239 void reloc(void); 240 void relocsym(Sym*); 241 void savedata(Sym*, Prog*, char*); 242 void symgrow(Sym*, int32); 243 void addstrdata(char*, char*); 244 vlong addstring(Sym*, char*); 245 vlong adduint8(Sym*, uint8); 246 vlong adduint16(Sym*, uint16); 247 vlong adduint32(Sym*, uint32); 248 vlong adduint64(Sym*, uint64); 249 vlong adduintxx(Sym*, uint64, int); 250 vlong addaddr(Sym*, Sym*); 251 vlong addaddrplus(Sym*, Sym*, vlong); 252 vlong addpcrelplus(Sym*, Sym*, vlong); 253 vlong addsize(Sym*, Sym*); 254 vlong setaddrplus(Sym*, vlong, Sym*, vlong); 255 vlong setaddr(Sym*, vlong, Sym*); 256 vlong setuint8(Sym*, vlong, uint8); 257 vlong setuint16(Sym*, vlong, uint16); 258 vlong setuint32(Sym*, vlong, uint32); 259 vlong setuint64(Sym*, vlong, uint64); 260 vlong setuintxx(Sym*, vlong, uint64, vlong); 261 void asmsym(void); 262 void asmelfsym(void); 263 void asmplan9sym(void); 264 void putelfsectionsym(Sym*, int); 265 void putelfsymshndx(vlong, int); 266 void strnput(char*, int); 267 void dodata(void); 268 void dosymtype(void); 269 void address(void); 270 void textaddress(void); 271 void genasmsym(void (*put)(Sym*, char*, int, vlong, vlong, int, Sym*)); 272 vlong datoff(vlong); 273 void adddynlib(char*); 274 int archreloc(Reloc*, Sym*, vlong*); 275 void adddynsym(Sym*); 276 void addexport(void); 277 void dostkcheck(void); 278 void undef(void); 279 void doweak(void); 280 void setpersrc(Sym*); 281 void doversion(void); 282 void usage(void); 283 void setinterp(char*); 284 Sym* listsort(Sym*, int(*cmp)(Sym*, Sym*), int); 285 int valuecmp(Sym*, Sym*); 286 void hostobjs(void); 287 void hostlink(void); 288 char* estrdup(char*); 289 void* erealloc(void*, long); 290 Sym* defgostring(char*); 291 292 int pathchar(void); 293 void* mal(uint32); 294 void unmal(void*, uint32); 295 void mywhatsys(void); 296 int rbyoff(const void*, const void*); 297 298 uint16 le16(uchar*); 299 uint32 le32(uchar*); 300 uint64 le64(uchar*); 301 uint16 be16(uchar*); 302 uint32 be32(uchar*); 303 uint64 be64(uchar*); 304 305 typedef struct Endian Endian; 306 struct Endian 307 { 308 uint16 (*e16)(uchar*); 309 uint32 (*e32)(uchar*); 310 uint64 (*e64)(uchar*); 311 }; 312 313 extern Endian be, le; 314 315 /* set by call to mywhatsys() */ 316 extern char* goroot; 317 extern char* goarch; 318 extern char* goos; 319 320 /* whence for ldpkg */ 321 enum { 322 FileObj = 0, 323 ArchiveObj, 324 Pkgdef 325 }; 326 327 /* executable header types */ 328 enum { 329 Hgarbunix = 0, // garbage unix 330 Hnoheader, // no header 331 Hunixcoff, // unix coff 332 Hrisc, // aif for risc os 333 Hplan9x32, // plan 9 32-bit format 334 Hplan9x64, // plan 9 64-bit format 335 Hmsdoscom, // MS-DOS .COM 336 Hnetbsd, // NetBSD 337 Hmsdosexe, // fake MS-DOS .EXE 338 Hixp1200, // IXP1200 (raw) 339 Helf, // ELF32 340 Hipaq, // ipaq 341 Hdarwin, // Apple Mach-O 342 Hlinux, // Linux ELF 343 Hfreebsd, // FreeBSD ELF 344 Hwindows, // MS Windows PE 345 Hopenbsd, // OpenBSD ELF 346 Hdragonfly, // DragonFly ELF 347 }; 348 349 typedef struct Header Header; 350 struct Header { 351 char *name; 352 int val; 353 }; 354 355 EXTERN char* headstring; 356 extern Header headers[]; 357 358 int headtype(char*); 359 char* headstr(int); 360 void setheadtype(char*); 361 362 int Yconv(Fmt*); 363 364 #pragma varargck type "O" int 365 #pragma varargck type "Y" Sym* 366 367 // buffered output 368 369 EXTERN Biobuf bso; 370 371 EXTERN struct 372 { 373 char cbuf[MAXIO]; /* output buffer */ 374 } buf; 375 376 EXTERN int cbc; 377 EXTERN char* cbp; 378 EXTERN char* cbpmax; 379 380 #define cput(c)\ 381 { *cbp++ = c;\ 382 if(--cbc <= 0)\ 383 cflush(); } 384 385 void cflush(void); 386 vlong cpos(void); 387 void cseek(vlong); 388 void cwrite(void*, int); 389 void importcycles(void); 390 int Zconv(Fmt*); 391 392 uint8 decodetype_kind(Sym*); 393 vlong decodetype_size(Sym*); 394 Sym* decodetype_gc(Sym*); 395 Sym* decodetype_arrayelem(Sym*); 396 vlong decodetype_arraylen(Sym*); 397 Sym* decodetype_ptrelem(Sym*); 398 Sym* decodetype_mapkey(Sym*); 399 Sym* decodetype_mapvalue(Sym*); 400 Sym* decodetype_chanelem(Sym*); 401 int decodetype_funcdotdotdot(Sym*); 402 int decodetype_funcincount(Sym*); 403 int decodetype_funcoutcount(Sym*); 404 Sym* decodetype_funcintype(Sym*, int); 405 Sym* decodetype_funcouttype(Sym*, int); 406 int decodetype_structfieldcount(Sym*); 407 char* decodetype_structfieldname(Sym*, int); 408 Sym* decodetype_structfieldtype(Sym*, int); 409 vlong decodetype_structfieldoffs(Sym*, int); 410 vlong decodetype_ifacemethodcount(Sym*);