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