mirror of
https://github.com/golang/go
synced 2024-11-19 01:14:39 -07:00
runtime, cmd/go: enable address sanitizer on linux/loong64
The recently released llvm-16/LoongArch already supports the asan feature; but gcc13/LoongArch does not yet fully support the asan feature, and asan will be fully supported in gcc14. Change-Id: I48a65f2f10e3dc488acd9c02ea1a1f37de192be0 Reviewed-on: https://go-review.googlesource.com/c/go/+/481317 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: abner chenc <chenguoqi@loongson.cn> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Meidan Li <limeidan@loongson.cn> TryBot-Result: Gopher Robot <gobot@golang.org> Commit-Queue: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
626a3cd9fa
commit
e9c14a7780
@ -293,11 +293,17 @@ func compilerRequiredAsanVersion(goos, goarch string) bool {
|
|||||||
}
|
}
|
||||||
switch compiler.name {
|
switch compiler.name {
|
||||||
case "gcc":
|
case "gcc":
|
||||||
|
if goarch == "loong64" {
|
||||||
|
return compiler.major >= 14
|
||||||
|
}
|
||||||
if goarch == "ppc64le" {
|
if goarch == "ppc64le" {
|
||||||
return compiler.major >= 9
|
return compiler.major >= 9
|
||||||
}
|
}
|
||||||
return compiler.major >= 7
|
return compiler.major >= 7
|
||||||
case "clang":
|
case "clang":
|
||||||
|
if goarch == "loong64" {
|
||||||
|
return compiler.major >= 16
|
||||||
|
}
|
||||||
return compiler.major >= 9
|
return compiler.major >= 9
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
|
@ -122,9 +122,10 @@
|
|||||||
// PIE build mode will be used on all platforms except linux/amd64.
|
// PIE build mode will be used on all platforms except linux/amd64.
|
||||||
// -asan
|
// -asan
|
||||||
// enable interoperation with address sanitizer.
|
// enable interoperation with address sanitizer.
|
||||||
// Supported only on linux/arm64, linux/amd64.
|
// Supported only on linux/arm64, linux/amd64, linux/loong64.
|
||||||
// Supported only on linux/amd64 or linux/arm64 and only with GCC 7 and higher
|
// Supported on linux/amd64 or linux/arm64 and only with GCC 7 and higher
|
||||||
// or Clang/LLVM 9 and higher.
|
// or Clang/LLVM 9 and higher.
|
||||||
|
// And supported on linux/loong64 only with Clang/LLVM 16 and higher.
|
||||||
// -cover
|
// -cover
|
||||||
// enable code coverage instrumentation.
|
// enable code coverage instrumentation.
|
||||||
// -covermode set,count,atomic
|
// -covermode set,count,atomic
|
||||||
|
@ -81,9 +81,10 @@ and test commands:
|
|||||||
PIE build mode will be used on all platforms except linux/amd64.
|
PIE build mode will be used on all platforms except linux/amd64.
|
||||||
-asan
|
-asan
|
||||||
enable interoperation with address sanitizer.
|
enable interoperation with address sanitizer.
|
||||||
Supported only on linux/arm64, linux/amd64.
|
Supported only on linux/arm64, linux/amd64, linux/loong64.
|
||||||
Supported only on linux/amd64 or linux/arm64 and only with GCC 7 and higher
|
Supported on linux/amd64 or linux/arm64 and only with GCC 7 and higher
|
||||||
or Clang/LLVM 9 and higher.
|
or Clang/LLVM 9 and higher.
|
||||||
|
And supported on linux/loong64 only with Clang/LLVM 16 and higher.
|
||||||
-cover
|
-cover
|
||||||
enable code coverage instrumentation.
|
enable code coverage instrumentation.
|
||||||
-covermode set,count,atomic
|
-covermode set,count,atomic
|
||||||
|
@ -51,7 +51,7 @@ func MSanSupported(goos, goarch string) bool {
|
|||||||
func ASanSupported(goos, goarch string) bool {
|
func ASanSupported(goos, goarch string) bool {
|
||||||
switch goos {
|
switch goos {
|
||||||
case "linux":
|
case "linux":
|
||||||
return goarch == "arm64" || goarch == "amd64" || goarch == "riscv64" || goarch == "ppc64le"
|
return goarch == "arm64" || goarch == "amd64" || goarch == "loong64" || goarch == "riscv64" || goarch == "ppc64le"
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build asan && linux && (arm64 || amd64 || riscv64 || ppc64le)
|
//go:build asan && linux && (arm64 || amd64 || loong64 || riscv64 || ppc64le)
|
||||||
|
|
||||||
package asan
|
package asan
|
||||||
|
|
||||||
|
75
src/runtime/asan_loong64.s
Normal file
75
src/runtime/asan_loong64.s
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
// Copyright 2023 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 R4
|
||||||
|
#define RARG1 R5
|
||||||
|
#define RARG2 R6
|
||||||
|
#define RARG3 R7
|
||||||
|
#define FARG R8
|
||||||
|
|
||||||
|
// Called from instrumented code.
|
||||||
|
// func runtime·doasanread(addr unsafe.Pointer, sz, sp, pc uintptr)
|
||||||
|
TEXT runtime·doasanread(SB), NOSPLIT, $0-32
|
||||||
|
MOVV addr+0(FP), RARG0
|
||||||
|
MOVV size+8(FP), RARG1
|
||||||
|
MOVV sp+16(FP), RARG2
|
||||||
|
MOVV pc+24(FP), RARG3
|
||||||
|
// void __asan_read_go(void *addr, uintptr_t sz, void *sp, void *pc);
|
||||||
|
MOVV $__asan_read_go(SB), FARG
|
||||||
|
JMP asancall<>(SB)
|
||||||
|
|
||||||
|
// func runtime·doasanwrite(addr unsafe.Pointer, sz, sp, pc uintptr)
|
||||||
|
TEXT runtime·doasanwrite(SB), NOSPLIT, $0-32
|
||||||
|
MOVV addr+0(FP), RARG0
|
||||||
|
MOVV size+8(FP), RARG1
|
||||||
|
MOVV sp+16(FP), RARG2
|
||||||
|
MOVV pc+24(FP), RARG3
|
||||||
|
// void __asan_write_go(void *addr, uintptr_t sz, void *sp, void *pc);
|
||||||
|
MOVV $__asan_write_go(SB), FARG
|
||||||
|
JMP asancall<>(SB)
|
||||||
|
|
||||||
|
// func runtime·asanunpoison(addr unsafe.Pointer, sz uintptr)
|
||||||
|
TEXT runtime·asanunpoison(SB), NOSPLIT, $0-16
|
||||||
|
MOVV addr+0(FP), RARG0
|
||||||
|
MOVV size+8(FP), RARG1
|
||||||
|
// void __asan_unpoison_go(void *addr, uintptr_t sz);
|
||||||
|
MOVV $__asan_unpoison_go(SB), FARG
|
||||||
|
JMP asancall<>(SB)
|
||||||
|
|
||||||
|
// func runtime·asanpoison(addr unsafe.Pointer, sz uintptr)
|
||||||
|
TEXT runtime·asanpoison(SB), NOSPLIT, $0-16
|
||||||
|
MOVV addr+0(FP), RARG0
|
||||||
|
MOVV size+8(FP), RARG1
|
||||||
|
// void __asan_poison_go(void *addr, uintptr_t sz);
|
||||||
|
MOVV $__asan_poison_go(SB), FARG
|
||||||
|
JMP asancall<>(SB)
|
||||||
|
|
||||||
|
// func runtime·asanregisterglobals(addr unsafe.Pointer, n uintptr)
|
||||||
|
TEXT runtime·asanregisterglobals(SB), NOSPLIT, $0-16
|
||||||
|
MOVV addr+0(FP), RARG0
|
||||||
|
MOVV size+8(FP), RARG1
|
||||||
|
// void __asan_register_globals_go(void *addr, uintptr_t n);
|
||||||
|
MOVV $__asan_register_globals_go(SB), FARG
|
||||||
|
JMP asancall<>(SB)
|
||||||
|
|
||||||
|
// Switches SP to g0 stack and calls (FARG). Arguments already set.
|
||||||
|
TEXT asancall<>(SB), NOSPLIT, $0-0
|
||||||
|
MOVV R3, R23 // callee-saved
|
||||||
|
BEQ g, g0stack // no g, still on a system stack
|
||||||
|
MOVV g_m(g), R14
|
||||||
|
MOVV m_g0(R14), R15
|
||||||
|
BEQ R15, g, g0stack
|
||||||
|
|
||||||
|
MOVV (g_sched+gobuf_sp)(R15), R9
|
||||||
|
MOVV R9, R3
|
||||||
|
|
||||||
|
g0stack:
|
||||||
|
JAL (FARG)
|
||||||
|
MOVV R23, R3
|
||||||
|
RET
|
Loading…
Reference in New Issue
Block a user