From 046070074df6f23da3b29134dd0398c91a41fe90 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 22 May 2022 15:29:47 +0200 Subject: [PATCH] darwin: add support for ThinLTO --- builder/build.go | 13 +++++++++---- compileopts/config.go | 4 ---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/builder/build.go b/builder/build.go index adf89d00..0917b6c9 100644 --- a/builder/build.go +++ b/builder/build.go @@ -695,10 +695,15 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil } if config.UseThinLTO() { ldflags = append(ldflags, - "--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto"), - "-plugin-opt=mcpu="+config.CPU(), - "-plugin-opt=O"+strconv.Itoa(optLevel), - "-plugin-opt=thinlto") + "-mllvm", "-mcpu="+config.CPU(), + "--lto-O"+strconv.Itoa(optLevel)) + if config.GOOS() == "darwin" { + // Options for the ld64-compatible lld linker. + ldflags = append(ldflags, "-cache_path_lto", filepath.Join(cacheDir, "thinlto")) + } else { + // Options for the ELF linker. + ldflags = append(ldflags, "--thinlto-cache-dir="+filepath.Join(cacheDir, "thinlto")) + } if config.CodeModel() != "default" { ldflags = append(ldflags, "-mllvm", "-code-model="+config.CodeModel()) diff --git a/compileopts/config.go b/compileopts/config.go index b30e653e..045890bb 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -192,10 +192,6 @@ func (c *Config) UseThinLTO() bool { // through a plugin, but it's too much hassle to set up. return false } - if len(parts) >= 2 && strings.HasPrefix(parts[2], "macos") { - // We use an external linker here at the moment. - return false - } if len(parts) >= 2 && parts[2] == "windows" { // Linker error (undefined runtime.trackedGlobalsBitmap) when linking // for Windows. Disable it for now until that's figured out and fixed.