github.com/huandu/go@v0.0.0-20151114150818-04e615e41150/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  }
   150  
   151  type LinkArch struct {
   152  	ByteOrder binary.ByteOrder
   153  	Name      string
   154  	Thechar   int
   155  	Minlc     int
   156  	Ptrsize   int
   157  	Regsize   int
   158  }
   159  
   160  type Library struct {
   161  	Objref string
   162  	Srcref string
   163  	File   string
   164  	Pkg    string
   165  	Shlib  string
   166  	hash   []byte
   167  }
   168  
   169  type Pcln struct {
   170  	Pcsp        Pcdata
   171  	Pcfile      Pcdata
   172  	Pcline      Pcdata
   173  	Pcdata      []Pcdata
   174  	Npcdata     int
   175  	Funcdata    []*LSym
   176  	Funcdataoff []int64
   177  	Nfuncdata   int
   178  	File        []*LSym
   179  	Nfile       int
   180  	Mfile       int
   181  	Lastfile    *LSym
   182  	Lastindex   int
   183  }
   184  
   185  type Pcdata struct {
   186  	P []byte
   187  }
   188  
   189  type Pciter struct {
   190  	d       Pcdata
   191  	p       []byte
   192  	pc      uint32
   193  	nextpc  uint32
   194  	pcscale uint32
   195  	value   int32
   196  	start   int
   197  	done    int
   198  }
   199  
   200  // Reloc.variant
   201  const (
   202  	RV_NONE = iota
   203  	RV_POWER_LO
   204  	RV_POWER_HI
   205  	RV_POWER_HA
   206  	RV_POWER_DS
   207  	RV_CHECK_OVERFLOW = 1 << 8
   208  	RV_TYPE_MASK      = RV_CHECK_OVERFLOW - 1
   209  )
   210  
   211  const (
   212  	LINKHASH = 100003
   213  )
   214  
   215  // Pcdata iterator.
   216  //	for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
   217  
   218  // Link holds the context for writing object code from a compiler
   219  // to be linker input or for reading that input into the linker.
   220  
   221  // LinkArch is the definition of a single architecture.
   222  
   223  const (
   224  	LinkAuto = 0 + iota
   225  	LinkInternal
   226  	LinkExternal
   227  )