github.com/ccccaoqing/test@v0.0.0-20220510085219-3985d23445c0/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 growdatsize(vlong *datsizep, LSym *s); 231 char* headstr(int v); 232 int headtype(char *name); 233 void hostlink(void); 234 void hostobjs(void); 235 int iconv(Fmt *fp); 236 void importcycles(void); 237 void linkarchinit(void); 238 void ldelf(Biobuf *f, char *pkg, int64 len, char *pn); 239 void ldhostobj(void (*ld)(Biobuf*, char*, int64, char*), Biobuf *f, char *pkg, int64 len, char *pn, char *file); 240 void ldmacho(Biobuf *f, char *pkg, int64 len, char *pn); 241 void ldobj(Biobuf *f, char *pkg, int64 len, char *pn, char *file, int whence); 242 void ldpe(Biobuf *f, char *pkg, int64 len, char *pn); 243 void ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence); 244 uint16 le16(uchar *b); 245 uint32 le32(uchar *b); 246 uint64 le64(uchar *b); 247 void libinit(void); 248 LSym* listsort(LSym *l, int (*cmp)(LSym*, LSym*), int off); 249 void loadinternal(char *name); 250 void loadlib(void); 251 void lputb(int32 l); 252 void lputl(int32 l); 253 void* mal(uint32 n); 254 void mark(LSym *s); 255 void mywhatsys(void); 256 struct ar_hdr; 257 void objfile(char *file, char *pkg); 258 void patch(void); 259 int pathchar(void); 260 void pcln(void); 261 void pclntab(void); 262 void putelfsectionsym(LSym* s, int shndx); 263 void putelfsymshndx(vlong sympos, int shndx); 264 void putsymb(LSym *s, char *name, int t, vlong v, vlong size, int ver, LSym *typ); 265 int rbyoff(const void *va, const void *vb); 266 void reloc(void); 267 void relocsym(LSym *s); 268 void setheadtype(char *s); 269 void setinterp(char *s); 270 void setlinkmode(char *arg); 271 void span(void); 272 void strnput(char *s, int n); 273 vlong symaddr(LSym *s); 274 void symtab(void); 275 void textaddress(void); 276 void undef(void); 277 void unmal(void *v, uint32 n); 278 void usage(void); 279 void vputb(uint64 v); 280 int valuecmp(LSym *a, LSym *b); 281 void vputl(uint64 v); 282 void wputb(ushort w); 283 void wputl(ushort w); 284 void xdefine(char *p, int t, vlong v); 285 void zerosig(char *sp); 286 void archinit(void); 287 void diag(char *fmt, ...); 288 289 #pragma varargck argpos diag 1