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
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
92 uchar scond; // arm only
96 uchar reg; // arm, power64 only (e.g., ADD from, reg, to);
97 // also used for ADATA width on arm, power64
98 Addr from3; // power64 only (e.g., RLWM/FMADD from, reg, from3, to)
101 // for 5g, 6g, 8g internal use
104 // for 5l, 6l, 8l internal use
107 Prog* comefrom; // 6l, 8l
111 uint16 optab; // 5l, 9l
112 uchar back; // 6l, 8l
113 uchar ft; /* 6l, 8l oclass cache */
115 uchar isize; // 6l, 8l
117 char width; /* fake for DATA */
118 char mode; /* 16, 32, or 64 in 6l, 8l; internal use in 5g, 6g, 8g */
120 /*c2go uchar TEXTFLAG; */
123 // prevent incompatible type signatures between liblink and 8l on Plan 9
124 #pragma incomplete struct Section
129 char* extname; // name used in external object files
141 uchar leaf; // arm only
142 uchar fnptr; // arm only
144 uchar onlist; // on the textp or datap lists
145 int16 symid; // for writing .5/.6/.8 files
150 int32 align; // if non-zero, required alignment in bytes
152 int32 args; // size of stack frame incoming arguments area
153 int32 locals; // size of stack frame locals area (arm only?)
156 LSym* hash; // in hash table
157 LSym* allsym; // in all symbol list
158 LSym* next; // in text or data list
159 LSym* sub; // in SSUB list
160 LSym* outer; // container of sub
167 struct Section* sect;
189 /* order here is order in output file */
190 /* readonly, executable */
194 /* readonly, non-executable */
202 SSYMTAB, // TODO: move to unmapped section
206 /* writable, non-executable */
209 SMACHO, /* Mach-O __nl_symbol_ptr */
231 SSUB = 1<<8, /* sub-symbol, linked from parent via ->sub list */
233 SHIDDEN = 1<<9, // hidden or local symbol
240 R_ADDRPOWER, // relocation for loading 31-bit address using addis and addi/ld/st for Power
242 R_CALL, // relocation for direct PC-relative call
243 R_CALLARM, // relocation for ARM direct call
244 R_CALLIND, // marker for indirect call (no actual relocating necessary)
245 R_CALLPOWER, // relocation for Power direct call
249 R_TLS_LE, // TLS local exec offset from TLS segment register
250 R_TLS_IE, // TLS initial exec offset from TLS base pointer
297 char *objref; // object where we found the reference
298 char *srcref; // src file where we found the reference
299 char *file; // object file
300 char *pkg; // import path
330 // for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
343 void pciterinit(Link*, Pciter*, Pcdata*);
344 void pciternext(Pciter*);
346 // symbol version, incremented each time a file is loaded.
347 // version==1 is reserved for savehist.
353 // Link holds the context for writing object code from a compiler
354 // to be linker input or for reading that input into the linker.
357 int32 thechar; // '5' (arm), '6' (amd64), etc.
358 char* thestring; // full name of architecture ("arm", "amd64", ..)
359 int32 goarm; // for arm only, GOARM setting
363 int32 (*ignore)(char*); // do not emit names satisfying this function
364 int32 debugasm; // -S flag in compiler
365 int32 debugline; // -L flag in compiler
366 int32 debughist; // -O flag in linker
367 int32 debugread; // -W flag in linker
368 int32 debugvlog; // -v flag in linker
369 int32 debugstack; // -K flag in linker
370 int32 debugzerostack; // -Z flag in linker
371 int32 debugdivmod; // -M flag in 5l
372 int32 debugfloat; // -F flag in 5l
373 int32 debugpcln; // -O flag in linker
374 int32 flag_shared; // -shared flag in linker
376 Biobuf* bso; // for -v flag
382 int32 enforce_data_order; // for use by assembler
384 // hash table of all symbols
385 LSym* hash[LINKHASH];
402 LSym* symmorestack[2];
411 int repn; // for nacl
412 int lock; // for nacl
420 // for reading input files (during linker)
429 void (*diag)(char*, ...);
443 LittleEndian = 0x04030201,
444 BigEndian = 0x01020304,
447 // LinkArch is the definition of a single architecture.
450 char* name; // "arm", "amd64", and so on
451 int thechar; // '5', '6', and so on
452 int32 endian; // LittleEndian or BigEndian
454 void (*addstacksplit)(Link*, LSym*);
455 void (*assemble)(Link*, LSym*);
456 int (*datasize)(Prog*);
457 void (*follow)(Link*, LSym*);
458 int (*iscall)(Prog*);
459 int (*isdata)(Prog*);
461 void (*progedit)(Link*, Prog*);
462 void (*settextflag)(Prog*, int);
463 int (*symtype)(Addr*);
464 int (*textflag)(Prog*);
470 // TODO: Give these the same values on all systems.
497 /* executable header types */
520 extern uchar fnuxi8[8];
521 extern uchar fnuxi4[4];
522 extern uchar inuxi1[1];
523 extern uchar inuxi2[2];
524 extern uchar inuxi4[4];
525 extern uchar inuxi8[8];
528 void span5(Link *ctxt, LSym *s);
529 int chipfloat5(Link *ctxt, float64 e);
530 int chipzero5(Link *ctxt, float64 e);
533 void span6(Link *ctxt, LSym *s);
536 void span8(Link *ctxt, LSym *s);
539 void span9(Link *ctxt, LSym *s);
542 vlong addaddr(Link *ctxt, LSym *s, LSym *t);
543 vlong addaddrplus(Link *ctxt, LSym *s, LSym *t, vlong add);
544 vlong addaddrplus4(Link *ctxt, LSym *s, LSym *t, vlong add);
545 vlong addpcrelplus(Link *ctxt, LSym *s, LSym *t, vlong add);
546 Reloc* addrel(LSym *s);
547 vlong addsize(Link *ctxt, LSym *s, LSym *t);
548 vlong adduint16(Link *ctxt, LSym *s, uint16 v);
549 vlong adduint32(Link *ctxt, LSym *s, uint32 v);
550 vlong adduint64(Link *ctxt, LSym *s, uint64 v);
551 vlong adduint8(Link *ctxt, LSym *s, uint8 v);
552 vlong adduintxx(Link *ctxt, LSym *s, uint64 v, int wid);
553 void mangle(char *file);
554 void savedata(Link *ctxt, LSym *s, Prog *p, char *pn);
555 void savedata1(Link *ctxt, LSym *s, Prog *p, char *pn, int enforce_order);
556 vlong setaddr(Link *ctxt, LSym *s, vlong off, LSym *t);
557 vlong setaddrplus(Link *ctxt, LSym *s, vlong off, LSym *t, vlong add);
558 vlong setuint16(Link *ctxt, LSym *s, vlong r, uint16 v);
559 vlong setuint32(Link *ctxt, LSym *s, vlong r, uint32 v);
560 vlong setuint64(Link *ctxt, LSym *s, vlong r, uint64 v);
561 vlong setuint8(Link *ctxt, LSym *s, vlong r, uint8 v);
562 vlong setuintxx(Link *ctxt, LSym *s, vlong off, uint64 v, vlong wid);
563 void symgrow(Link *ctxt, LSym *s, vlong siz);
566 void double2ieee(uint64 *ieee, double native);
567 void* emallocz(long n);
568 void* erealloc(void *p, long n);
569 char* estrdup(char *p);
570 char* expandpkg(char *t0, char *pkg);
573 void addhist(Link *ctxt, int32 line, int type);
574 void addlib(Link *ctxt, char *src, char *obj, char *path);
575 void addlibpath(Link *ctxt, char *srcref, char *objref, char *file, char *pkg);
576 void collapsefrog(Link *ctxt, LSym *s);
577 void copyhistfrog(Link *ctxt, char *buf, int nbuf);
578 int find1(int32 l, int c);
579 void linkgetline(Link *ctxt, int32 line, LSym **f, int32 *l);
580 void histtoauto(Link *ctxt);
582 void nuxiinit(LinkArch*);
583 void savehist(Link *ctxt, int32 line, int32 off);
584 Prog* copyp(Link*, Prog*);
585 Prog* appendp(Link*, Prog*);
586 vlong atolwhex(char*);
589 void listinit5(void);
590 void listinit6(void);
591 void listinit8(void);
592 void listinit9(void);
595 int linklinefmt(Link *ctxt, Fmt *fp);
596 void linklinehist(Link *ctxt, int lineno, char *f, int offset);
597 Plist* linknewplist(Link *ctxt);
598 void linkprfile(Link *ctxt, int32 l);
601 void ldobjfile(Link *ctxt, Biobuf *b, char *pkg, int64 len, char *path);
602 void writeobj(Link *ctxt, Biobuf *b);
605 Prog* brchain(Link *ctxt, Prog *p);
606 Prog* brloop(Link *ctxt, Prog *p);
607 void linkpatch(Link *ctxt, LSym *sym);
610 void linkpcln(Link*, LSym*);
613 LSym* linklookup(Link *ctxt, char *name, int v);
614 Link* linknew(LinkArch*);
615 LSym* linknewsym(Link *ctxt, char *symb, int v);
616 LSym* linkrlookup(Link *ctxt, char *name, int v);
617 int linksymfmt(Fmt *f);
621 extern char* anames5[];
622 extern char* anames6[];
623 extern char* anames8[];
624 extern char* anames9[];
626 extern char* cnames5[];
627 extern char* cnames9[];
629 extern LinkArch link386;
630 extern LinkArch linkamd64;
631 extern LinkArch linkamd64p32;
632 extern LinkArch linkarm;
633 extern LinkArch linkpower64;
634 extern LinkArch linkpower64le;
636 #pragma varargck type "A" int
637 #pragma varargck type "D" Addr*
638 #pragma varargck type "lD" Addr*
639 #pragma varargck type "P" Prog*
640 #pragma varargck type "R" int
641 #pragma varargck type "^" int // for 5l/9l, C_* classes (liblink internal)
643 // TODO(ality): remove this workaround.
644 // It's here because Pconv in liblink/list?.c references %L.
645 #pragma varargck type "L" int32