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