Skip to content

Commit 0460700

Browse files
aykevldeadprogram
authored andcommitted
darwin: add support for ThinLTO
1 parent c23a5b6 commit 0460700

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

builder/build.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,15 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
695695
}
696696
if config.UseThinLTO() {
697697
ldflags = append(ldflags,
698-
"--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto"),
699-
"-plugin-opt=mcpu="+config.CPU(),
700-
"-plugin-opt=O"+strconv.Itoa(optLevel),
701-
"-plugin-opt=thinlto")
698+
"-mllvm", "-mcpu="+config.CPU(),
699+
"--lto-O"+strconv.Itoa(optLevel))
700+
if config.GOOS() == "darwin" {
701+
// Options for the ld64-compatible lld linker.
702+
ldflags = append(ldflags, "-cache_path_lto", filepath.Join(cacheDir, "thinlto"))
703+
} else {
704+
// Options for the ELF linker.
705+
ldflags = append(ldflags, "--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto"))
706+
}
702707
if config.CodeModel() != "default" {
703708
ldflags = append(ldflags,
704709
"-mllvm", "-code-model="+config.CodeModel())

compileopts/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +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 && strings.HasPrefix(parts[2], "macos") {
196-
// We use an external linker here at the moment.
197-
return false
198-
}
199195
if len(parts) >= 2 && parts[2] == "windows" {
200196
// Linker error (undefined runtime.trackedGlobalsBitmap) when linking
201197
// for Windows. Disable it for now until that's figured out and fixed.

0 commit comments

Comments
 (0)