1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:54:40 -07:00

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: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Ian Lance Taylor 2015-10-21 07:11:01 -07:00
parent 3c1712db0b
commit 7b4b96f248
3 changed files with 16 additions and 0 deletions

View File

@ -72,6 +72,8 @@ Flags:
Write memory profile to file. Write memory profile to file.
-memprofilerate rate -memprofilerate rate
Set runtime.MemProfileRate to rate. Set runtime.MemProfileRate to rate.
-msan
Link with C/C++ memory sanitizer support.
-o file -o file
Write output to file (default a.out, or a.out.exe on Windows). Write output to file (default a.out, or a.out.exe on Windows).
-r dir1:dir2:... -r dir1:dir2:...

View File

@ -198,6 +198,7 @@ var (
elfglobalsymndx int elfglobalsymndx int
flag_installsuffix string flag_installsuffix string
flag_race int flag_race int
flag_msan int
Buildmode BuildMode Buildmode BuildMode
Linkshared bool Linkshared bool
tracksym string tracksym string
@ -373,6 +374,9 @@ func libinit() {
} else if flag_race != 0 { } else if flag_race != 0 {
suffixsep = "_" suffixsep = "_"
suffix = "race" suffix = "race"
} else if flag_msan != 0 {
suffixsep = "_"
suffix = "msan"
} }
Lflag(fmt.Sprintf("%s/pkg/%s_%s%s%s", goroot, goos, goarch, suffixsep, suffix)) Lflag(fmt.Sprintf("%s/pkg/%s_%s%s%s", goroot, goos, goarch, suffixsep, suffix))
@ -483,6 +487,9 @@ func loadlib() {
if flag_race != 0 { if flag_race != 0 {
loadinternal("runtime/race") loadinternal("runtime/race")
} }
if flag_msan != 0 {
loadinternal("runtime/msan")
}
var i int var i int
for i = 0; i < len(Ctxt.Library); i++ { 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 { if (Thearch.Thechar == '5' || Thearch.Thechar == '7') && HEADTYPE == obj.Hdarwin && iscgo {
Linkmode = LinkExternal Linkmode = LinkExternal
} }
// Force external linking for msan.
if flag_msan != 0 {
Linkmode = LinkExternal
}
} }
// cmd/7l doesn't support cgo internal linking // cmd/7l doesn't support cgo internal linking
@ -797,6 +809,7 @@ var internalpkg = []string{
"os/user", "os/user",
"runtime/cgo", "runtime/cgo",
"runtime/race", "runtime/race",
"runtime/msan",
} }
func ldhostobj(ld func(*obj.Biobuf, string, int64, string), f *obj.Biobuf, pkg string, length int64, pn string, file string) { func ldhostobj(ld func(*obj.Biobuf, string, int64, string), f *obj.Biobuf, pkg string, length int64, pn string, file string) {

View File

@ -98,6 +98,7 @@ func Ldmain() {
obj.Flagstr("k", "set field tracking `symbol`", &tracksym) obj.Flagstr("k", "set field tracking `symbol`", &tracksym)
obj.Flagfn1("linkmode", "set link `mode` (internal, external, auto)", setlinkmode) obj.Flagfn1("linkmode", "set link `mode` (internal, external, auto)", setlinkmode)
flag.BoolVar(&Linkshared, "linkshared", false, "link against installed Go shared libraries") 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.Flagcount("n", "dump symbol table", &Debug['n'])
obj.Flagstr("o", "write output to `file`", &outfile) obj.Flagstr("o", "write output to `file`", &outfile)
flag.Var(&rpath, "r", "set the ELF dynamic linker search `path` to dir1:dir2:...") flag.Var(&rpath, "r", "set the ELF dynamic linker search `path` to dir1:dir2:...")