1 // Derived from Inferno utils/6l/l.h and related files.
2 // http://code.google.com/p/inferno-os/source/browse/utils/6l/l.h
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.
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:
20 // The above copyright notice and this permission notice shall be included in
21 // all copies or substantial portions of the Software.
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
31 typedef struct Addr Addr;
32 typedef struct Prog Prog;
33 typedef struct LSym LSym;
34 typedef struct Reloc Reloc;
35 typedef struct Auto Auto;
36 typedef struct Hist Hist;
37 typedef struct Link Link;
38 typedef struct Plist Plist;
39 typedef struct LinkArch LinkArch;
40 typedef struct Library Library;
42 typedef struct Pcln Pcln;
43 typedef struct Pcdata Pcdata;
44 typedef struct Pciter Pciter;
46 // prevent incompatible type signatures between liblink and 8l on Plan 9
47 #pragma incomplete struct Node
57 Prog* branch; // for 5g, 6g, 8g, 9g
65 int8 reg; // for 5l, 9l; GPRs and FPRs both start at 0
66 int8 name; // for 5l, 9l
67 int8 class; // for 5l, 9l
68 uint8 etype; // for 5g, 6g, 8g
69 int32 offset2; // for 5l, 8l
70 struct Node* node; // for 5g, 6g, 8g
71 int64 width; // for 5g, 6g, 8g
80 int32 variant; // RV_*: variant on computed value
93 uchar scond; // arm only; condition codes
97 uchar reg; // arm, ppc64 only (e.g., ADD from, reg, to);
98 // starts at 0 for both GPRs and FPRs;
99 // also used for ADATA width on arm, ppc64
100 Addr from3; // ppc64 only (e.g., RLWM/FMADD from, reg, from3, to)
103 // for 5g, 6g, 8g internal use
106 // for 5l, 6l, 8l internal use
109 Prog* comefrom; // 6l, 8l
113 uint16 optab; // 5l, 9l
114 uchar back; // 6l, 8l
115 uchar ft; /* 6l, 8l oclass cache */
117 uchar isize; // 6l, 8l
120 char width; /* fake for DATA */
121 char mode; /* 16, 32, or 64 in 6l, 8l; internal use in 5g, 6g, 8g */
123 /*c2go uchar TEXTFLAG; */
126 // prevent incompatible type signatures between liblink and 8l on Plan 9
127 #pragma incomplete struct Section
132 char* extname; // name used in external object files
144 uchar leaf; // arm only
145 uchar fnptr; // arm only
146 uchar localentry; // ppc64: instrs between global & local entry
148 uchar onlist; // on the textp or datap lists
150 int16 symid; // for writing .5/.6/.8 files
155 int32 align; // if non-zero, required alignment in bytes
157 int32 args; // size of stack frame incoming arguments area
158 int32 locals; // size of stack frame locals area (arm only?)
161 LSym* hash; // in hash table
162 LSym* allsym; // in all symbol list
163 LSym* next; // in text or data list
164 LSym* sub; // in SSUB list
165 LSym* outer; // container of sub
172 struct Section* sect;
194 /* order here is order in output file */
195 /* readonly, executable */
199 /* readonly, non-executable */
207 SSYMTAB, // TODO: move to unmapped section
211 /* writable, non-executable */
214 SMACHO, /* Mach-O __nl_symbol_ptr */
217 SELFGOT, /* also .toc in ppc64 ABI */
237 SSUB = 1<<8, /* sub-symbol, linked from parent via ->sub list */
239 SHIDDEN = 1<<9, // hidden or local symbol
246 R_ADDRPOWER, // relocation for loading 31-bit address using addis and addi/ld/st for Power
248 R_CALL, // relocation for direct PC-relative call
249 R_CALLARM, // relocation for ARM direct call
250 R_CALLIND, // marker for indirect call (no actual relocating necessary)
251 R_CALLPOWER, // relocation for Power direct call
255 R_TLS_LE, // TLS local exec offset from TLS segment register
256 R_TLS_IE, // TLS initial exec offset from TLS base pointer
262 R_POWER_TOC, // ELF R_PPC64_TOC16*
268 RV_NONE, // identity variant
269 RV_POWER_LO, // x & 0xFFFF
270 RV_POWER_HI, // x >> 16
271 RV_POWER_HA, // (x + 0x8000) >> 16
272 RV_POWER_DS, // x & 0xFFFC, check x&0x3 == 0
274 RV_CHECK_OVERFLOW = 1<<8, // check overflow flag
275 RV_TYPE_MASK = (RV_CHECK_OVERFLOW - 1),
318 char *objref; // object where we found the reference
319 char *srcref; // src file where we found the reference
320 char *file; // object file
321 char *pkg; // import path
351 // for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
364 void pciterinit(Link*, Pciter*, Pcdata*);
365 void pciternext(Pciter*);
367 // symbol version, incremented each time a file is loaded.
368 // version==1 is reserved for savehist.
374 // Link holds the context for writing object code from a compiler
375 // to be linker input or for reading that input into the linker.
378 int32 thechar; // '5' (arm), '6' (amd64), etc.
379 char* thestring; // full name of architecture ("arm", "amd64", ..)
380 int32 goarm; // for arm only, GOARM setting
384 int32 (*ignore)(char*); // do not emit names satisfying this function
385 int32 debugasm; // -S flag in compiler
386 int32 debugline; // -L flag in compiler
387 int32 debughist; // -O flag in linker
388 int32 debugread; // -W flag in linker
389 int32 debugvlog; // -v flag in linker
390 int32 debugstack; // -K flag in linker
391 int32 debugzerostack; // -Z flag in linker
392 int32 debugdivmod; // -M flag in 5l
393 int32 debugfloat; // -F flag in 5l
394 int32 debugpcln; // -O flag in linker
395 int32 flag_shared; // -shared flag in linker
397 Biobuf* bso; // for -v flag
403 int32 enforce_data_order; // for use by assembler
405 // hash table of all symbols
406 LSym* hash[LINKHASH];
423 LSym* symmorestack[2];
432 int repn; // for nacl
433 int lock; // for nacl
441 // for reading input files (during linker)
450 void (*diag)(char*, ...);
464 LittleEndian = 0x04030201,
465 BigEndian = 0x01020304,
468 // LinkArch is the definition of a single architecture.
471 char* name; // "arm", "amd64", and so on
472 int thechar; // '5', '6', and so on
473 int32 endian; // LittleEndian or BigEndian
475 void (*addstacksplit)(Link*, LSym*);
476 void (*assemble)(Link*, LSym*);
477 int (*datasize)(Prog*);
478 void (*follow)(Link*, LSym*);
479 int (*iscall)(Prog*);
480 int (*isdata)(Prog*);
482 void (*progedit)(Link*, Prog*);
483 void (*settextflag)(Prog*, int);
484 int (*symtype)(Addr*);
485 int (*textflag)(Prog*);
491 // TODO: Give these the same values on all systems.
518 /* executable header types */
541 extern uchar fnuxi8[8];
542 extern uchar fnuxi4[4];
543 extern uchar inuxi1[1];
544 extern uchar inuxi2[2];
545 extern uchar inuxi4[4];
546 extern uchar inuxi8[8];
549 void span5(Link *ctxt, LSym *s);
550 int chipfloat5(Link *ctxt, float64 e);
551 int chipzero5(Link *ctxt, float64 e);
554 void span6(Link *ctxt, LSym *s);
557 void span8(Link *ctxt, LSym *s);
560 void span9(Link *ctxt, LSym *s);
563 vlong addaddr(Link *ctxt, LSym *s, LSym *t);
564 vlong addaddrplus(Link *ctxt, LSym *s, LSym *t, vlong add);
565 vlong addaddrplus4(Link *ctxt, LSym *s, LSym *t, vlong add);
566 vlong addpcrelplus(Link *ctxt, LSym *s, LSym *t, vlong add);
567 Reloc* addrel(LSym *s);
568 vlong addsize(Link *ctxt, LSym *s, LSym *t);
569 vlong adduint16(Link *ctxt, LSym *s, uint16 v);
570 vlong adduint32(Link *ctxt, LSym *s, uint32 v);
571 vlong adduint64(Link *ctxt, LSym *s, uint64 v);
572 vlong adduint8(Link *ctxt, LSym *s, uint8 v);
573 vlong adduintxx(Link *ctxt, LSym *s, uint64 v, int wid);
574 void mangle(char *file);
575 void savedata(Link *ctxt, LSym *s, Prog *p, char *pn);
576 void savedata1(Link *ctxt, LSym *s, Prog *p, char *pn, int enforce_order);
577 vlong setaddr(Link *ctxt, LSym *s, vlong off, LSym *t);
578 vlong setaddrplus(Link *ctxt, LSym *s, vlong off, LSym *t, vlong add);
579 vlong setuint16(Link *ctxt, LSym *s, vlong r, uint16 v);
580 vlong setuint32(Link *ctxt, LSym *s, vlong r, uint32 v);
581 vlong setuint64(Link *ctxt, LSym *s, vlong r, uint64 v);
582 vlong setuint8(Link *ctxt, LSym *s, vlong r, uint8 v);
583 vlong setuintxx(Link *ctxt, LSym *s, vlong off, uint64 v, vlong wid);
584 void symgrow(Link *ctxt, LSym *s, vlong siz);
587 void double2ieee(uint64 *ieee, double native);
588 void* emallocz(long n);
589 void* erealloc(void *p, long n);
590 char* estrdup(char *p);
591 char* expandpkg(char *t0, char *pkg);
594 void addhist(Link *ctxt, int32 line, int type);
595 void addlib(Link *ctxt, char *src, char *obj, char *path);
596 void addlibpath(Link *ctxt, char *srcref, char *objref, char *file, char *pkg);
597 void collapsefrog(Link *ctxt, LSym *s);
598 void copyhistfrog(Link *ctxt, char *buf, int nbuf);
599 int find1(int32 l, int c);
600 void linkgetline(Link *ctxt, int32 line, LSym **f, int32 *l);
601 void histtoauto(Link *ctxt);
603 void nuxiinit(LinkArch*);
604 void savehist(Link *ctxt, int32 line, int32 off);
605 Prog* copyp(Link*, Prog*);
606 Prog* appendp(Link*, Prog*);
607 vlong atolwhex(char*);
610 void listinit5(void);
611 void listinit6(void);
612 void listinit8(void);
613 void listinit9(void);
616 int linklinefmt(Link *ctxt, Fmt *fp);
617 void linklinehist(Link *ctxt, int lineno, char *f, int offset);
618 Plist* linknewplist(Link *ctxt);
619 void linkprfile(Link *ctxt, int32 l);
622 void ldobjfile(Link *ctxt, Biobuf *b, char *pkg, int64 len, char *path);
623 void writeobj(Link *ctxt, Biobuf *b);
626 Prog* brchain(Link *ctxt, Prog *p);
627 Prog* brloop(Link *ctxt, Prog *p);
628 void linkpatch(Link *ctxt, LSym *sym);
631 void linkpcln(Link*, LSym*);
634 LSym* linklookup(Link *ctxt, char *name, int v);
635 Link* linknew(LinkArch*);
636 LSym* linknewsym(Link *ctxt, char *symb, int v);
637 LSym* linkrlookup(Link *ctxt, char *name, int v);
638 int linksymfmt(Fmt *f);
642 extern char* anames5[];
643 extern char* anames6[];
644 extern char* anames8[];
645 extern char* anames9[];
647 extern char* cnames5[];
648 extern char* cnames9[];
650 extern char* dnames5[];
651 extern char* dnames6[];
652 extern char* dnames8[];
653 extern char* dnames9[];
655 extern LinkArch link386;
656 extern LinkArch linkamd64;
657 extern LinkArch linkamd64p32;
658 extern LinkArch linkarm;
659 extern LinkArch linkppc64;
660 extern LinkArch linkppc64le;
662 #pragma varargck type "A" int
663 #pragma varargck type "E" uint
664 #pragma varargck type "D" Addr*
665 #pragma varargck type "lD" Addr*
666 #pragma varargck type "P" Prog*
667 #pragma varargck type "R" int
668 #pragma varargck type "^" int // for 5l/9l, C_* classes (liblink internal)
670 // TODO(ality): remove this workaround.
671 // It's here because Pconv in liblink/list?.c references %L.
672 #pragma varargck type "L" int32