mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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:
parent
5d414d180b
commit
ae4d67c89d
4 changed files with 14 additions and 0 deletions
|
|
@ -45,6 +45,8 @@ Flags:
|
||||||
Note that before Go 1.5 this option took two separate arguments.
|
Note that before Go 1.5 this option took two separate arguments.
|
||||||
-a
|
-a
|
||||||
Disassemble output.
|
Disassemble output.
|
||||||
|
-asan
|
||||||
|
Link with C/C++ address sanitizer support.
|
||||||
-buildid id
|
-buildid id
|
||||||
Record id as Go toolchain build id.
|
Record id as Go toolchain build id.
|
||||||
-buildmode mode
|
-buildmode mode
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,10 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
|
||||||
return true, "msan"
|
return true, "msan"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *flagAsan {
|
||||||
|
return true, "asan"
|
||||||
|
}
|
||||||
|
|
||||||
// Internally linking cgo is incomplete on some architectures.
|
// Internally linking cgo is incomplete on some architectures.
|
||||||
// https://golang.org/issue/14449
|
// https://golang.org/issue/14449
|
||||||
if iscgo && ctxt.Arch.InFamily(sys.MIPS64, sys.MIPS, sys.RISCV64) {
|
if iscgo && ctxt.Arch.InFamily(sys.MIPS64, sys.MIPS, sys.RISCV64) {
|
||||||
|
|
|
||||||
|
|
@ -385,6 +385,9 @@ func libinit(ctxt *Link) {
|
||||||
} else if *flagMsan {
|
} else if *flagMsan {
|
||||||
suffixsep = "_"
|
suffixsep = "_"
|
||||||
suffix = "msan"
|
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)))
|
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 {
|
if *flagMsan {
|
||||||
loadinternal(ctxt, "runtime/msan")
|
loadinternal(ctxt, "runtime/msan")
|
||||||
}
|
}
|
||||||
|
if *flagAsan {
|
||||||
|
loadinternal(ctxt, "runtime/asan")
|
||||||
|
}
|
||||||
loadinternal(ctxt, "runtime")
|
loadinternal(ctxt, "runtime")
|
||||||
for ; i < len(ctxt.Library); i++ {
|
for ; i < len(ctxt.Library); i++ {
|
||||||
lib := ctxt.Library[i]
|
lib := ctxt.Library[i]
|
||||||
|
|
@ -1015,6 +1021,7 @@ var internalpkg = []string{
|
||||||
"runtime/cgo",
|
"runtime/cgo",
|
||||||
"runtime/race",
|
"runtime/race",
|
||||||
"runtime/msan",
|
"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 {
|
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 {
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ var (
|
||||||
flagDumpDep = flag.Bool("dumpdep", false, "dump symbol dependency graph")
|
flagDumpDep = flag.Bool("dumpdep", false, "dump symbol dependency graph")
|
||||||
flagRace = flag.Bool("race", false, "enable race detector")
|
flagRace = flag.Bool("race", false, "enable race detector")
|
||||||
flagMsan = flag.Bool("msan", false, "enable MSan interface")
|
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")
|
flagAslr = flag.Bool("aslr", true, "enable ASLR for buildmode=c-shared on windows")
|
||||||
|
|
||||||
flagFieldTrack = flag.String("k", "", "set field tracking `symbol`")
|
flagFieldTrack = flag.String("k", "", "set field tracking `symbol`")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue