]> Cypherpunks.ru repositories - gostls13.git/blob - include/link.h
math/big: fix %b format so it matches strconf %b format for non-zero values
[gostls13.git] / include / link.h
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
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 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;
41
42 typedef struct  Pcln    Pcln;
43 typedef struct  Pcdata  Pcdata;
44 typedef struct  Pciter  Pciter;
45
46 // An Addr is an argument to an instruction.
47 // The general forms and their encodings are:
48 //
49 //      sym±offset(symkind)(reg)(index*scale)
50 //              Memory reference at address &sym(symkind) + offset + reg + index*scale.
51 //              Any of sym(symkind), ±offset, (reg), (index*scale), and *scale can be omitted.
52 //              If (reg) and *scale are both omitted, the resulting expression (index) is parsed as (reg).
53 //              To force a parsing as index*scale, write (index*1).
54 //              Encoding:
55 //                      type = TYPE_MEM
56 //                      name = symkind (NAME_AUTO, ...) or 0 (NAME_NONE)
57 //                      sym = sym
58 //                      offset = ±offset
59 //                      reg = reg (REG_*)
60 //                      index = index (REG_*)
61 //                      scale = scale (1, 2, 4, 8)
62 //
63 //      $<mem>
64 //              Effective address of memory reference <mem>, defined above.
65 //              Encoding: same as memory reference, but type = TYPE_ADDR.
66 //
67 //      $<±integer value>
68 //              This is a special case of $<mem>, in which only ±offset is present.
69 //              It has a separate type for easy recognition.
70 //              Encoding:
71 //                      type = TYPE_CONST
72 //                      offset = ±integer value
73 //
74 //      *<mem>
75 //              Indirect reference through memory reference <mem>, defined above.
76 //              Only used on x86 for CALL/JMP *sym(SB), which calls/jumps to a function
77 //              pointer stored in the data word sym(SB), not a function named sym(SB).
78 //              Encoding: same as above, but type = TYPE_INDIR.
79 //
80 //      $*$<mem>
81 //              No longer used.
82 //              On machines with actual SB registers, $*$<mem> forced the
83 //              instruction encoding to use a full 32-bit constant, never a
84 //              reference relative to SB.
85 //
86 //      $<floating point literal>
87 //              Floating point constant value.
88 //              Encoding:
89 //                      type = TYPE_FCONST
90 //                      u.dval = floating point value
91 //
92 //      $<string literal, up to 8 chars>
93 //              String literal value (raw bytes used for DATA instruction).
94 //              Encoding:
95 //                      type = TYPE_SCONST
96 //                      u.sval = string
97 //
98 //      <register name>
99 //              Any register: integer, floating point, control, segment, and so on.
100 //              If looking for specific register kind, must check type and reg value range.
101 //              Encoding:
102 //                      type = TYPE_REG
103 //                      reg = reg (REG_*)
104 //
105 //      x(PC)
106 //              Encoding:
107 //                      type = TYPE_BRANCH
108 //                      u.branch = Prog* reference OR ELSE offset = target pc (branch takes priority)
109 //
110 //      $±x-±y
111 //              Final argument to TEXT, specifying local frame size x and argument size y.
112 //              In this form, x and y are integer literals only, not arbitrary expressions.
113 //              This avoids parsing ambiguities due to the use of - as a separator.
114 //              The ± are optional.
115 //              If the final argument to TEXT omits the -±y, the encoding should still
116 //              use TYPE_TEXTSIZE (not TYPE_CONST), with u.argsize = ArgsSizeUnknown.
117 //              Encoding:
118 //                      type = TYPE_TEXTSIZE
119 //                      offset = x
120 //                      u.argsize = y
121 //
122 //      reg<<shift, reg>>shift, reg->shift, reg@>shift
123 //              Shifted register value, for ARM.
124 //              In this form, reg must be a register and shift can be a register or an integer constant.
125 //              Encoding:
126 //                      type = TYPE_SHIFT
127 //                      offset = (reg&15) | shifttype<<5 | count
128 //                      shifttype = 0, 1, 2, 3 for <<, >>, ->, @>
129 //                      count = (reg&15)<<8 | 1<<4 for a register shift count, (n&31)<<7 for an integer constant.
130 //
131 //      (reg, reg)
132 //              A destination register pair. When used as the last argument of an instruction,
133 //              this form makes clear that both registers are destinations.
134 //              Encoding:
135 //                      type = TYPE_REGREG
136 //                      reg = first register
137 //                      offset = second register
138 //
139 //      reg, reg
140 //              TYPE_REGREG2, to be removed.
141 //
142 struct  Addr
143 {
144         int16   type; // could be int8
145         int16   reg;
146         int16   index;
147         int8    scale;
148         int8    name;
149         int64   offset;
150         LSym*   sym;
151         
152         union
153         {
154                 char    sval[8];
155                 float64 dval;
156                 Prog*   branch;
157                 int32   argsize;        // for 5l, 8l
158                 uint64  bits; // raw union bits, for testing if anything has been written to any field
159         } u;
160
161         // gotype is the name of the Go type descriptor for sym.
162         // It cannot be set using assembly syntax.
163         // It is generated by the Go compiler for global declarations,
164         // to convey information about pointer locations to the back end
165         // and for use in generating debug information.
166         LSym*   gotype;
167
168         int8    class;  // for internal use by liblink
169         uint8   etype; // for internal use by 5g, 6g, 8g
170         void*   node; // for internal use by 5g, 6g, 8g
171         int64   width; // for internal use by 5g, 6g, 8g
172 };
173
174 enum {
175         NAME_NONE = 0,
176         NAME_EXTERN,
177         NAME_STATIC,
178         NAME_AUTO,
179         NAME_PARAM,
180 };
181
182 enum {
183         TYPE_NONE = 0,
184         TYPE_BRANCH = 5, // avoid accidental conflicts with NAME_* 
185         TYPE_TEXTSIZE,
186         TYPE_MEM,
187         TYPE_CONST,
188         TYPE_FCONST,
189         TYPE_SCONST,
190         TYPE_REG,
191         TYPE_ADDR,
192         TYPE_SHIFT,
193         TYPE_REGREG,
194         TYPE_REGREG2,
195         TYPE_INDIR,
196 };
197
198 struct  Reloc
199 {
200         int32   off;
201         uchar   siz;
202         uchar   done;
203         int32   type;
204         int32   variant; // RV_*: variant on computed value
205         int64   add;
206         int64   xadd;
207         LSym*   sym;
208         LSym*   xsym;
209 };
210
211 // TODO(rsc): Describe prog.
212 // TODO(rsc): Describe TEXT/GLOBL flag in from3, DATA width in from3.
213 struct  Prog
214 {
215         vlong   pc;
216         int32   lineno;
217         Prog*   link;
218         short   as;
219         uchar   scond; // arm only; condition codes
220
221         // operands
222         Addr    from;
223         int16   reg; // arm, ppc64 only (e.g., ADD from, reg, to);
224                      // starts at 0 for both GPRs and FPRs;
225                      // also used for ADATA width on arm, ppc64
226         Addr    from3; // addl source argument (e.g., RLWM/FMADD from, reg, from3, to)
227         Addr    to;
228         
229         // for 5g, 6g, 8g internal use
230         void*   opt;
231
232         // for liblink internal use
233         Prog*   forwd;
234         Prog*   pcond;
235         Prog*   comefrom;       // amd64, 386
236         Prog*   pcrel;  // arm
237         int32   spadj;
238         uint16  mark;
239         uint16  optab;  // arm, ppc64
240         uchar   back;   // amd64, 386
241         uchar   ft;     // oclass cache
242         uchar   tt;     // oclass cache
243         uchar   isize;  // amd64, 386
244
245         char    width;  /* fake for DATA */
246         char    mode;   /* 16, 32, or 64 in 6l, 8l; internal use in 5g, 6g, 8g */
247 };
248
249 extern Prog zprog; // zeroed Prog
250
251 // Prog.as opcodes.
252 // These are the portable opcodes, common to all architectures.
253 // Each architecture defines many more arch-specific opcodes,
254 // with values starting at A_ARCHSPECIFIC.
255 enum {
256         AXXX = 0,
257
258         ACALL,
259         ACHECKNIL,
260         ADATA,
261         ADUFFCOPY,
262         ADUFFZERO,
263         AEND,
264         AFUNCDATA,
265         AGLOBL,
266         AJMP,
267         ANOP,
268         APCDATA,
269         ARET,
270         ATEXT,
271         ATYPE,
272         AUNDEF,
273         AUSEFIELD,
274         AVARDEF,
275         AVARKILL,
276         
277         A_ARCHSPECIFIC, // first architecture-specific opcode value
278 };
279
280 // prevent incompatible type signatures between liblink and 8l on Plan 9
281 #pragma incomplete struct Section
282
283 struct  LSym
284 {
285         char*   name;
286         char*   extname;        // name used in external object files
287         short   type;
288         short   version;
289         uchar   dupok;
290         uchar   cfunc;
291         uchar   external;
292         uchar   nosplit;
293         uchar   reachable;
294         uchar   cgoexport;
295         uchar   special;
296         uchar   stkcheck;
297         uchar   hide;
298         uchar   leaf;   // arm only
299         uchar   fnptr;  // arm only
300         uchar   localentry;     // ppc64: instrs between global & local entry
301         uchar   seenglobl;
302         uchar   onlist; // on the textp or datap lists
303         int16   symid;  // for writing .5/.6/.8 files
304         int32   dynid;
305         int32   sig;
306         int32   plt;
307         int32   got;
308         int32   align;  // if non-zero, required alignment in bytes
309         int32   elfsym;
310         int32   args;   // size of stack frame incoming arguments area
311         int32   locals; // size of stack frame locals area (arm only?)
312         vlong   value;
313         vlong   size;
314         LSym*   hash;   // in hash table
315         LSym*   allsym; // in all symbol list
316         LSym*   next;   // in text or data list
317         LSym*   sub;    // in SSUB list
318         LSym*   outer;  // container of sub
319         LSym*   gotype;
320         LSym*   reachparent;
321         LSym*   queue;
322         char*   file;
323         char*   dynimplib;
324         char*   dynimpvers;
325         struct Section* sect;
326         
327         // STEXT
328         Auto*   autom;
329         Prog*   text;
330         Prog*   etext;
331         Pcln*   pcln;
332
333         // SDATA, SBSS
334         uchar*  p;
335         int     np;
336         int32   maxp;
337         Reloc*  r;
338         int32   nr;
339         int32   maxr;
340 };
341
342 // LSym.type
343 enum
344 {
345         Sxxx,
346
347         /* order here is order in output file */
348         /* readonly, executable */
349         STEXT,
350         SELFRXSECT,
351         
352         /* readonly, non-executable */
353         STYPE,
354         SSTRING,
355         SGOSTRING,
356         SGOFUNC,
357         SRODATA,
358         SFUNCTAB,
359         STYPELINK,
360         SSYMTAB, // TODO: move to unmapped section
361         SPCLNTAB,
362         SELFROSECT,
363         
364         /* writable, non-executable */
365         SMACHOPLT,
366         SELFSECT,
367         SMACHO, /* Mach-O __nl_symbol_ptr */
368         SMACHOGOT,
369         SWINDOWS,
370         SELFGOT,        /* also .toc in ppc64 ABI */
371         SNOPTRDATA,
372         SINITARR,
373         SDATA,
374         SBSS,
375         SNOPTRBSS,
376         STLSBSS,
377
378         /* not mapped */
379         SXREF,
380         SMACHOSYMSTR,
381         SMACHOSYMTAB,
382         SMACHOINDIRECTPLT,
383         SMACHOINDIRECTGOT,
384         SFILE,
385         SFILEPATH,
386         SCONST,
387         SDYNIMPORT,
388         SHOSTOBJ,
389
390         SSUB = 1<<8,    /* sub-symbol, linked from parent via ->sub list */
391         SMASK = SSUB - 1,
392         SHIDDEN = 1<<9, // hidden or local symbol
393 };
394
395 // Reloc.type
396 enum
397 {
398         R_ADDR = 1,
399         R_ADDRPOWER, // relocation for loading 31-bit address using addis and addi/ld/st for Power
400         R_SIZE,
401         R_CALL, // relocation for direct PC-relative call
402         R_CALLARM, // relocation for ARM direct call
403         R_CALLIND, // marker for indirect call (no actual relocating necessary)
404         R_CALLPOWER, // relocation for Power direct call
405         R_CONST,
406         R_PCREL,
407         R_TLS,
408         R_TLS_LE, // TLS local exec offset from TLS segment register
409         R_TLS_IE, // TLS initial exec offset from TLS base pointer
410         R_GOTOFF,
411         R_PLT0,
412         R_PLT1,
413         R_PLT2,
414         R_USEFIELD,
415         R_POWER_TOC,            // ELF R_PPC64_TOC16*
416 };
417
418 // Reloc.variant
419 enum
420 {
421         RV_NONE,                // identity variant
422         RV_POWER_LO,            // x & 0xFFFF
423         RV_POWER_HI,            // x >> 16
424         RV_POWER_HA,            // (x + 0x8000) >> 16
425         RV_POWER_DS,            // x & 0xFFFC, check x&0x3 == 0
426
427         RV_CHECK_OVERFLOW = 1<<8,       // check overflow flag
428         RV_TYPE_MASK = (RV_CHECK_OVERFLOW - 1),
429 };
430
431 // Auto.name
432 enum
433 {
434         A_AUTO = 1,
435         A_PARAM,
436 };
437
438 struct  Auto
439 {
440         LSym*   asym;
441         Auto*   link;
442         int32   aoffset;
443         int16   name;
444         LSym*   gotype;
445 };
446
447 enum
448 {
449         LINKHASH = 100003,
450 };
451
452 struct  Hist
453 {
454         Hist*   link;
455         char*   name;
456         int32   line;
457         int32   offset;
458 };
459
460 struct  Plist
461 {
462         LSym*   name;
463         Prog*   firstpc;
464         int     recur;
465         Plist*  link;
466 };
467
468 struct  Library
469 {
470         char *objref;   // object where we found the reference
471         char *srcref;   // src file where we found the reference
472         char *file;     // object file
473         char *pkg;      // import path
474 };
475
476 struct Pcdata
477 {
478         uchar *p;
479         int n;
480         int m;
481 };
482
483 struct Pcln
484 {
485         Pcdata pcsp;
486         Pcdata pcfile;
487         Pcdata pcline;
488         Pcdata *pcdata;
489         int npcdata;
490         LSym **funcdata;
491         int64 *funcdataoff;
492         int nfuncdata;
493         
494         LSym **file;
495         int nfile;
496         int mfile;
497
498         LSym *lastfile;
499         int lastindex;
500 };
501
502 // Pcdata iterator.
503 //      for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
504 struct Pciter
505 {
506         Pcdata d;
507         uchar *p;
508         uint32 pc;
509         uint32 nextpc;
510         uint32 pcscale;
511         int32 value;
512         int start;
513         int done;
514 };
515
516 void    pciterinit(Link*, Pciter*, Pcdata*);
517 void    pciternext(Pciter*);
518
519 // symbol version, incremented each time a file is loaded.
520 // version==1 is reserved for savehist.
521 enum
522 {
523         HistVersion = 1,
524 };
525
526 // Link holds the context for writing object code from a compiler
527 // to be linker input or for reading that input into the linker.
528 struct  Link
529 {
530         int32   thechar; // '5' (arm), '6' (amd64), etc.
531         char*   thestring; // full name of architecture ("arm", "amd64", ..)
532         int32   goarm; // for arm only, GOARM setting
533         int     headtype;
534
535         LinkArch*       arch;
536         int32   (*ignore)(char*);       // do not emit names satisfying this function
537         int32   debugasm;       // -S flag in compiler
538         int32   debugline;      // -L flag in compiler
539         int32   debughist;      // -O flag in linker
540         int32   debugread;      // -W flag in linker
541         int32   debugvlog;      // -v flag in linker
542         int32   debugstack;     // -K flag in linker
543         int32   debugzerostack; // -Z flag in linker
544         int32   debugdivmod;    // -M flag in 5l
545         int32   debugfloat;     // -F flag in 5l
546         int32   debugpcln;      // -O flag in linker
547         int32   flag_shared;    // -shared flag in linker
548         int32   iself;
549         Biobuf* bso;    // for -v flag
550         char*   pathname;
551         int32   windows;
552         char*   trimpath;
553         char*   goroot;
554         char*   goroot_final;
555         int32   enforce_data_order;     // for use by assembler
556
557         // hash table of all symbols
558         LSym*   hash[LINKHASH];
559         LSym*   allsym;
560         int32   nsymbol;
561
562         // file-line history
563         Hist*   hist;
564         Hist*   ehist;
565         
566         // all programs
567         Plist*  plist;
568         Plist*  plast;
569         
570         // code generation
571         LSym*   sym_div;
572         LSym*   sym_divu;
573         LSym*   sym_mod;
574         LSym*   sym_modu;
575         LSym*   symmorestack[2];
576         LSym*   tlsg;
577         LSym*   plan9privates;
578         Prog*   curp;
579         Prog*   printp;
580         Prog*   blitrl;
581         Prog*   elitrl;
582         int     rexflag;
583         int     rep; // for nacl
584         int     repn; // for nacl
585         int     lock; // for nacl
586         int     asmode;
587         uchar*  andptr;
588         uchar   and[100];
589         int64   instoffset;
590         int32   autosize;
591         int32   armsize;
592
593         // for reading input files (during linker)
594         vlong   pc;
595         char**  libdir;
596         int32   nlibdir;
597         int32   maxlibdir;
598         Library*        library;
599         int     libraryp;
600         int     nlibrary;
601         int     tlsoffset;
602         void    (*diag)(char*, ...);
603         int     mode;
604         Auto*   curauto;
605         Auto*   curhist;
606         LSym*   cursym;
607         int     version;
608         LSym*   textp;
609         LSym*   etextp;
610         int32   histdepth;
611         int32   nhistfile;
612         LSym*   filesyms;
613 };
614
615 enum {
616         LittleEndian = 0x04030201,
617         BigEndian = 0x01020304,
618 };
619
620 // LinkArch is the definition of a single architecture.
621 struct LinkArch
622 {
623         char*   name; // "arm", "amd64", and so on
624         int     thechar;        // '5', '6', and so on
625         int32   endian; // LittleEndian or BigEndian
626
627         void    (*preprocess)(Link*, LSym*);
628         void    (*assemble)(Link*, LSym*);
629         void    (*follow)(Link*, LSym*);
630         void    (*progedit)(Link*, Prog*);
631
632         int     minlc;
633         int     ptrsize;
634         int     regsize;
635 };
636
637 /* executable header types */
638 enum {
639         Hunknown = 0,
640         Hdarwin,
641         Hdragonfly,
642         Helf,
643         Hfreebsd,
644         Hlinux,
645         Hnacl,
646         Hnetbsd,
647         Hopenbsd,
648         Hplan9,
649         Hsolaris,
650         Hwindows,
651 };
652
653 enum
654 {
655         LinkAuto = 0,
656         LinkInternal,
657         LinkExternal,
658 };
659
660 extern  uchar   fnuxi8[8];
661 extern  uchar   fnuxi4[4];
662 extern  uchar   inuxi1[1];
663 extern  uchar   inuxi2[2];
664 extern  uchar   inuxi4[4];
665 extern  uchar   inuxi8[8];
666
667 // asm5.c
668 void    span5(Link *ctxt, LSym *s);
669 int     chipfloat5(Link *ctxt, float64 e);
670 int     chipzero5(Link *ctxt, float64 e);
671
672 // asm6.c
673 void    span6(Link *ctxt, LSym *s);
674
675 // asm8.c
676 void    span8(Link *ctxt, LSym *s);
677
678 // asm9.c
679 void    span9(Link *ctxt, LSym *s);
680
681 // data.c
682 vlong   addaddr(Link *ctxt, LSym *s, LSym *t);
683 vlong   addaddrplus(Link *ctxt, LSym *s, LSym *t, vlong add);
684 vlong   addaddrplus4(Link *ctxt, LSym *s, LSym *t, vlong add);
685 vlong   addpcrelplus(Link *ctxt, LSym *s, LSym *t, vlong add);
686 Reloc*  addrel(LSym *s);
687 vlong   addsize(Link *ctxt, LSym *s, LSym *t);
688 vlong   adduint16(Link *ctxt, LSym *s, uint16 v);
689 vlong   adduint32(Link *ctxt, LSym *s, uint32 v);
690 vlong   adduint64(Link *ctxt, LSym *s, uint64 v);
691 vlong   adduint8(Link *ctxt, LSym *s, uint8 v);
692 vlong   adduintxx(Link *ctxt, LSym *s, uint64 v, int wid);
693 void    mangle(char *file);
694 void    savedata(Link *ctxt, LSym *s, Prog *p, char *pn);
695 void    savedata1(Link *ctxt, LSym *s, Prog *p, char *pn, int enforce_order);
696 vlong   setaddr(Link *ctxt, LSym *s, vlong off, LSym *t);
697 vlong   setaddrplus(Link *ctxt, LSym *s, vlong off, LSym *t, vlong add);
698 vlong   setuint16(Link *ctxt, LSym *s, vlong r, uint16 v);
699 vlong   setuint32(Link *ctxt, LSym *s, vlong r, uint32 v);
700 vlong   setuint64(Link *ctxt, LSym *s, vlong r, uint64 v);
701 vlong   setuint8(Link *ctxt, LSym *s, vlong r, uint8 v);
702 vlong   setuintxx(Link *ctxt, LSym *s, vlong off, uint64 v, vlong wid);
703 void    symgrow(Link *ctxt, LSym *s, vlong siz);
704
705 // go.c
706 void    double2ieee(uint64 *ieee, double native);
707 void*   emallocz(long n);
708 void*   erealloc(void *p, long n);
709 char*   estrdup(char *p);
710 char*   expandpkg(char *t0, char *pkg);
711 void    linksetexp(void);
712 char*   expstring(void);
713
714 extern  int     fieldtrack_enabled;
715 extern  int     framepointer_enabled;
716
717 // ld.c
718 void    addhist(Link *ctxt, int32 line, int type);
719 void    addlib(Link *ctxt, char *src, char *obj, char *path);
720 void    addlibpath(Link *ctxt, char *srcref, char *objref, char *file, char *pkg);
721 void    collapsefrog(Link *ctxt, LSym *s);
722 void    copyhistfrog(Link *ctxt, char *buf, int nbuf);
723 int     find1(int32 l, int c);
724 void    linkgetline(Link *ctxt, int32 line, LSym **f, int32 *l);
725 void    histtoauto(Link *ctxt);
726 void    mkfwd(LSym*);
727 void    nuxiinit(LinkArch*);
728 void    savehist(Link *ctxt, int32 line, int32 off);
729 Prog*   copyp(Link*, Prog*);
730 Prog*   appendp(Link*, Prog*);
731 vlong   atolwhex(char*);
732
733 // list[5689].c
734 void    listinit5(void);
735 void    listinit6(void);
736 void    listinit8(void);
737 void    listinit9(void);
738
739 // obj.c
740 int     linklinefmt(Link *ctxt, Fmt *fp);
741 void    linklinehist(Link *ctxt, int lineno, char *f, int offset);
742 Plist*  linknewplist(Link *ctxt);
743 void    linkprfile(Link *ctxt, int32 l);
744
745 // objfile.c
746 void    ldobjfile(Link *ctxt, Biobuf *b, char *pkg, int64 len, char *path);
747 void    writeobj(Link *ctxt, Biobuf *b);
748
749 // pass.c
750 Prog*   brchain(Link *ctxt, Prog *p);
751 Prog*   brloop(Link *ctxt, Prog *p);
752 void    linkpatch(Link *ctxt, LSym *sym);
753
754 // pcln.c
755 void    linkpcln(Link*, LSym*);
756
757 // sym.c
758 LSym*   linklookup(Link *ctxt, char *name, int v);
759 Link*   linknew(LinkArch*);
760 LSym*   linknewsym(Link *ctxt, char *symb, int v);
761 LSym*   linkrlookup(Link *ctxt, char *name, int v);
762 int     linksymfmt(Fmt *f);
763 int     headtype(char*);
764 char*   headstr(int);
765
766 extern  char*   anames5[];
767 extern  char*   anames6[];
768 extern  char*   anames8[];
769 extern  char*   anames9[];
770
771 extern  char*   cnames5[];
772 extern  char*   cnames9[];
773
774 extern  char*   dnames5[];
775 extern  char*   dnames6[];
776 extern  char*   dnames8[];
777 extern  char*   dnames9[];
778
779 extern  LinkArch        link386;
780 extern  LinkArch        linkamd64;
781 extern  LinkArch        linkamd64p32;
782 extern  LinkArch        linkarm;
783 extern  LinkArch        linkppc64;
784 extern  LinkArch        linkppc64le;
785
786 extern  int     linkbasepointer;
787 extern  void    linksetexp(void);
788
789 #pragma varargck        type    "A"     int
790 #pragma varargck        type    "E"     uint
791 #pragma varargck        type    "D"     Addr*
792 #pragma varargck        type    "lD"    Addr*
793 #pragma varargck        type    "P"     Prog*
794 #pragma varargck        type    "R"     int
795 #pragma varargck        type    "^"     int // for 5l/9l, C_* classes (liblink internal)
796
797 // TODO(ality): remove this workaround.
798 //   It's here because Pconv in liblink/list?.c references %L.
799 #pragma varargck        type    "L"     int32