github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/link/internal/loader/symbolbuilder.go (about)

     1  // Copyright 2019 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 loader
     6  
     7  import (
     8  	"github.com/shogo82148/std/cmd/internal/objabi"
     9  	"github.com/shogo82148/std/cmd/internal/sys"
    10  	"github.com/shogo82148/std/cmd/link/internal/sym"
    11  )
    12  
    13  // SymbolBuilder is a helper designed to help with the construction
    14  // of new symbol contents.
    15  type SymbolBuilder struct {
    16  	*extSymPayload
    17  	symIdx Sym
    18  	l      *Loader
    19  }
    20  
    21  // MakeSymbolBuilder creates a symbol builder for use in constructing
    22  // an entirely new symbol.
    23  func (l *Loader) MakeSymbolBuilder(name string) *SymbolBuilder
    24  
    25  // MakeSymbolUpdater creates a symbol builder helper for an existing
    26  // symbol 'symIdx'. If 'symIdx' is not an external symbol, then create
    27  // a clone of it (copy name, properties, etc) fix things up so that
    28  // the lookup tables and caches point to the new version, not the old
    29  // version.
    30  func (l *Loader) MakeSymbolUpdater(symIdx Sym) *SymbolBuilder
    31  
    32  // CreateSymForUpdate creates a symbol with given name and version,
    33  // returns a CreateSymForUpdate for update. If the symbol already
    34  // exists, it will update in-place.
    35  func (l *Loader) CreateSymForUpdate(name string, version int) *SymbolBuilder
    36  
    37  func (sb *SymbolBuilder) Sym() Sym
    38  func (sb *SymbolBuilder) Name() string
    39  func (sb *SymbolBuilder) Version() int
    40  func (sb *SymbolBuilder) Type() sym.SymKind
    41  func (sb *SymbolBuilder) Size() int64
    42  func (sb *SymbolBuilder) Data() []byte
    43  func (sb *SymbolBuilder) Value() int64
    44  func (sb *SymbolBuilder) Align() int32
    45  func (sb *SymbolBuilder) Localentry() uint8
    46  func (sb *SymbolBuilder) OnList() bool
    47  func (sb *SymbolBuilder) External() bool
    48  func (sb *SymbolBuilder) Extname() string
    49  func (sb *SymbolBuilder) CgoExportDynamic() bool
    50  func (sb *SymbolBuilder) Dynimplib() string
    51  func (sb *SymbolBuilder) Dynimpvers() string
    52  func (sb *SymbolBuilder) SubSym() Sym
    53  func (sb *SymbolBuilder) GoType() Sym
    54  func (sb *SymbolBuilder) VisibilityHidden() bool
    55  func (sb *SymbolBuilder) Sect() *sym.Section
    56  
    57  func (sb *SymbolBuilder) SetType(kind sym.SymKind)
    58  func (sb *SymbolBuilder) SetSize(size int64)
    59  func (sb *SymbolBuilder) SetData(data []byte)
    60  func (sb *SymbolBuilder) SetOnList(v bool)
    61  func (sb *SymbolBuilder) SetExternal(v bool)
    62  func (sb *SymbolBuilder) SetValue(v int64)
    63  func (sb *SymbolBuilder) SetAlign(align int32)
    64  func (sb *SymbolBuilder) SetLocalentry(value uint8)
    65  func (sb *SymbolBuilder) SetExtname(value string)
    66  func (sb *SymbolBuilder) SetDynimplib(value string)
    67  func (sb *SymbolBuilder) SetDynimpvers(value string)
    68  func (sb *SymbolBuilder) SetPlt(value int32)
    69  func (sb *SymbolBuilder) SetGot(value int32)
    70  func (sb *SymbolBuilder) SetSpecial(value bool)
    71  func (sb *SymbolBuilder) SetLocal(value bool)
    72  func (sb *SymbolBuilder) SetVisibilityHidden(value bool)
    73  
    74  func (sb *SymbolBuilder) SetNotInSymbolTable(value bool)
    75  
    76  func (sb *SymbolBuilder) SetSect(sect *sym.Section)
    77  
    78  func (sb *SymbolBuilder) AddBytes(data []byte)
    79  
    80  func (sb *SymbolBuilder) Relocs() Relocs
    81  
    82  // ResetRelocs removes all relocations on this symbol.
    83  func (sb *SymbolBuilder) ResetRelocs()
    84  
    85  // SetRelocType sets the type of the 'i'-th relocation on this sym to 't'
    86  func (sb *SymbolBuilder) SetRelocType(i int, t objabi.RelocType)
    87  
    88  // SetRelocSym sets the target sym of the 'i'-th relocation on this sym to 's'
    89  func (sb *SymbolBuilder) SetRelocSym(i int, tgt Sym)
    90  
    91  // SetRelocAdd sets the addend of the 'i'-th relocation on this sym to 'a'
    92  func (sb *SymbolBuilder) SetRelocAdd(i int, a int64)
    93  
    94  // Add n relocations, return a handle to the relocations.
    95  func (sb *SymbolBuilder) AddRelocs(n int) Relocs
    96  
    97  // Add a relocation with given type, return its handle and index
    98  // (to set other fields).
    99  func (sb *SymbolBuilder) AddRel(typ objabi.RelocType) (Reloc, int)
   100  
   101  // Sort relocations by offset.
   102  func (sb *SymbolBuilder) SortRelocs()
   103  
   104  func (sb *SymbolBuilder) Reachable() bool
   105  
   106  func (sb *SymbolBuilder) SetReachable(v bool)
   107  
   108  func (sb *SymbolBuilder) ReadOnly() bool
   109  
   110  func (sb *SymbolBuilder) SetReadOnly(v bool)
   111  
   112  func (sb *SymbolBuilder) DuplicateOK() bool
   113  
   114  func (sb *SymbolBuilder) SetDuplicateOK(v bool)
   115  
   116  func (sb *SymbolBuilder) Outer() Sym
   117  
   118  func (sb *SymbolBuilder) Sub() Sym
   119  
   120  func (sb *SymbolBuilder) SortSub()
   121  
   122  func (sb *SymbolBuilder) AddInteriorSym(sub Sym)
   123  
   124  func (sb *SymbolBuilder) AddUint8(v uint8) int64
   125  
   126  func (sb *SymbolBuilder) AddUintXX(arch *sys.Arch, v uint64, wid int) int64
   127  
   128  func (sb *SymbolBuilder) AddUint16(arch *sys.Arch, v uint16) int64
   129  
   130  func (sb *SymbolBuilder) AddUint32(arch *sys.Arch, v uint32) int64
   131  
   132  func (sb *SymbolBuilder) AddUint64(arch *sys.Arch, v uint64) int64
   133  
   134  func (sb *SymbolBuilder) AddUint(arch *sys.Arch, v uint64) int64
   135  
   136  func (sb *SymbolBuilder) SetUint8(arch *sys.Arch, r int64, v uint8) int64
   137  
   138  func (sb *SymbolBuilder) SetUint16(arch *sys.Arch, r int64, v uint16) int64
   139  
   140  func (sb *SymbolBuilder) SetUint32(arch *sys.Arch, r int64, v uint32) int64
   141  
   142  func (sb *SymbolBuilder) SetUint(arch *sys.Arch, r int64, v uint64) int64
   143  
   144  func (sb *SymbolBuilder) SetUintptr(arch *sys.Arch, r int64, v uintptr) int64
   145  
   146  func (sb *SymbolBuilder) SetAddrPlus(arch *sys.Arch, off int64, tgt Sym, add int64) int64
   147  
   148  func (sb *SymbolBuilder) SetAddr(arch *sys.Arch, off int64, tgt Sym) int64
   149  
   150  func (sb *SymbolBuilder) AddStringAt(off int64, str string) int64
   151  
   152  // AddCStringAt adds str plus a null terminating byte.
   153  func (sb *SymbolBuilder) AddCStringAt(off int64, str string) int64
   154  
   155  func (sb *SymbolBuilder) Addstring(str string) int64
   156  
   157  func (sb *SymbolBuilder) SetBytesAt(off int64, b []byte) int64
   158  
   159  // Add a symbol reference (relocation) with given type, addend, and size
   160  // (the most generic form).
   161  func (sb *SymbolBuilder) AddSymRef(arch *sys.Arch, tgt Sym, add int64, typ objabi.RelocType, rsize int) int64
   162  
   163  func (sb *SymbolBuilder) AddAddrPlus(arch *sys.Arch, tgt Sym, add int64) int64
   164  
   165  func (sb *SymbolBuilder) AddAddrPlus4(arch *sys.Arch, tgt Sym, add int64) int64
   166  
   167  func (sb *SymbolBuilder) AddAddr(arch *sys.Arch, tgt Sym) int64
   168  
   169  func (sb *SymbolBuilder) AddPEImageRelativeAddrPlus(arch *sys.Arch, tgt Sym, add int64) int64
   170  
   171  func (sb *SymbolBuilder) AddPCRelPlus(arch *sys.Arch, tgt Sym, add int64) int64
   172  
   173  func (sb *SymbolBuilder) AddCURelativeAddrPlus(arch *sys.Arch, tgt Sym, add int64) int64
   174  
   175  func (sb *SymbolBuilder) AddSize(arch *sys.Arch, tgt Sym) int64
   176  
   177  // GenAddAddrPlusFunc returns a function to be called when capturing
   178  // a function symbol's address. In later stages of the link (when
   179  // address assignment is done) when doing internal linking and
   180  // targeting an executable, we can just emit the address of a function
   181  // directly instead of generating a relocation. Clients can call
   182  // this function (setting 'internalExec' based on build mode and target)
   183  // and then invoke the returned function in roughly the same way that
   184  // loader.*SymbolBuilder.AddAddrPlus would be used.
   185  func GenAddAddrPlusFunc(internalExec bool) func(s *SymbolBuilder, arch *sys.Arch, tgt Sym, add int64) int64
   186  
   187  func (sb *SymbolBuilder) MakeWritable()
   188  
   189  func (sb *SymbolBuilder) AddUleb(v uint64)