rsc.io/go@v0.0.0-20150416155037-e040fd465409/src/cmd/internal/ld/link.go (about) 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 package ld 32 33 import "encoding/binary" 34 35 type LSym struct { 36 Name string 37 Extname string 38 Type int16 39 Version int16 40 Dupok uint8 41 Cfunc uint8 42 External uint8 43 Nosplit uint8 44 Reachable bool 45 Cgoexport uint8 46 Special uint8 47 Stkcheck uint8 48 Hide uint8 49 Leaf uint8 50 Localentry uint8 51 Onlist uint8 52 Dynid int32 53 Plt int32 54 Got int32 55 Align int32 56 Elfsym int32 57 Args int32 58 Locals int32 59 Value int64 60 Size int64 61 Hash *LSym 62 Allsym *LSym 63 Next *LSym 64 Sub *LSym 65 Outer *LSym 66 Gotype *LSym 67 Reachparent *LSym 68 Queue *LSym 69 File string 70 Dynimplib string 71 Dynimpvers string 72 Sect interface{} 73 Autom *Auto 74 Pcln *Pcln 75 P []byte 76 R []Reloc 77 Local bool 78 } 79 80 type Reloc struct { 81 Off int32 82 Siz uint8 83 Done uint8 84 Type int32 85 Variant int32 86 Add int64 87 Xadd int64 88 Sym *LSym 89 Xsym *LSym 90 } 91 92 type Auto struct { 93 Asym *LSym 94 Link *Auto 95 Aoffset int32 96 Name int16 97 Gotype *LSym 98 } 99 100 type Link struct { 101 Thechar int32 102 Thestring string 103 Goarm int32 104 Headtype int 105 Arch *LinkArch 106 Debugasm int32 107 Debugvlog int32 108 Bso *Biobuf 109 Windows int32 110 Goroot string 111 Hash map[symVer]*LSym 112 Allsym *LSym 113 Nsymbol int32 114 Tlsg *LSym 115 Libdir []string 116 Library []Library 117 Shlibs []string 118 Tlsoffset int 119 Diag func(string, ...interface{}) 120 Cursym *LSym 121 Version int 122 Textp *LSym 123 Etextp *LSym 124 Nhistfile int32 125 Filesyms *LSym 126 } 127 128 type LinkArch struct { 129 ByteOrder binary.ByteOrder 130 Name string 131 Thechar int 132 Minlc int 133 Ptrsize int 134 Regsize int 135 } 136 137 type Library struct { 138 Objref string 139 Srcref string 140 File string 141 Pkg string 142 Shlib string 143 } 144 145 type Pcln struct { 146 Pcsp Pcdata 147 Pcfile Pcdata 148 Pcline Pcdata 149 Pcdata []Pcdata 150 Npcdata int 151 Funcdata []*LSym 152 Funcdataoff []int64 153 Nfuncdata int 154 File []*LSym 155 Nfile int 156 Mfile int 157 Lastfile *LSym 158 Lastindex int 159 } 160 161 type Pcdata struct { 162 P []byte 163 } 164 165 type Pciter struct { 166 d Pcdata 167 p []byte 168 pc uint32 169 nextpc uint32 170 pcscale uint32 171 value int32 172 start int 173 done int 174 } 175 176 // LSym.type 177 const ( 178 Sxxx = iota 179 STEXT 180 SELFRXSECT 181 STYPE 182 SSTRING 183 SGOSTRING 184 SGOFUNC 185 SRODATA 186 SFUNCTAB 187 STYPELINK 188 SSYMTAB 189 SPCLNTAB 190 SELFROSECT 191 SMACHOPLT 192 SELFSECT 193 SMACHO 194 SMACHOGOT 195 SWINDOWS 196 SELFGOT 197 SNOPTRDATA 198 SINITARR 199 SDATA 200 SBSS 201 SNOPTRBSS 202 STLSBSS 203 SXREF 204 SMACHOSYMSTR 205 SMACHOSYMTAB 206 SMACHOINDIRECTPLT 207 SMACHOINDIRECTGOT 208 SFILE 209 SFILEPATH 210 SCONST 211 SDYNIMPORT 212 SHOSTOBJ 213 SSUB = 1 << 8 214 SMASK = SSUB - 1 215 SHIDDEN = 1 << 9 216 ) 217 218 // Reloc.type 219 const ( 220 R_ADDR = 1 + iota 221 R_ADDRPOWER 222 R_ADDRARM64 223 R_SIZE 224 R_CALL 225 R_CALLARM 226 R_CALLARM64 227 R_CALLIND 228 R_CALLPOWER 229 R_CONST 230 R_PCREL 231 R_TLS 232 R_TLS_LE 233 R_TLS_IE 234 R_GOTOFF 235 R_PLT0 236 R_PLT1 237 R_PLT2 238 R_USEFIELD 239 R_POWER_TOC 240 R_GOTPCREL 241 ) 242 243 // Reloc.variant 244 const ( 245 RV_NONE = iota 246 RV_POWER_LO 247 RV_POWER_HI 248 RV_POWER_HA 249 RV_POWER_DS 250 RV_CHECK_OVERFLOW = 1 << 8 251 RV_TYPE_MASK = RV_CHECK_OVERFLOW - 1 252 ) 253 254 // Auto.name 255 const ( 256 A_AUTO = 1 + iota 257 A_PARAM 258 ) 259 260 const ( 261 LINKHASH = 100003 262 ) 263 264 // Pcdata iterator. 265 // for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) } 266 267 // symbol version, incremented each time a file is loaded. 268 // version==1 is reserved for savehist. 269 const ( 270 HistVersion = 1 271 ) 272 273 // Link holds the context for writing object code from a compiler 274 // to be linker input or for reading that input into the linker. 275 276 // LinkArch is the definition of a single architecture. 277 278 /* executable header types */ 279 const ( 280 Hunknown = 0 + iota 281 Hdarwin 282 Hdragonfly 283 Helf 284 Hfreebsd 285 Hlinux 286 Hnacl 287 Hnetbsd 288 Hopenbsd 289 Hplan9 290 Hsolaris 291 Hwindows 292 ) 293 294 const ( 295 LinkAuto = 0 + iota 296 LinkInternal 297 LinkExternal 298 )