Commit 7b4b96f2 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/link: add -msan option

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: 's avatarDavid Crawshaw <crawshaw@golang.org>
parent 3c1712db
......@@ -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:...
......
......@@ -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) {
......
......@@ -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:...")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment