1
2
3
4
5 package objabi
6
7 import "sync"
8
9
10
11 type PkgSpecial struct {
12
13
14
15
16
17
18
19
20
21
22
23
24
25 Runtime bool
26
27
28
29
30
31 NoInstrument bool
32
33
34
35
36 NoRaceFunc bool
37
38
39
40
41
42 AllowAsmABI bool
43 }
44
45 var runtimePkgs = []string{
46
47
48
49 "runtime",
50
51 "internal/runtime/atomic",
52 "internal/runtime/cgroup",
53 "internal/runtime/exithook",
54 "internal/runtime/gc",
55 "internal/runtime/maps",
56 "internal/runtime/math",
57 "internal/runtime/strconv",
58 "internal/runtime/sys",
59 "internal/runtime/syscall",
60
61 "internal/abi",
62 "internal/bytealg",
63 "internal/byteorder",
64 "internal/chacha8rand",
65 "internal/coverage/rtcov",
66 "internal/cpu",
67 "internal/goarch",
68 "internal/godebugs",
69 "internal/goexperiment",
70 "internal/goos",
71 "internal/profilerecord",
72 "internal/stringslite",
73 }
74
75
76
77 var extraNoInstrumentPkgs = []string{
78 "runtime/race",
79 "runtime/msan",
80 "runtime/asan",
81
82
83
84
85
86 "-internal/bytealg",
87 }
88
89 var noRaceFuncPkgs = []string{"sync", "sync/atomic", "internal/sync", "internal/runtime/atomic"}
90
91 var allowAsmABIPkgs = []string{
92 "runtime",
93 "reflect",
94 "syscall",
95 "internal/bytealg",
96 "internal/chacha8rand",
97 "internal/runtime/syscall",
98 "internal/runtime/startlinetest",
99 }
100
101
102 func LookupPkgSpecial(pkgPath string) PkgSpecial {
103 return pkgSpecialsOnce()[pkgPath]
104 }
105
106 var pkgSpecialsOnce = sync.OnceValue(func() map[string]PkgSpecial {
107
108
109
110 pkgSpecials := make(map[string]PkgSpecial)
111 set := func(elt string, f func(*PkgSpecial)) {
112 s := pkgSpecials[elt]
113 f(&s)
114 pkgSpecials[elt] = s
115 }
116 for _, pkg := range runtimePkgs {
117 set(pkg, func(ps *PkgSpecial) { ps.Runtime = true; ps.NoInstrument = true })
118 }
119 for _, pkg := range extraNoInstrumentPkgs {
120 if pkg[0] == '-' {
121 set(pkg[1:], func(ps *PkgSpecial) { ps.NoInstrument = false })
122 } else {
123 set(pkg, func(ps *PkgSpecial) { ps.NoInstrument = true })
124 }
125 }
126 for _, pkg := range noRaceFuncPkgs {
127 set(pkg, func(ps *PkgSpecial) { ps.NoRaceFunc = true })
128 }
129 for _, pkg := range allowAsmABIPkgs {
130 set(pkg, func(ps *PkgSpecial) { ps.AllowAsmABI = true })
131 }
132 return pkgSpecials
133 })
134
View as plain text