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/gc/scan",
56 "internal/runtime/maps",
57 "internal/runtime/math",
58 "internal/runtime/strconv",
59 "internal/runtime/sys",
60 "internal/runtime/syscall/linux",
61 "internal/runtime/syscall/windows",
62
63 "internal/abi",
64 "internal/bytealg",
65 "internal/byteorder",
66 "internal/chacha8rand",
67 "internal/coverage/rtcov",
68 "internal/cpu",
69 "internal/goarch",
70 "internal/godebugs",
71 "internal/goexperiment",
72 "internal/goos",
73 "internal/profilerecord",
74 "internal/stringslite",
75 }
76
77
78
79 var extraNoInstrumentPkgs = []string{
80 "runtime/race",
81 "runtime/msan",
82 "runtime/asan",
83
84
85
86
87
88 "-internal/bytealg",
89 }
90
91 var noRaceFuncPkgs = []string{"sync", "sync/atomic", "internal/sync", "internal/runtime/atomic"}
92
93 var allowAsmABIPkgs = []string{
94 "runtime",
95 "reflect",
96 "syscall",
97 "internal/bytealg",
98 "internal/chacha8rand",
99 "internal/runtime/syscall/linux",
100 "internal/runtime/syscall/windows",
101 "internal/runtime/startlinetest",
102 }
103
104
105 func LookupPkgSpecial(pkgPath string) PkgSpecial {
106 return pkgSpecialsOnce()[pkgPath]
107 }
108
109 var pkgSpecialsOnce = sync.OnceValue(func() map[string]PkgSpecial {
110
111
112
113 pkgSpecials := make(map[string]PkgSpecial)
114 set := func(elt string, f func(*PkgSpecial)) {
115 s := pkgSpecials[elt]
116 f(&s)
117 pkgSpecials[elt] = s
118 }
119 for _, pkg := range runtimePkgs {
120 set(pkg, func(ps *PkgSpecial) { ps.Runtime = true; ps.NoInstrument = true })
121 }
122 for _, pkg := range extraNoInstrumentPkgs {
123 if pkg[0] == '-' {
124 set(pkg[1:], func(ps *PkgSpecial) { ps.NoInstrument = false })
125 } else {
126 set(pkg, func(ps *PkgSpecial) { ps.NoInstrument = true })
127 }
128 }
129 for _, pkg := range noRaceFuncPkgs {
130 set(pkg, func(ps *PkgSpecial) { ps.NoRaceFunc = true })
131 }
132 for _, pkg := range allowAsmABIPkgs {
133 set(pkg, func(ps *PkgSpecial) { ps.AllowAsmABI = true })
134 }
135 return pkgSpecials
136 })
137
View as plain text