Skip to content

Commit 7729a36

Browse files
aykevldeadprogram
authored andcommitted
windows: use ThinLTO
Switch Windows builds to use ThinLTO. This gets us closer to using ThinLTO everywhere.
1 parent 5404c81 commit 7729a36

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

builder/build.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -694,15 +694,23 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
694694
config.Options.PrintCommands(config.Target.Linker, ldflags...)
695695
}
696696
if config.UseThinLTO() {
697-
ldflags = append(ldflags,
698-
"-mllvm", "-mcpu="+config.CPU(),
699-
"--lto-O"+strconv.Itoa(optLevel))
700-
if config.GOOS() == "darwin" {
697+
ldflags = append(ldflags, "-mllvm", "-mcpu="+config.CPU())
698+
if config.GOOS() == "windows" {
699+
// Options for the MinGW wrapper for the lld COFF linker.
700+
ldflags = append(ldflags,
701+
"-Xlink=/opt:lldlto="+strconv.Itoa(optLevel),
702+
"--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto"))
703+
} else if config.GOOS() == "darwin" {
701704
// Options for the ld64-compatible lld linker.
702-
ldflags = append(ldflags, "-cache_path_lto", filepath.Join(cacheDir, "thinlto"))
705+
ldflags = append(ldflags,
706+
"--lto-O"+strconv.Itoa(optLevel),
707+
"-cache_path_lto", filepath.Join(cacheDir, "thinlto"))
703708
} else {
704709
// Options for the ELF linker.
705-
ldflags = append(ldflags, "--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto"))
710+
ldflags = append(ldflags,
711+
"--lto-O"+strconv.Itoa(optLevel),
712+
"--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto"),
713+
)
706714
}
707715
if config.CodeModel() != "default" {
708716
ldflags = append(ldflags,

compileopts/config.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,6 @@ func (c *Config) UseThinLTO() bool {
192192
// through a plugin, but it's too much hassle to set up.
193193
return false
194194
}
195-
if len(parts) >= 2 && parts[2] == "windows" {
196-
// Linker error (undefined runtime.trackedGlobalsBitmap) when linking
197-
// for Windows. Disable it for now until that's figured out and fixed.
198-
return false
199-
}
200195
// Other architectures support ThinLTO.
201196
return true
202197
}

0 commit comments

Comments
 (0)