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