]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: enable Asan check for global variables
authorfanzha02 <fannie.zhang@arm.com>
Thu, 29 Apr 2021 09:02:53 +0000 (17:02 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 4 May 2022 18:51:19 +0000 (18:51 +0000)
commit1b0f9fbb67ad3708665675c9f600608dc9b375fa
tree92687137a60fa7674580caffd945afef753ba493
parentc570f0eda2c6d250c58028eb9d1e45061f607b67
cmd/compile: enable Asan check for global variables

With this patch, -asan option can detect the error memory
access to global variables.

So this patch makes a few changes:

1. Add the asanregisterglobals runtime support function,
which calls asan runtime function _asan_register_globals
to register global variables.

2. Create a new initialization function for the package
being compiled. This function initializes an array of
instrumented global variables and pass it to function
runtime.asanregisterglobals. An instrumented global
variable has trailing redzone.

3. Writes the new size of instrumented global variables
that have trailing redzones into object file.

4. Notice that the current implementation is only compatible with
the ASan library from version v7 to v9. Therefore, using the
-asan option requires that the gcc version is not less than 7
and the clang version is less than 4, otherwise a segmentation
fault will occur. So this patch adds a check on whether the compiler
being used is a supported version in cmd/go.

(This is a redo of CL 401775 with a fix for a build break due to an
intervening commit that removed the internal/execabs package.)

Updates #44853.

Change-Id: I719d4ef2b22cb2d5516e1494cd453c3efb47d6c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/403851
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
18 files changed:
misc/cgo/testsanitizers/asan_test.go
misc/cgo/testsanitizers/cc_test.go
src/cmd/compile/internal/base/base.go
src/cmd/compile/internal/gc/obj.go
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/noder/object.go
src/cmd/compile/internal/noder/reader.go
src/cmd/compile/internal/pkginit/init.go
src/cmd/compile/internal/pkginit/initAsanGlobals.go [new file with mode: 0644]
src/cmd/go/alldocs.go
src/cmd/go/internal/work/build.go
src/cmd/go/internal/work/init.go
src/cmd/go/testdata/script/install_msan_and_race_and_asan_require_cgo.txt [moved from src/cmd/go/testdata/script/install_msan_and_race_require_cgo.txt with 63% similarity]
src/runtime/asan.go
src/runtime/asan/asan.go
src/runtime/asan0.go
src/runtime/asan_amd64.s
src/runtime/asan_arm64.s