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