Skip to content

Commit 265b5fd

Browse files
Bryan Millsgopherbot
Bryan Mills
authored andcommitted
Revert "cmd/compile: enable Asan check for global variables"
This reverts CL 401775. Reason for revert: broke build. Change-Id: I4f6f2edff1e4afcf31cd90e26dacf303979eb10c Reviewed-on: https://go-review.googlesource.com/c/go/+/403981 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent f52b4ec commit 265b5fd

File tree

18 files changed

+15
-509
lines changed

18 files changed

+15
-509
lines changed

misc/cgo/testsanitizers/asan_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ func TestASAN(t *testing.T) {
2222
if !aSanSupported(goos, goarch) {
2323
t.Skipf("skipping on %s/%s; -asan option is not supported.", goos, goarch)
2424
}
25-
// The current implementation is only compatible with the ASan library from version
26-
// v7 to v9 (See the description in src/runtime/asan/asan.go). Therefore, using the
27-
// -asan option must use a compatible version of ASan library, which requires that
28-
// the gcc version is not less than 7 and the clang version is not less than 9,
29-
// otherwise a segmentation fault will occur.
30-
if !compilerRequiredAsanVersion() {
31-
t.Skipf("skipping: too old version of compiler")
32-
}
3325

3426
t.Parallel()
3527
requireOvercommit(t)

misc/cgo/testsanitizers/cc_test.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,17 @@ func compilerVersion() (version, error) {
184184
var match [][]byte
185185
if bytes.HasPrefix(out, []byte("gcc")) {
186186
compiler.name = "gcc"
187-
cmd, err := cc("-v")
187+
188+
cmd, err := cc("-dumpversion")
188189
if err != nil {
189190
return err
190191
}
191-
out, err := cmd.CombinedOutput()
192+
out, err := cmd.Output()
192193
if err != nil {
193-
// gcc, but does not support gcc's "-v" flag?!
194+
// gcc, but does not support gcc's "-dumpversion" flag?!
194195
return err
195196
}
196-
gccRE := regexp.MustCompile(`gcc version (\d+)\.(\d+)`)
197+
gccRE := regexp.MustCompile(`(\d+)\.(\d+)`)
197198
match = gccRE.FindSubmatch(out)
198199
} else {
199200
clangRE := regexp.MustCompile(`clang version (\d+)\.(\d+)`)
@@ -234,22 +235,6 @@ func compilerSupportsLocation() bool {
234235
}
235236
}
236237

237-
// compilerRequiredAsanVersion reports whether the compiler is the version required by Asan.
238-
func compilerRequiredAsanVersion() bool {
239-
compiler, err := compilerVersion()
240-
if err != nil {
241-
return false
242-
}
243-
switch compiler.name {
244-
case "gcc":
245-
return compiler.major >= 7
246-
case "clang":
247-
return compiler.major >= 9
248-
default:
249-
return false
250-
}
251-
}
252-
253238
type compilerCheck struct {
254239
once sync.Once
255240
err error

src/cmd/compile/internal/base/base.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ var NoInstrumentPkgs = []string{
7070
"runtime/msan",
7171
"runtime/asan",
7272
"internal/cpu",
73-
"buildcfg",
7473
}
7574

7675
// Don't insert racefuncenter/racefuncexit into the following packages.

src/cmd/compile/internal/gc/obj.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"cmd/compile/internal/ir"
1010
"cmd/compile/internal/noder"
1111
"cmd/compile/internal/objw"
12-
"cmd/compile/internal/pkginit"
1312
"cmd/compile/internal/reflectdata"
1413
"cmd/compile/internal/staticdata"
1514
"cmd/compile/internal/typecheck"
@@ -111,6 +110,7 @@ func dumpCompilerObj(bout *bio.Writer) {
111110
func dumpdata() {
112111
numExterns := len(typecheck.Target.Externs)
113112
numDecls := len(typecheck.Target.Decls)
113+
114114
dumpglobls(typecheck.Target.Externs)
115115
reflectdata.CollectPTabs()
116116
numExports := len(typecheck.Target.Exports)
@@ -287,20 +287,7 @@ func ggloblnod(nam *ir.Name) {
287287
if nam.Type() != nil && !nam.Type().HasPointers() {
288288
flags |= obj.NOPTR
289289
}
290-
size := nam.Type().Size()
291-
linkname := nam.Sym().Linkname
292-
name := nam.Sym().Name
293-
294-
// We've skipped linkname'd globals's instrument, so we can skip them here as well.
295-
if base.Flag.ASan && linkname == "" && pkginit.InstrumentGlobalsMap[name] != nil {
296-
// Write the new size of instrumented global variables that have
297-
// trailing redzones into object file.
298-
rzSize := pkginit.GetRedzoneSizeForGlobal(size)
299-
sizeWithRZ := rzSize + size
300-
base.Ctxt.Globl(s, sizeWithRZ, flags)
301-
} else {
302-
base.Ctxt.Globl(s, size, flags)
303-
}
290+
base.Ctxt.Globl(s, nam.Type().Size(), flags)
304291
if nam.LibfuzzerExtraCounter() {
305292
s.Type = objabi.SLIBFUZZER_EXTRA_COUNTER
306293
}

src/cmd/compile/internal/noder/noder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ func parseGoEmbed(args string) ([]string, error) {
442442
// the name, normally "pkg.init", is altered to "pkg.init.0".
443443
var renameinitgen int
444444

445-
func Renameinit() *types.Sym {
445+
func renameinit() *types.Sym {
446446
s := typecheck.LookupNum("init.", renameinitgen)
447447
renameinitgen++
448448
return s

src/cmd/compile/internal/noder/object.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (g *irgen) obj(obj types2.Object) *ir.Name {
104104
var typ *types.Type
105105
if recv := sig.Recv(); recv == nil {
106106
if obj.Name() == "init" {
107-
sym = Renameinit()
107+
sym = renameinit()
108108
} else {
109109
sym = g.sym(obj)
110110
}

src/cmd/compile/internal/noder/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
645645

646646
case pkgbits.ObjFunc:
647647
if sym.Name == "init" {
648-
sym = Renameinit()
648+
sym = renameinit()
649649
}
650650
name := do(ir.ONAME, true)
651651
setType(name, r.signature(sym.Pkg, nil))

src/cmd/compile/internal/pkginit/init.go

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package pkginit
77
import (
88
"cmd/compile/internal/base"
99
"cmd/compile/internal/ir"
10-
"cmd/compile/internal/noder"
1110
"cmd/compile/internal/objw"
1211
"cmd/compile/internal/staticinit"
1312
"cmd/compile/internal/typecheck"
@@ -84,58 +83,6 @@ func Task() *ir.Name {
8483
}
8584
deps = append(deps, n.(*ir.Name).Linksym())
8685
}
87-
if base.Flag.ASan {
88-
// Make an initialization function to call runtime.asanregisterglobals to register an
89-
// array of instrumented global variables when -asan is enabled. An instrumented global
90-
// variable is described by a structure.
91-
// See the _asan_global structure declared in src/runtime/asan/asan.go.
92-
//
93-
// func init {
94-
// var globals []_asan_global {...}
95-
// asanregisterglobals(&globals[0], len(globals))
96-
// }
97-
for _, n := range typecheck.Target.Externs {
98-
if canInstrumentGlobal(n) {
99-
name := n.Sym().Name
100-
InstrumentGlobalsMap[name] = n
101-
InstrumentGlobalsSlice = append(InstrumentGlobalsSlice, n)
102-
}
103-
}
104-
ni := len(InstrumentGlobalsMap)
105-
if ni != 0 {
106-
// Make an init._ function.
107-
base.Pos = base.AutogeneratedPos
108-
typecheck.DeclContext = ir.PEXTERN
109-
name := noder.Renameinit()
110-
fnInit := typecheck.DeclFunc(name, ir.NewFuncType(base.Pos, nil, nil, nil))
111-
112-
// Get an array of intrumented global variables.
113-
globals := instrumentGlobals(fnInit)
114-
115-
// Call runtime.asanregisterglobals function to poison redzones.
116-
// runtime.asanregisterglobals(unsafe.Pointer(&globals[0]), ni)
117-
asanf := typecheck.NewName(ir.Pkgs.Runtime.Lookup("asanregisterglobals"))
118-
ir.MarkFunc(asanf)
119-
asanf.SetType(types.NewSignature(types.NoPkg, nil, nil, []*types.Field{
120-
types.NewField(base.Pos, nil, types.Types[types.TUNSAFEPTR]),
121-
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
122-
}, nil))
123-
asancall := ir.NewCallExpr(base.Pos, ir.OCALL, asanf, nil)
124-
asancall.Args.Append(typecheck.ConvNop(typecheck.NodAddr(
125-
ir.NewIndexExpr(base.Pos, globals, ir.NewInt(0))), types.Types[types.TUNSAFEPTR]))
126-
asancall.Args.Append(typecheck.ConvNop(ir.NewInt(int64(ni)), types.Types[types.TUINTPTR]))
127-
128-
fnInit.Body.Append(asancall)
129-
typecheck.FinishFuncBody()
130-
typecheck.Func(fnInit)
131-
ir.CurFunc = fnInit
132-
typecheck.Stmts(fnInit.Body)
133-
ir.CurFunc = nil
134-
135-
typecheck.Target.Decls = append(typecheck.Target.Decls, fnInit)
136-
typecheck.Target.Inits = append(typecheck.Target.Inits, fnInit)
137-
}
138-
}
13986

14087
// Record user init functions.
14188
for _, fn := range typecheck.Target.Inits {

0 commit comments

Comments
 (0)