1
0
mirror of https://github.com/golang/go synced 2024-09-29 20:14:29 -06:00

cmd/link: add -asan option

The -asan option causes the linker to link against the runtime/asan
package in order to use the C/C++ address sanitizer.

This CL passes tests but is not usable by itself.  The actual
runtime/asan package, and support for -asan in the go tool and the
compiler, and tests, are in separate CLs.

Updates #44853.

Change-Id: Ifc6046c1f75ba52777cbb3d937a4b66e91d5798d
Reviewed-on: https://go-review.googlesource.com/c/go/+/298610
Trust: fannie zhang <Fannie.Zhang@arm.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
fanzha02 2021-01-04 16:23:01 +08:00 committed by Ian Lance Taylor
parent 5d414d180b
commit ae4d67c89d
4 changed files with 14 additions and 0 deletions

View File

@ -45,6 +45,8 @@ Flags:
Note that before Go 1.5 this option took two separate arguments.
-a
Disassemble output.
-asan
Link with C/C++ address sanitizer support.
-buildid id
Record id as Go toolchain build id.
-buildmode mode

View File

@ -193,6 +193,10 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
return true, "msan"
}
if *flagAsan {
return true, "asan"
}
// Internally linking cgo is incomplete on some architectures.
// https://golang.org/issue/14449
if iscgo && ctxt.Arch.InFamily(sys.MIPS64, sys.MIPS, sys.RISCV64) {

View File

@ -385,6 +385,9 @@ func libinit(ctxt *Link) {
} else if *flagMsan {
suffixsep = "_"
suffix = "msan"
} else if *flagAsan {
suffixsep = "_"
suffix = "asan"
}
Lflag(ctxt, filepath.Join(buildcfg.GOROOT, "pkg", fmt.Sprintf("%s_%s%s%s", buildcfg.GOOS, buildcfg.GOARCH, suffixsep, suffix)))
@ -529,6 +532,9 @@ func (ctxt *Link) loadlib() {
if *flagMsan {
loadinternal(ctxt, "runtime/msan")
}
if *flagAsan {
loadinternal(ctxt, "runtime/asan")
}
loadinternal(ctxt, "runtime")
for ; i < len(ctxt.Library); i++ {
lib := ctxt.Library[i]
@ -1015,6 +1021,7 @@ var internalpkg = []string{
"runtime/cgo",
"runtime/race",
"runtime/msan",
"runtime/asan",
}
func ldhostobj(ld func(*Link, *bio.Reader, string, int64, string), headType objabi.HeadType, f *bio.Reader, pkg string, length int64, pn string, file string) *Hostobj {

View File

@ -69,6 +69,7 @@ var (
flagDumpDep = flag.Bool("dumpdep", false, "dump symbol dependency graph")
flagRace = flag.Bool("race", false, "enable race detector")
flagMsan = flag.Bool("msan", false, "enable MSan interface")
flagAsan = flag.Bool("asan", false, "enable ASan interface")
flagAslr = flag.Bool("aslr", true, "enable ASLR for buildmode=c-shared on windows")
flagFieldTrack = flag.String("k", "", "set field tracking `symbol`")