sym

package standard library
go1.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SymVerABI0        = 0
	SymVerABIInternal = 1
	SymVerABICount    = 2  // Number of internal ABIs
	SymVerStatic      = 10 // Minimum version used by static (file-local) syms
)

Variables

AbiSymKindToSymKind maps values read from object files (which are of type cmd/internal/objabi.SymKind) to values of type SymKind.

ReadOnly are the symbol kinds that form read-only sections. In some cases, if they will require relocations, they are transformed into rel-ro sections using relROMap.

RelROMap describes the transformation of read-only symbols to rel-ro symbols.

Functions

func ABIToVersion added in go1.12

func ABIToVersion(abi obj.ABI) int

func RelocName

func RelocName(arch *sys.Arch, r objabi.RelocType) string

func VersionToABI added in go1.12

func VersionToABI(v int) (obj.ABI, bool)

Types

type CompilationUnit added in go1.14

type CompilationUnit struct {
	Lib       *Library      // Our library
	PclnIndex int           // Index of this CU in pclntab
	PCs       []dwarf.Range // PC ranges, relative to Textp[0]
	DWInfo    *dwarf.DWDie  // CU root DIE
	FileTable []string      // The file table used in this compilation unit.

	Consts    LoaderSym            // Package constants DIEs
	FuncDIEs  []LoaderSym          // Function DIE subtrees
	VarDIEs   []LoaderSym          // Global variable DIEs
	AbsFnDIEs []LoaderSym          // Abstract function DIE subtrees
	RangeSyms []LoaderSym          // Symbols for debug_range
	Textp     []LoaderSym          // Text symbols in this CU
	Addrs     map[LoaderSym]uint32 // slot in .debug_addr for fn sym (DWARF5)
}

A CompilationUnit represents a set of source files that are compiled together. Since all Go sources in a Go package are compiled together, there's one CompilationUnit per package that represents all Go sources in that package, plus one for each assembly file.

Equivalently, there's one CompilationUnit per object file in each Library loaded by the linker.

These are used for both DWARF and pclntab generation.

type Library

type Library struct {
	Objref      string
	Srcref      string
	File        string
	Pkg         string
	Shlib       string
	Fingerprint goobj.FingerprintType
	Autolib     []goobj.ImportedPkg
	Imports     []*Library
	Main        bool
	Units       []*CompilationUnit

	Textp       []LoaderSym // text syms defined in this library
	DupTextSyms []LoaderSym // dupok text syms defined in this library
}

func (Library) String

func (l Library) String() string

type LoaderSym added in go1.15

type LoaderSym uint32

LoaderSym holds a loader.Sym value. We can't refer to this type from the sym package since loader imports sym.

type RelocVariant

type RelocVariant uint8

RelocVariant is a linker-internal variation on a relocation.

const (
	RV_NONE RelocVariant = iota
	RV_POWER_LO
	RV_POWER_HI
	RV_POWER_HA
	RV_POWER_DS

	// RV_390_DBL is a s390x-specific relocation variant that indicates that
	// the value to be placed into the relocatable field should first be
	// divided by 2.
	RV_390_DBL

	RV_CHECK_OVERFLOW RelocVariant = 1 << 7
	RV_TYPE_MASK      RelocVariant = RV_CHECK_OVERFLOW - 1
)

type Section

type Section struct {
	Rwx     uint8
	Extnum  int16
	Align   int32
	Name    string
	Vaddr   uint64
	Length  uint64
	Seg     *Segment
	Elfsect any // an *ld.ElfShdr
	Reloff  uint64
	Rellen  uint64
	// Relcount is the number of *host* relocations applied to this section
	// (when external linking).
	// Incremented atomically on multiple goroutines.
	// Note: this may differ from number of Go relocations, as one Go relocation
	// may turn into multiple host relocations.
	Relcount uint32
	Sym      LoaderSym // symbol for the section, if any
	Index    uint16    // each section has a unique index, used internally

	Compressed bool
}

type Segment

type Segment struct {
	Rwx      uint8  // permission as usual unix bits (5 = r-x etc)
	Vaddr    uint64 // virtual address
	Length   uint64 // length in memory
	Fileoff  uint64 // file offset
	Filelen  uint64 // length on disk
	Sections []*Section
}

type SymKind

type SymKind uint8

A SymKind describes the kind of memory represented by a symbol.

