]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: add -msan option
authorIan Lance Taylor <iant@golang.org>
Wed, 21 Oct 2015 14:11:01 +0000 (07:11 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 21 Oct 2015 14:40:07 +0000 (14:40 +0000)
The -msan option causes the linker to link against the runtime/msan
package in order to use the C/C++ memory sanitizer.

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

Change-Id: I02c097393b98c5b80e40ee3dbc167a8b4d23efe0
Reviewed-on: https://go-review.googlesource.com/16161
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/link/doc.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/pobj.go

index 479988e8b1ab734b411d7c38237eb9f3eaf8f94a..6a16080f35440b2c271cd3c359a6c6a378282e72 100644 (file)
@@ -72,6 +72,8 @@ Flags:
                Write memory profile to file.
        -memprofilerate rate
                Set runtime.MemProfileRate to rate.
+       -msan
+               Link with C/C++ memory sanitizer support.
        -o file
                Write output to file (default a.out, or a.out.exe on Windows).
        -r dir1:dir2:...
index 5977bee7f108a687e43f6e374c8b3a2bc07b972b..9bcfcbf9225fb8751d5d94681c896750ae9f9a5a 100644 (file)
@@ -198,6 +198,7 @@ var (
        elfglobalsymndx    int
        flag_installsuffix string
        flag_race          int
+       flag_msan          int
        Buildmode          BuildMode
        Linkshared         bool
        tracksym           string
@@ -373,6 +374,9 @@ func libinit() {
        } else if flag_race != 0 {
                suffixsep = "_"
                suffix = "race"
+       } else if flag_msan != 0 {
+               suffixsep = "_"
+               suffix = "msan"
        }
 
        Lflag(fmt.Sprintf("%s/pkg/%s_%s%s%s", goroot, goos, goarch, suffixsep, suffix))
@@ -483,6 +487,9 @@ func loadlib() {
        if flag_race != 0 {
                loadinternal("runtime/race")
        }
+       if flag_msan != 0 {
+               loadinternal("runtime/msan")
+       }
 
        var i int
        for i = 0; i < len(Ctxt.Library); i++ {
@@ -517,6 +524,11 @@ func loadlib() {
                if (Thearch.Thechar == '5' || Thearch.Thechar == '7') && HEADTYPE == obj.Hdarwin && iscgo {
                        Linkmode = LinkExternal
                }
+
+               // Force external linking for msan.
+               if flag_msan != 0 {
+                       Linkmode = LinkExternal
+               }
        }
 
        // cmd/7l doesn't support cgo internal linking
@@ -797,6 +809,7 @@ var internalpkg = []string{
        "os/user",
        "runtime/cgo",
        "runtime/race",
+       "runtime/msan",
 }
 
 func ldhostobj(ld func(*obj.Biobuf, string, int64, string), f *obj.Biobuf, pkg string, length int64, pn string, file string) {
index f6c47ddc32eec1fd9704c6135e7085ac8a35f1ab..5ba5a68d74facd3bc189298b3ad3dec011a3ce64 100644 (file)
@@ -98,6 +98,7 @@ func Ldmain() {
        obj.Flagstr("k", "set field tracking `symbol`", &tracksym)
        obj.Flagfn1("linkmode", "set link `mode` (internal, external, auto)", setlinkmode)
        flag.BoolVar(&Linkshared, "linkshared", false, "link against installed Go shared libraries")
+       obj.Flagcount("msan", "enable MSan interface", &flag_msan)
        obj.Flagcount("n", "dump symbol table", &Debug['n'])
        obj.Flagstr("o", "write output to `file`", &outfile)
        flag.Var(&rpath, "r", "set the ELF dynamic linker search `path` to dir1:dir2:...")