Source file src/cmd/link/internal/ld/typelink.go

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ld
     6  
     7  import (
     8  	"cmd/internal/objabi"
     9  	"cmd/link/internal/loader"
    10  	"cmd/link/internal/sym"
    11  )
    12  
    13  // typelink generates the itablink table which is used by runtime.itabInit.
    14  func (ctxt *Link) typelink() {
    15  	ldr := ctxt.loader
    16  	var itabs []loader.Sym
    17  	for s := loader.Sym(1); s < loader.Sym(ldr.NSym()); s++ {
    18  		if !ldr.AttrReachable(s) {
    19  			continue
    20  		}
    21  		if ldr.IsItab(s) {
    22  			itabs = append(itabs, s)
    23  		}
    24  	}
    25  
    26  	ptrsize := ctxt.Arch.PtrSize
    27  	il := ldr.CreateSymForUpdate("runtime.itablink", 0)
    28  	il.SetType(sym.SITABLINK)
    29  	ldr.SetAttrLocal(il.Sym(), true)
    30  	il.SetSize(int64(ptrsize * len(itabs)))
    31  	il.Grow(il.Size())
    32  	relocs := il.AddRelocs(len(itabs))
    33  	for i, s := range itabs {
    34  		r := relocs.At(i)
    35  		r.SetSym(s)
    36  		r.SetOff(int32(i * ptrsize))
    37  		r.SetSiz(uint8(ptrsize))
    38  		r.SetType(objabi.R_ADDR)
    39  	}
    40  }
    41  

View as plain text