blob: a384b9508da031451196324a53339fb339ffa60e [file] [log] [blame]
Russ Cox1f9dbb62015-02-27 22:57:28 -05001// 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
31package ld
32
Dave Cheney71274e42015-05-02 12:44:49 +100033import (
34 "cmd/internal/obj"
Michael Hudson-Doyle9f5d0bf2015-05-05 16:10:12 +120035 "debug/elf"
Dave Cheney71274e42015-05-02 12:44:49 +100036 "encoding/binary"
Russ Cox512f75e2015-05-08 01:43:18 -040037 "fmt"
Dave Cheney71274e42015-05-02 12:44:49 +100038)
Russ Cox1f9dbb62015-02-27 22:57:28 -050039
40type LSym struct {
Michael Hudson-Doyle9f5d0bf2015-05-05 16:10:12 +120041 Name string
42 Extname string
43 Type int16
44 Version int16
45 Dupok uint8
46 Cfunc uint8
47 External uint8
48 Nosplit uint8
49 Reachable bool
50 Cgoexport uint8
51 Special uint8
52 Stkcheck uint8
53 Hide uint8
54 Leaf uint8
55 Localentry uint8
56 Onlist uint8
57 // ElfType is set for symbols read from shared libraries by ldshlibsyms. It
58 // is not set for symbols defined by the packages being linked or by symbols
59 // read by ldelf (and so is left as elf.STT_NOTYPE).
60 ElfType elf.SymType
Russ Cox1f9dbb62015-02-27 22:57:28 -050061 Dynid int32
Russ Cox1f9dbb62015-02-27 22:57:28 -050062 Plt int32
63 Got int32
64 Align int32
65 Elfsym int32
66 Args int32
67 Locals int32
68 Value int64
69 Size int64
70 Hash *LSym
71 Allsym *LSym
72 Next *LSym
73 Sub *LSym
74 Outer *LSym
75 Gotype *LSym
76 Reachparent *LSym
77 Queue *LSym
78 File string
79 Dynimplib string
80 Dynimpvers string
Michael Hudson-Doylecf2736c2015-05-27 12:04:25 +120081 Sect *Section
Russ Cox1f9dbb62015-02-27 22:57:28 -050082 Autom *Auto
83 Pcln *Pcln
84 P []byte
85 R []Reloc
Michael Hudson-Doyle00bc19e2015-03-30 02:59:10 +000086 Local bool
Russ Cox1f9dbb62015-02-27 22:57:28 -050087}
88
Russ Cox512f75e2015-05-08 01:43:18 -040089func (s *LSym) String() string {
90 if s.Version == 0 {
91 return s.Name
92 }
93 return fmt.Sprintf("%s<%d>", s.Name, s.Version)
94}
95
Russ Cox1f9dbb62015-02-27 22:57:28 -050096type Reloc struct {
97 Off int32
98 Siz uint8
99 Done uint8
100 Type int32
101 Variant int32
102 Add int64
103 Xadd int64
104 Sym *LSym
105 Xsym *LSym
106}
107
108type Auto struct {
109 Asym *LSym
110 Link *Auto
111 Aoffset int32
112 Name int16
113 Gotype *LSym
114}
115
Michael Hudson-Doyle77fc03f2015-04-11 12:05:21 +0800116type Shlib struct {
117 Path string
118 Hash []byte
Michael Hudson-Doylebcc18702015-05-25 14:51:02 +1200119 Deps []string
Michael Hudson-Doylec949cff2015-05-25 16:13:50 +1200120 File *elf.File
Michael Hudson-Doyle77fc03f2015-04-11 12:05:21 +0800121}
122
Russ Cox1f9dbb62015-02-27 22:57:28 -0500123type Link struct {
Michael Hudson-Doyle7f9e4432015-08-19 13:34:33 +1200124 Thechar int32
125 Thestring string
126 Goarm int32
127 Headtype int
128 Arch *LinkArch
129 Debugasm int32
130 Debugvlog int32
131 Bso *obj.Biobuf
132 Windows int32
133 Goroot string
134 Hash map[symVer]*LSym
135 Allsym *LSym
136 Nsymbol int32
137 Tlsg *LSym
138 Libdir []string
139 Library []*Library
140 Shlibs []Shlib
141 Tlsoffset int
142 Diag func(string, ...interface{})
143 Cursym *LSym
144 Version int
145 Textp *LSym
146 Etextp *LSym
147 Nhistfile int32
148 Filesyms *LSym
149 Moduledata *LSym
Russ Cox1f9dbb62015-02-27 22:57:28 -0500150}
151
Michael Hudson-Doyled66f6c2c2015-10-12 12:19:20 +1300152// The smallest possible offset from the hardware stack pointer to a local
153// variable on the stack. Architectures that use a link register save its value
154// on the stack in the function prologue and so always have a pointer between
155// the hardware stack pointer and the local variable area.
156func (ctxt *Link) FixedFrameSize() int64 {
157 switch ctxt.Arch.Thechar {
158 case '6', '8':
159 return 0
160 default:
161 return int64(ctxt.Arch.Ptrsize)
162 }
163}
164
Russ Cox1f9dbb62015-02-27 22:57:28 -0500165type LinkArch struct {
166 ByteOrder binary.ByteOrder
167 Name string
168 Thechar int
Russ Cox1f9dbb62015-02-27 22:57:28 -0500169 Minlc int
170 Ptrsize int
171 Regsize int
172}
173
174type Library struct {
175 Objref string
176 Srcref string
177 File string
178 Pkg string
Michael Hudson-Doyle75c05662015-04-01 14:57:34 +1300179 Shlib string
Michael Hudson-Doyle77fc03f2015-04-11 12:05:21 +0800180 hash []byte
Russ Cox1f9dbb62015-02-27 22:57:28 -0500181}
182
183type Pcln struct {
184 Pcsp Pcdata
185 Pcfile Pcdata
186 Pcline Pcdata
187 Pcdata []Pcdata
188 Npcdata int
189 Funcdata []*LSym
190 Funcdataoff []int64
191 Nfuncdata int
192 File []*LSym
193 Nfile int
194 Mfile int
195 Lastfile *LSym
196 Lastindex int
197}
198
199type Pcdata struct {
200 P []byte
201}
202
203type Pciter struct {
204 d Pcdata
205 p []byte
206 pc uint32
207 nextpc uint32
208 pcscale uint32
209 value int32
210 start int
211 done int
212}
213
Russ Cox1f9dbb62015-02-27 22:57:28 -0500214// Reloc.variant
215const (
216 RV_NONE = iota
217 RV_POWER_LO
218 RV_POWER_HI
219 RV_POWER_HA
220 RV_POWER_DS
221 RV_CHECK_OVERFLOW = 1 << 8
222 RV_TYPE_MASK = RV_CHECK_OVERFLOW - 1
223)
224
Russ Cox1f9dbb62015-02-27 22:57:28 -0500225// Pcdata iterator.
226// for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
227
Russ Cox1f9dbb62015-02-27 22:57:28 -0500228// Link holds the context for writing object code from a compiler
229// to be linker input or for reading that input into the linker.
230
Russ Cox1f9dbb62015-02-27 22:57:28 -0500231// LinkArch is the definition of a single architecture.
232
Russ Cox1f9dbb62015-02-27 22:57:28 -0500233const (
234 LinkAuto = 0 + iota
235 LinkInternal
236 LinkExternal
237)