]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: add address sanitizer support for ppc64le
authorArchana R <aravind5@in.ibm.com>
Thu, 26 May 2022 10:24:38 +0000 (05:24 -0500)
committerLynn Boger <laboger@linux.vnet.ibm.com>
Fri, 26 Aug 2022 18:13:33 +0000 (18:13 +0000)
updates #44853

Change-Id: I71905ee1bcb99ce7300bbed2daad3617d2643c53
Reviewed-on: https://go-review.googlesource.com/c/go/+/408814
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Archana Ravindar <aravind5@in.ibm.com>

misc/cgo/testsanitizers/cc_test.go
src/cmd/dist/test.go
src/cmd/internal/sys/supported.go
src/runtime/asan/asan.go
src/runtime/asan_ppc64le.s [new file with mode: 0644]

index 664083f570e7e40292ceff614c5d3429a1e7847d..72af42660d3a6b7283fedaaf66d2e3159a297c0a 100644 (file)
@@ -527,7 +527,7 @@ func mSanSupported(goos, goarch string) bool {
 func aSanSupported(goos, goarch string) bool {
        switch goos {
        case "linux":
-               return goarch == "amd64" || goarch == "arm64" || goarch == "riscv64"
+               return goarch == "amd64" || goarch == "arm64" || goarch == "riscv64" || goarch == "ppc64le"
        default:
                return false
        }
index 759377ffa54568556485ab16e32c18dfe27529b2..6372054929e56b1182e54a946b018c80f578c9ed 100644 (file)
@@ -836,7 +836,7 @@ func (t *tester) registerTests() {
                if t.supportedBuildmode("plugin") {
                        t.registerTest("testplugin", "../misc/cgo/testplugin", t.goTest(), t.timeout(600), ".")
                }
-               if gohostos == "linux" && goarch == "amd64" {
+               if gohostos == "linux" && (goarch == "amd64" || goarch == "ppc64le") {
                        t.registerTest("testasan", "../misc/cgo/testasan", "go", "run", ".")
                }
                if goos == "linux" {
index 1d74f6b5e691f57a420c21799c224b3c008ab4dd..ee98d0548e659c859a4d76d2e61fa529dcf7ef35 100644 (file)
@@ -40,7 +40,7 @@ func MSanSupported(goos, goarch string) bool {
 func ASanSupported(goos, goarch string) bool {
        switch goos {
        case "linux":
-               return goarch == "arm64" || goarch == "amd64" || goarch == "riscv64"
+               return goarch == "arm64" || goarch == "amd64" || goarch == "riscv64" || goarch == "ppc64le"
        default:
                return false
        }
index 3b7c0511f5dcc6d7b3e207e17eaefe2c0c02851a..25f15ae45b6c7b45703e6bab38c5053702cdd875 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build asan && linux && (arm64 || amd64 || riscv64)
+//go:build asan && linux && (arm64 || amd64 || riscv64 || ppc64le)
 
 package asan
 
diff --git a/src/runtime/asan_ppc64le.s b/src/runtime/asan_ppc64le.s
new file mode 100644 (file)
index 0000000..d13301a
--- /dev/null
@@ -0,0 +1,87 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build asan
+
+#include "go_asm.h"
+#include "textflag.h"
+
+#define RARG0 R3
+#define RARG1 R4
+#define RARG2 R5
+#define RARG3 R6
+#define FARG R12
+
+// Called from instrumented code.
+// func runtime·doasanread(addr unsafe.Pointer, sz, sp, pc uintptr)
+TEXT   runtime·doasanread(SB),NOSPLIT|NOFRAME,$0-32
+       MOVD    addr+0(FP), RARG0
+       MOVD    sz+8(FP), RARG1
+       MOVD    sp+16(FP), RARG2
+       MOVD    pc+24(FP), RARG3
+       // void __asan_read_go(void *addr, uintptr_t sz, void *sp, void *pc);
+       MOVD    $__asan_read_go(SB), FARG
+       BR      asancall<>(SB)
+
+// func runtime·doasanwrite(addr unsafe.Pointer, sz, sp, pc uintptr)
+TEXT   runtime·doasanwrite(SB),NOSPLIT|NOFRAME,$0-32
+       MOVD    addr+0(FP), RARG0
+       MOVD    sz+8(FP), RARG1
+       MOVD    sp+16(FP), RARG2
+       MOVD    pc+24(FP), RARG3
+       // void __asan_write_go(void *addr, uintptr_t sz, void *sp, void *pc);
+       MOVD    $__asan_write_go(SB), FARG
+       BR      asancall<>(SB)
+
+// func runtime·asanunpoison(addr unsafe.Pointer, sz uintptr)
+TEXT   runtime·asanunpoison(SB),NOSPLIT|NOFRAME,$0-16
+       MOVD    addr+0(FP), RARG0
+       MOVD    sz+8(FP), RARG1
+       // void __asan_unpoison_go(void *addr, uintptr_t sz);
+       MOVD    $__asan_unpoison_go(SB), FARG
+       BR      asancall<>(SB)
+
+// func runtime·asanpoison(addr unsafe.Pointer, sz uintptr)
+TEXT   runtime·asanpoison(SB),NOSPLIT|NOFRAME,$0-16
+       MOVD    addr+0(FP), RARG0
+       MOVD    sz+8(FP), RARG1
+       // void __asan_poison_go(void *addr, uintptr_t sz);
+       MOVD    $__asan_poison_go(SB), FARG
+       BR      asancall<>(SB)
+
+// func runtime·asanregisterglobals(addr unsafe.Pointer, n uintptr)
+TEXT   runtime·asanregisterglobals(SB),NOSPLIT|NOFRAME,$0-16
+       MOVD    addr+0(FP), RARG0
+       MOVD    n+8(FP), RARG1
+       // void __asan_register_globals_go(void *addr, uintptr_t n);
+       MOVD    $__asan_register_globals_go(SB), FARG
+       BR      asancall<>(SB)
+
+// Switches SP to g0 stack and calls (FARG). Arguments already set.
+TEXT   asancall<>(SB), NOSPLIT, $0-0
+       // LR saved in generated prologue
+       // Get info from the current goroutine
+       MOVD    runtime·tls_g(SB), R10  // g offset in TLS
+       MOVD    0(R10), g
+       MOVD    g_m(g), R7              // m for g
+       MOVD    R1, R16                 // callee-saved, preserved across C call
+       MOVD    m_g0(R7), R10           // g0 for m
+       CMP     R10, g                  // same g0?
+       BEQ     call                    // already on g0
+       MOVD    (g_sched+gobuf_sp)(R10), R1 // switch R1
+call:
+       // prepare frame for C ABI
+       SUB     $32, R1                 // create frame for callee saving LR, CR, R2 etc.
+       RLDCR   $0, R1, $~15, R1        // align SP to 16 bytes
+       MOVD    FARG, CTR               // address of function to be called
+       MOVD    R0, 0(R1)               // clear back chain pointer
+       BL      (CTR)
+       MOVD    $0, R0                  // C code can clobber R0 set it back to 0
+       MOVD    R16, R1                 // restore R1;
+       MOVD    runtime·tls_g(SB), R10 // find correct g
+       MOVD    0(R10), g
+       RET
+
+// tls_g, g value for each thread in TLS
+GLOBL runtime·tls_g+0(SB), TLSBSS+DUPOK, $8