Debian Codegraph @

src/internal/abi/symtab.go

raw
1 // Copyright 2023 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 abi
6
7 // PCLnTabMagic is the version at the start of the PC/line table.
8 // This is the start of the .pclntab section, and is also runtime.pcHeader.
9 // The magic numbers are chosen such that reading the value with
10 // a different endianness does not result in the same value.
11 // That lets us the magic number to determine the endianness.
12 type PCLnTabMagic uint32
13
14 const (
15 // Initial PCLnTabMagic value used in Go 1.2 through Go 1.15.
16 Go12PCLnTabMagic PCLnTabMagic = 0xfffffffb
17 // PCLnTabMagic value used in Go 1.16 through Go 1.17.
18 // Several fields added to header (CL 241598).
19 Go116PCLnTabMagic PCLnTabMagic = 0xfffffffa
20 // PCLnTabMagic value used in Go 1.18 through Go 1.19.
21 // Entry PC of func data changed from address to offset (CL 351463).
22 Go118PCLnTabMagic PCLnTabMagic = 0xfffffff0
23 // PCLnTabMagic value used in Go 1.20 and later.
24 // A ":" was added to generated symbol names (#37762).
25 Go120PCLnTabMagic PCLnTabMagic = 0xfffffff1
26
27 // CurrentPCLnTabMagic is the value emitted by the current toolchain.
28 // This is written by the linker to the pcHeader and read by the
29 // runtime and debug/gosym (and external tools like Delve).
30 //
31 // Change this value when updating the pclntab version.
32 // Changing this exported value is OK because is an
33 // internal package.
34 CurrentPCLnTabMagic = Go120PCLnTabMagic
35 )
36
37 // A FuncFlag records bits about a function, passed to the runtime.
38 type FuncFlag uint8
39
40 const (
41 // FuncFlagTopFrame indicates a function that appears at the top of its stack.
42 // The traceback routine stop at such a function and consider that a
43 // successful, complete traversal of the stack.
44 // Examples of TopFrame functions include goexit, which appears
45 // at the top of a user goroutine stack, and mstart, which appears
46 // at the top of a system goroutine stack.
47 FuncFlagTopFrame FuncFlag = 1 << iota
48
49 // FuncFlagSPWrite indicates a function that writes an arbitrary value to SP
50 // (any write other than adding or subtracting a constant amount).
51 // The traceback routines cannot encode such changes into the
52 // pcsp tables, so the function traceback cannot safely unwind past
53 // SPWrite functions. Stopping at an SPWrite function is considered
54 // to be an incomplete unwinding of the stack. In certain contexts
55 // (in particular garbage collector stack scans) that is a fatal error.
56 FuncFlagSPWrite
57
58 // FuncFlagAsm indicates that a function was implemented in assembly.
59 FuncFlagAsm
60 )
61
62 // A FuncID identifies particular functions that need to be treated
63 // specially by the runtime.
64 // Note that in some situations involving plugins, there may be multiple
65 // copies of a particular special runtime function.
66 type FuncID uint8
67
68 const (
69 // If you add a FuncID, you probably also want to add an entry to the map in
70 // ../../cmd/internal/objabi/funcid.go
71
72 FuncIDNormal FuncID = iota // not a special function
73 FuncID_abort
74 FuncID_asmcgocall
75 FuncID_asyncPreempt
76 FuncID_cgocallback
77 FuncID_corostart
78 FuncID_debugCallV2
79 FuncID_gcBgMarkWorker
80 FuncID_goexit
81 FuncID_gogo
82 FuncID_gopanic
83 FuncID_handleAsyncEvent
84 FuncID_mcall
85 FuncID_morestack
86 FuncID_mstart
87 FuncID_panicwrap
88 FuncID_rt0_go
89 FuncID_runtime_main
90 FuncID_runFinalizers
91 FuncID_runCleanups
92 FuncID_sigpanic
93 FuncID_systemstack
94 FuncID_systemstack_switch
95 FuncIDWrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.)
96 )
97
98 // ArgsSizeUnknown is set in Func.argsize to mark all functions
99 // whose argument size is unknown (C vararg functions, and
100 // assembly code without an explicit specification).
101 // This value is generated by the compiler, assembler, or linker.
102 const ArgsSizeUnknown = -0x80000000
103
104 // IDs for PCDATA and FUNCDATA tables in Go binaries.
105 //
106 // These must agree with ../../../runtime/funcdata.h.
107 const (
108 PCDATA_UnsafePoint = 0
109 PCDATA_StackMapIndex = 1
110 PCDATA_InlTreeIndex = 2
111 PCDATA_ArgLiveIndex = 3
112 PCDATA_PanicBounds = 4
113
114 FUNCDATA_ArgsPointerMaps = 0
115 FUNCDATA_LocalsPointerMaps = 1
116 FUNCDATA_StackObjects = 2
117 FUNCDATA_InlTree = 3
118 FUNCDATA_OpenCodedDeferInfo = 4
119 FUNCDATA_ArgInfo = 5
120 FUNCDATA_ArgLiveInfo = 6
121 FUNCDATA_WrapInfo = 7
122 )
123
124 // Special values for the PCDATA_UnsafePoint table.
125 const (
126 UnsafePointSafe = -1 // Safe for async preemption
127 UnsafePointUnsafe = -2 // Unsafe for async preemption
128
129 // UnsafePointRestart1(2) apply on a sequence of instructions, within
130 // which if an async preemption happens, we should back off the PC
131 // to the start of the sequence when resuming.
132 // We need two so we can distinguish the start/end of the sequence
133 // in case that two sequences are next to each other.
134 UnsafePointRestart1 = -3
135 UnsafePointRestart2 = -4
136
137 // Like UnsafePointRestart1, but back to function entry if async preempted.
138 UnsafePointRestartAtEntry = -5
139 )
140
141 const MINFUNC = 16 // minimum size for a function
142
143 const FuncTabBucketSize = 256 * MINFUNC // size of bucket in the pc->func lookup table