const (
	// An otherwise invalid zero value for the type.
	Sxxx SymKind = iota
	// The text segment, containing executable instructions.
	STEXT          // General executable code.
	STEXTFIPSSTART // Start of FIPS text section.
	STEXTFIPS      // Instructions hashed for FIPS checks.
	STEXTFIPSEND   // End of FIPS text section.
	STEXTEND       // End of text section.
	SELFRXSECT     // Executable PLT; PPC64 .glink.
	SMACHOPLT      // Mach-O PLT.

	// Read-only, non-executable, segment.
	STYPE            // Type descriptors.
	SSTRING          // Used only for XCOFF runtime.rodata symbol?
	SGOSTRING        // Go string constants.
	SGOFUNC          // Function descriptors and funcdata symbols.
	SGCBITS          // GC bit masks and programs.
	SRODATA          // General read-only data.
	SRODATAFIPSSTART // Start of FIPS read-only data.
	SRODATAFIPS      // FIPS read-only data.
	SRODATAFIPSEND   // End of FIPS read-only data.
	SRODATAEND       // End of read-only data.
	SFUNCTAB         // Appears to be unused, except for runtime.etypes.
	SPCLNTAB         // Pclntab data.
	SELFROSECT       // ELF read-only data: relocs, dynamic linking info.

	// Read-only, non-executable, dynamically relocatable segment.
	//
	// Types STYPE-SFUNCTAB above are written to the .rodata section by default.
	// When linking a shared object, some conceptually "read only" types need to
	// be written to by relocations and putting them in a section called
	// ".rodata" interacts poorly with the system linkers. The GNU linkers
	// support this situation by arranging for sections of the name
	// ".data.rel.ro.XXX" to be mprotected read only by the dynamic linker after
	// relocations have applied, so when the Go linker is creating a shared
	// object it checks all objects of the above types and bumps any object that
	// has a relocation to it to the corresponding type below, which are then
	// written to sections with appropriate magic names.
	STYPERELRO
	SSTRINGRELRO
	SGOSTRINGRELRO
	SGOFUNCRELRO
	SGCBITSRELRO
	SRODATARELRO
	SFUNCTABRELRO

	SELFRELROSECT   // ELF-specific read-only relocatable: PLT, etc.
	SMACHORELROSECT // Mach-O specific read-only relocatable.

	STYPELINK // Type links.
	SITABLINK // Itab links.

	// Allocated writable segment.
	SFirstWritable
	SBUILDINFO          // debug/buildinfo data (why is this writable?).
	SFIPSINFO           // go:fipsinfo aka crypto/internal/fips140/check.Linkinfo (why is this writable)?
	SELFSECT            // .got.plt, .plt, .dynamic where appropriate.
	SMACHO              // Used only for .llvmasm?
	SWINDOWS            // Windows dynamic symbols.
	SMODULEDATA         // Linker generated moduledata struct.
	SELFGOT             // Writable ELF GOT section.
	SMACHOGOT           // Mach-O GOT.
	SNOPTRDATA          // Data with no heap pointers.
	SNOPTRDATAFIPSSTART // Start of FIPS non-pointer writable data.
	SNOPTRDATAFIPS      // FIPS non-pointer writable data.
	SNOPTRDATAFIPSEND   // End of FIPS non-pointer writable data.
	SNOPTRDATAEND       // End of data with no heap pointers.
	SINITARR            // ELF .init_array section.
	SDATA               // Data that may have heap pointers.
	SDATAFIPSSTART      // Start of FIPS writable data.
	SDATAFIPS           // FIPS writable data.
	SDATAFIPSEND        // End of FIPS writable data.
	SDATAEND            // End of data that may have heap pointers.
	SXCOFFTOC           // AIX TOC entries.

	// Allocated zero-initialized segment.
	SBSS                    // Zeroed data that may have heap pointers.
	SNOPTRBSS               // Zeroed data with no heap pointers.
	SLIBFUZZER_8BIT_COUNTER // Fuzzer counters.
	SCOVERAGE_COUNTER       // Coverage counters.
	SCOVERAGE_AUXVAR        // Compiler generated coverage symbols.
	STLSBSS                 // Thread-local zeroed data.

	// Unallocated segment.
	SFirstUnallocated
	SXREF             // Reference from non-Go object file.
	SMACHOSYMSTR      // Mach-O string table.
	SMACHOSYMTAB      // Mach-O symbol table.
	SMACHOINDIRECTPLT // Mach-O indirect PLT.
	SMACHOINDIRECTGOT // Mach-O indirect GOT.
	SDYNIMPORT        // Reference to symbol defined in shared library.
	SHOSTOBJ          // Symbol defined in non-Go object file.
	SUNDEFEXT         // Undefined symbol for resolution by external linker.

	// Unallocated DWARF debugging segment.
	SDWARFSECT
	// DWARF symbol types created by compiler or linker.
	SDWARFCUINFO
	SDWARFCONST
	SDWARFFCN
	SDWARFABSFCN
	SDWARFTYPE
	SDWARFVAR
	SDWARFRANGE
	SDWARFLOC
	SDWARFLINES
	SDWARFADDR

	// SEH symbol types. These are probably allocated at run time.
	SSEHUNWINDINFO // Compiler generated Windows SEH info.
	SSEHSECT       // Windows SEH data.
)

Defined SymKind values.

TODO(rsc): Give idiomatic Go names.

func (SymKind) IsDATA added in go1.24.0

func (t SymKind) IsDATA() bool

IsDATA returns true if t is one of the SDATA types.

func (SymKind) IsDWARF added in go1.22.0

func (t SymKind) IsDWARF() bool

func (SymKind) IsData added in go1.14

func (t SymKind) IsData() bool

IsData returns true if t is any kind of data type.

func (SymKind) IsNOPTRDATA added in go1.24.0

func (t SymKind) IsNOPTRDATA() bool

IsNOPTRDATA returns true if t is one of the SNOPTRDATA types.

func (SymKind) IsRODATA added in go1.24.0

func (t SymKind) IsRODATA() bool

IsRODATA returns true if t is one of the SRODATA types.

func (SymKind) IsText added in go1.24.0

func (t SymKind) IsText() bool

IsText returns true if t is a text type.

func (SymKind) String

func (i SymKind) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL