Skip to content

Commit 9e81099

Browse files
Archana Rlaboger
Archana R
authored andcommitted
runtime: add address sanitizer support for ppc64le
updates golang#44853 Change-Id: I71905ee1bcb99ce7300bbed2daad3617d2643c53 Reviewed-on: https://go-review.googlesource.com/c/go/+/408814 Reviewed-by: Lynn Boger <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Benny Siegert <[email protected]> Reviewed-by: David Chase <[email protected]> Run-TryBot: Archana Ravindar <[email protected]>
1 parent 62125c9 commit 9e81099

File tree

5 files changed

+91
-4
lines changed

5 files changed

+91
-4
lines changed

misc/cgo/testsanitizers/cc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ func mSanSupported(goos, goarch string) bool {
527527
func aSanSupported(goos, goarch string) bool {
528528
switch goos {
529529
case "linux":
530-
return goarch == "amd64" || goarch == "arm64" || goarch == "riscv64"
530+
return goarch == "amd64" || goarch == "arm64" || goarch == "riscv64" || goarch == "ppc64le"
531531
default:
532532
return false
533533
}

src/cmd/dist/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ func (t *tester) registerTests() {
836836
if t.supportedBuildmode("plugin") {
837837
t.registerTest("testplugin", "../misc/cgo/testplugin", t.goTest(), t.timeout(600), ".")
838838
}
839-
if gohostos == "linux" && goarch == "amd64" {
839+
if gohostos == "linux" && (goarch == "amd64" || goarch == "ppc64le") {
840840
t.registerTest("testasan", "../misc/cgo/testasan", "go", "run", ".")
841841
}
842842
if goos == "linux" {

src/cmd/internal/sys/supported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func MSanSupported(goos, goarch string) bool {
4040
func ASanSupported(goos, goarch string) bool {
4141
switch goos {
4242
case "linux":
43-
return goarch == "arm64" || goarch == "amd64" || goarch == "riscv64"
43+
return goarch == "arm64" || goarch == "amd64" || goarch == "riscv64" || goarch == "ppc64le"
4444
default:
4545
return false
4646
}

src/runtime/asan/asan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build asan && linux && (arm64 || amd64 || riscv64)
5+
//go:build asan && linux && (arm64 || amd64 || riscv64 || ppc64le)
66

77
package asan
88

src/runtime/asan_ppc64le.s

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build asan
6+
7+
#include "go_asm.h"
8+
#include "textflag.h"
9+
10+
#define RARG0 R3
11+
#define RARG1 R4
12+
#define RARG2 R5
13+
#define RARG3 R6
14+
#define FARG R12
15+
16+
// Called from instrumented code.
17+
// func runtime·doasanread(addr unsafe.Pointer, sz, sp, pc uintptr)
18+
TEXT runtime·doasanread(SB),NOSPLIT|NOFRAME,$0-32
19+
MOVD addr+0(FP), RARG0
20+
MOVD sz+8(FP), RARG1
21+
MOVD sp+16(FP), RARG2
22+
MOVD pc+24(FP), RARG3
23+
// void __asan_read_go(void *addr, uintptr_t sz, void *sp, void *pc);
24+
MOVD $__asan_read_go(SB), FARG
25+
BR asancall<>(SB)
26+
27+
// func runtime·doasanwrite(addr unsafe.Pointer, sz, sp, pc uintptr)
28+
TEXT runtime·doasanwrite(SB),NOSPLIT|NOFRAME,$0-32
29+
MOVD addr+0(FP), RARG0
30+
MOVD sz+8(FP), RARG1
31+
MOVD sp+16(FP), RARG2
32+
MOVD pc+24(FP), RARG3
33+
// void __asan_write_go(void *addr, uintptr_t sz, void *sp, void *pc);
34+
MOVD $__asan_write_go(SB), FARG
35+
BR asancall<>(SB)
36+
37+
// func runtime·asanunpoison(addr unsafe.Pointer, sz uintptr)
38+
TEXT runtime·asanunpoison(SB),NOSPLIT|NOFRAME,$0-16
39+
MOVD addr+0(FP), RARG0
40+
MOVD sz+8(FP), RARG1
41+
// void __asan_unpoison_go(void *addr, uintptr_t sz);
42+
MOVD $__asan_unpoison_go(SB), FARG
43+
BR asancall<>(SB)
44+
45+
// func runtime·asanpoison(addr unsafe.Pointer, sz uintptr)
46+
TEXT runtime·asanpoison(SB),NOSPLIT|NOFRAME,$0-16
47+
MOVD addr+0(FP), RARG0
48+
MOVD sz+8(FP), RARG1
49+
// void __asan_poison_go(void *addr, uintptr_t sz);
50+
MOVD $__asan_poison_go(SB), FARG
51+
BR asancall<>(SB)
52+
53+
// func runtime·asanregisterglobals(addr unsafe.Pointer, n uintptr)
54+
TEXT runtime·asanregisterglobals(SB),NOSPLIT|NOFRAME,$0-16
55+
MOVD addr+0(FP), RARG0
56+
MOVD n+8(FP), RARG1
57+
// void __asan_register_globals_go(void *addr, uintptr_t n);
58+
MOVD $__asan_register_globals_go(SB), FARG
59+
BR asancall<>(SB)
60+
61+
// Switches SP to g0 stack and calls (FARG). Arguments already set.
62+
TEXT asancall<>(SB), NOSPLIT, $0-0
63+
// LR saved in generated prologue
64+
// Get info from the current goroutine
65+
MOVD runtime·tls_g(SB), R10 // g offset in TLS
66+
MOVD 0(R10), g
67+
MOVD g_m(g), R7 // m for g
68+
MOVD R1, R16 // callee-saved, preserved across C call
69+
MOVD m_g0(R7), R10 // g0 for m
70+
CMP R10, g // same g0?
71+
BEQ call // already on g0
72+
MOVD (g_sched+gobuf_sp)(R10), R1 // switch R1
73+
call:
74+
// prepare frame for C ABI
75+
SUB $32, R1 // create frame for callee saving LR, CR, R2 etc.
76+
RLDCR $0, R1, $~15, R1 // align SP to 16 bytes
77+
MOVD FARG, CTR // address of function to be called
78+
MOVD R0, 0(R1) // clear back chain pointer
79+
BL (CTR)
80+
MOVD $0, R0 // C code can clobber R0 set it back to 0
81+
MOVD R16, R1 // restore R1;
82+
MOVD runtime·tls_g(SB), R10 // find correct g
83+
MOVD 0(R10), g
84+
RET
85+
86+
// tls_g, g value for each thread in TLS
87+
GLOBL runtime·tls_g+0(SB), TLSBSS+DUPOK, $8

0 commit comments

Comments
 (0)