github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/link/internal/sym/attribute.go (about) 1 // Copyright 2017 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 sym 6 7 // Attribute is a set of common symbol attributes. 8 type Attribute int32 9 10 const ( 11 // AttrDuplicateOK marks a symbol that can be present in multiple object 12 // files. 13 AttrDuplicateOK Attribute = 1 << iota 14 // AttrExternal marks function symbols loaded from host object files. 15 AttrExternal 16 // AttrNoSplit marks functions that cannot split the stack; the linker 17 // cares because it checks that there are no call chains of nosplit 18 // functions that require more than StackLimit bytes (see 19 // lib.go:dostkcheck) 20 AttrNoSplit 21 // AttrReachable marks symbols that are transitively referenced from the 22 // entry points. Unreachable symbols are not written to the output. 23 AttrReachable 24 // AttrCgoExportDynamic and AttrCgoExportStatic mark symbols referenced 25 // by directives written by cgo (in response to //export directives in 26 // the source). 27 AttrCgoExportDynamic 28 AttrCgoExportStatic 29 // AttrSpecial marks symbols that do not have their address (i.e. Value) 30 // computed by the usual mechanism of data.go:dodata() & 31 // data.go:address(). 32 AttrSpecial 33 // AttrStackCheck is used by dostkcheck to only check each NoSplit 34 // function's stack usage once. 35 AttrStackCheck 36 // AttrNotInSymbolTable marks symbols that are not written to the symbol table. 37 AttrNotInSymbolTable 38 // AttrOnList marks symbols that are on some list (such as the list of 39 // all text symbols, or one of the lists of data symbols) and is 40 // consulted to avoid bugs where a symbol is put on a list twice. 41 AttrOnList 42 // AttrLocal marks symbols that are only visible within the module 43 // (executable or shared library) being linked. Only relevant when 44 // dynamically linking Go code. 45 AttrLocal 46 // AttrReflectMethod marks certain methods from the reflect package that 47 // can be used to call arbitrary methods. If no symbol with this bit set 48 // is marked as reachable, more dead code elimination can be done. 49 AttrReflectMethod 50 // AttrMakeTypelink Amarks types that should be added to the typelink 51 // table. See typelinks.go:typelinks(). 52 AttrMakeTypelink 53 // AttrShared marks symbols compiled with the -shared option. 54 AttrShared 55 // AttrVisibilityHidden symbols are ELF symbols with 56 // visibility set to STV_HIDDEN. They become local symbols in 57 // the final executable. Only relevant when internally linking 58 // on an ELF platform. 59 AttrVisibilityHidden 60 // AttrSubSymbol mostly means that the symbol appears on the Sub list of some 61 // other symbol. Unfortunately, it's not 100% reliable; at least, it's not set 62 // correctly for the .TOC. symbol in Link.dodata. Usually the Outer field of the 63 // symbol points to the symbol whose list it is on, but that it is not set for the 64 // symbols added to .windynamic in initdynimport in pe.go. 65 // 66 // TODO(mwhudson): fix the inconsistencies noticed above. 67 // 68 // Sub lists are used when loading host objects (sections from the host object 69 // become regular linker symbols and symbols go on the Sub list of their section) 70 // and for constructing the global offset table when internally linking a dynamic 71 // executable. 72 // 73 // TODO(mwhudson): perhaps a better name for this is AttrNonGoSymbol. 74 AttrSubSymbol 75 // AttrContainer is set on text symbols that are present as the .Outer for some 76 // other symbol. 77 AttrContainer 78 // AttrTopFrame means that the function is an entry point and unwinders 79 // should stop when they hit this function. 80 AttrTopFrame 81 // AttrReadOnly indicates whether the symbol's content (Symbol.P) is backed by 82 // read-only memory. 83 AttrReadOnly 84 // 19 attributes defined so far. 85 ) 86 87 func (a Attribute) DuplicateOK() bool { return a&AttrDuplicateOK != 0 } 88 func (a Attribute) External() bool { return a&AttrExternal != 0 } 89 func (a Attribute) NoSplit() bool { return a&AttrNoSplit != 0 } 90 func (a Attribute) Reachable() bool { return a&AttrReachable != 0 } 91 func (a Attribute) CgoExportDynamic() bool { return a&AttrCgoExportDynamic != 0 } 92 func (a Attribute) CgoExportStatic() bool { return a&AttrCgoExportStatic != 0 } 93 func (a Attribute) Special() bool { return a&AttrSpecial != 0 } 94 func (a Attribute) StackCheck() bool { return a&AttrStackCheck != 0 } 95 func (a Attribute) NotInSymbolTable() bool { return a&AttrNotInSymbolTable != 0 } 96 func (a Attribute) OnList() bool { return a&AttrOnList != 0 } 97 func (a Attribute) Local() bool { return a&AttrLocal != 0 } 98 func (a Attribute) ReflectMethod() bool { return a&AttrReflectMethod != 0 } 99 func (a Attribute) MakeTypelink() bool { return a&AttrMakeTypelink != 0 } 100 func (a Attribute) Shared() bool { return a&AttrShared != 0 } 101 func (a Attribute) VisibilityHidden() bool { return a&AttrVisibilityHidden != 0 } 102 func (a Attribute) SubSymbol() bool { return a&AttrSubSymbol != 0 } 103 func (a Attribute) Container() bool { return a&AttrContainer != 0 } 104 func (a Attribute) TopFrame() bool { return a&AttrTopFrame != 0 } 105 func (a Attribute) ReadOnly() bool { return a&AttrReadOnly != 0 } 106 107 func (a Attribute) CgoExport() bool { 108 return a.CgoExportDynamic() || a.CgoExportStatic() 109 } 110 111 func (a *Attribute) Set(flag Attribute, value bool) { 112 if value { 113 *a |= flag 114 } else { 115 *a &^= flag 116 } 117 }