github.com/d4l3k/go@v0.0.0-20151015000803-65fc379daeda/src/cmd/link/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 (
    34  	"cmd/internal/obj"
    35  	"debug/elf"
    36  	"encoding/binary"
    37  	"fmt"
    38  )
    39  
    40  type LSym struct {
    41  	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
    61  	Dynid       int32
    62  	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
    81  	Sect        *Section
    82  	Autom       *Auto
    83  	Pcln        *Pcln
    84  	P           []byte
    85  	R           []Reloc
    86  	Local       bool
    87  }
    88  
    89  func (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  
    96  type 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  
   108  type Auto struct {
   109  	Asym    *LSym
   110  	Link    *Auto
   111  	Aoffset int32
   112  	Name    int16
   113  	Gotype  *LSym
   114  }
   115  
   116  type Shlib struct {
   117  	Path string
   118  	Hash []byte
   119  	Deps []string
   120  	File *elf.File
   121  }
   122  
   123  type Link struct {
   124  	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
   150  }
   151  
   152  type LinkArch struct {
   153  	ByteOrder binary.ByteOrder
   154  	Name      string
   155  	Thechar   int
   156  	Minlc     int
   157  	Ptrsize   int
   158  	Regsize   int
   159  }
   160  
   161  type Library struct {
   162  	Objref string
   163  	Srcref string
   164  	File   string
   165  	Pkg    string
   166  	Shlib  string
   167  	hash   []byte
   168  }
   169  
   170  type Pcln struct {
   171  	Pcsp        Pcdata
   172  	Pcfile      Pcdata
   173  	Pcline      Pcdata
   174  	Pcdata      []Pcdata
   175  	Npcdata     int
   176  	Funcdata    []*LSym
   177  	Funcdataoff []int64
   178  	Nfuncdata   int
   179  	File        []*LSym
   180  	Nfile       int
   181  	Mfile       int
   182  	Lastfile    *LSym
   183  	Lastindex   int
   184  }
   185  
   186  type Pcdata struct {
   187  	P []byte
   188  }
   189  
   190  type Pciter struct {
   191  	d       Pcdata
   192  	p       []byte
   193  	pc      uint32
   194  	nextpc  uint32
   195  	pcscale uint32
   196  	value   int32
   197  	start   int
   198  	done    int
   199  }
   200  
   201  // Reloc.variant
   202  const (
   203  	RV_NONE = iota
   204  	RV_POWER_LO
   205  	RV_POWER_HI
   206  	RV_POWER_HA
   207  	RV_POWER_DS
   208  	RV_CHECK_OVERFLOW = 1 << 8
   209  	RV_TYPE_MASK      = RV_CHECK_OVERFLOW - 1
   210  )
   211  
   212  // Pcdata iterator.
   213  //	for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
   214  
   215  // Link holds the context for writing object code from a compiler
   216  // to be linker input or for reading that input into the linker.
   217  
   218  // LinkArch is the definition of a single architecture.
   219  
   220  const (
   221  	LinkAuto = 0 + iota
   222  	LinkInternal
   223  	LinkExternal
   224  )