]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/link: add -asan option
authorfanzha02 <fannie.zhang@arm.com>
Mon, 4 Jan 2021 08:23:01 +0000 (16:23 +0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 22 Oct 2021 21:48:34 +0000 (21:48 +0000)
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>
src/cmd/link/doc.go
src/cmd/link/internal/ld/config.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/main.go

index 604675caecf1f2ed72398a63a119931821ac6d5a..98c954f0f1ad76e871bb6c8a504d29a64bf0cbe4 100644 (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
index 4045c97dd776019b5b4b9268a92a5bed1089beb0..72616ff62f9012ca15e91963044eea14aac1bc64 100644 (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) {
index 3221d60f806800fa95fa314913329c318b24db0c..01ab6474b8f240e349c505846e054df29f8980b5 100644 (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 {
index 4d3b8b904c8168d765961a8ea1e64ba225aa7f15..a5a5a71250fe92b592b8d4beca01c5b932c85512 100644 (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`")