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

@ -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 {