@@ -594,12 +594,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
594594 defer llvmBuf .Dispose ()
595595 return result , os .WriteFile (outpath , llvmBuf .Bytes (), 0666 )
596596 case ".bc" :
597- var buf llvm.MemoryBuffer
598- if config .UseThinLTO () {
599- buf = llvm .WriteThinLTOBitcodeToMemoryBuffer (mod )
600- } else {
601- buf = llvm .WriteBitcodeToMemoryBuffer (mod )
602- }
597+ buf := llvm .WriteThinLTOBitcodeToMemoryBuffer (mod )
603598 defer buf .Dispose ()
604599 return result , os .WriteFile (outpath , buf .Bytes (), 0666 )
605600 case ".ll" :
@@ -621,16 +616,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
621616 dependencies : []* compileJob {programJob },
622617 result : objfile ,
623618 run : func (* compileJob ) error {
624- var llvmBuf llvm.MemoryBuffer
625- if config .UseThinLTO () {
626- llvmBuf = llvm .WriteThinLTOBitcodeToMemoryBuffer (mod )
627- } else {
628- var err error
629- llvmBuf , err = machine .EmitToMemoryBuffer (mod , llvm .ObjectFile )
630- if err != nil {
631- return err
632- }
633- }
619+ llvmBuf := llvm .WriteThinLTOBitcodeToMemoryBuffer (mod )
634620 defer llvmBuf .Dispose ()
635621 return os .WriteFile (objfile , llvmBuf .Bytes (), 0666 )
636622 },
@@ -664,7 +650,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
664650 job := & compileJob {
665651 description : "compile extra file " + path ,
666652 run : func (job * compileJob ) error {
667- result , err := compileAndCacheCFile (abspath , tmpdir , config .CFlags (), config .UseThinLTO (), config . Options .PrintCommands )
653+ result , err := compileAndCacheCFile (abspath , tmpdir , config .CFlags (), config .Options .PrintCommands )
668654 job .result = result
669655 return err
670656 },
@@ -682,7 +668,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
682668 job := & compileJob {
683669 description : "compile CGo file " + abspath ,
684670 run : func (job * compileJob ) error {
685- result , err := compileAndCacheCFile (abspath , tmpdir , pkg .CFlags , config .UseThinLTO (), config . Options .PrintCommands )
671+ result , err := compileAndCacheCFile (abspath , tmpdir , pkg .CFlags , config .Options .PrintCommands )
686672 job .result = result
687673 return err
688674 },
@@ -741,36 +727,34 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
741727 }
742728 ldflags = append (ldflags , dependency .result )
743729 }
744- if config .UseThinLTO () {
745- ldflags = append (ldflags , "-mllvm" , "-mcpu=" + config .CPU ())
746- if config .GOOS () == "windows" {
747- // Options for the MinGW wrapper for the lld COFF linker.
748- ldflags = append (ldflags ,
749- "-Xlink=/opt:lldlto=" + strconv .Itoa (optLevel ),
750- "--thinlto-cache-dir=" + filepath .Join (cacheDir , "thinlto" ))
751- } else if config .GOOS () == "darwin" {
752- // Options for the ld64-compatible lld linker.
753- ldflags = append (ldflags ,
754- "--lto-O" + strconv .Itoa (optLevel ),
755- "-cache_path_lto" , filepath .Join (cacheDir , "thinlto" ))
756- } else {
757- // Options for the ELF linker.
758- ldflags = append (ldflags ,
759- "--lto-O" + strconv .Itoa (optLevel ),
760- "--thinlto-cache-dir=" + filepath .Join (cacheDir , "thinlto" ),
761- )
762- }
763- if config .CodeModel () != "default" {
764- ldflags = append (ldflags ,
765- "-mllvm" , "-code-model=" + config .CodeModel ())
766- }
767- if sizeLevel >= 2 {
768- // Workaround with roughly the same effect as
769- // https://reviews.llvm.org/D119342.
770- // Can hopefully be removed in LLVM 15.
771- ldflags = append (ldflags ,
772- "-mllvm" , "--rotation-max-header-size=0" )
773- }
730+ ldflags = append (ldflags , "-mllvm" , "-mcpu=" + config .CPU ())
731+ if config .GOOS () == "windows" {
732+ // Options for the MinGW wrapper for the lld COFF linker.
733+ ldflags = append (ldflags ,
734+ "-Xlink=/opt:lldlto=" + strconv .Itoa (optLevel ),
735+ "--thinlto-cache-dir=" + filepath .Join (cacheDir , "thinlto" ))
736+ } else if config .GOOS () == "darwin" {
737+ // Options for the ld64-compatible lld linker.
738+ ldflags = append (ldflags ,
739+ "--lto-O" + strconv .Itoa (optLevel ),
740+ "-cache_path_lto" , filepath .Join (cacheDir , "thinlto" ))
741+ } else {
742+ // Options for the ELF linker.
743+ ldflags = append (ldflags ,
744+ "--lto-O" + strconv .Itoa (optLevel ),
745+ "--thinlto-cache-dir=" + filepath .Join (cacheDir , "thinlto" ),
746+ )
747+ }
748+ if config .CodeModel () != "default" {
749+ ldflags = append (ldflags ,
750+ "-mllvm" , "-code-model=" + config .CodeModel ())
751+ }
752+ if sizeLevel >= 2 {
753+ // Workaround with roughly the same effect as
754+ // https://reviews.llvm.org/D119342.
755+ // Can hopefully be removed in LLVM 15.
756+ ldflags = append (ldflags ,
757+ "-mllvm" , "--rotation-max-header-size=0" )
774758 }
775759 if config .Options .PrintCommands != nil {
776760 config .Options .PrintCommands (config .Target .Linker , ldflags ... )
@@ -1069,10 +1053,6 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config) error {
10691053 }
10701054 }
10711055
1072- if config .GOOS () != "darwin" && ! config .UseThinLTO () {
1073- transform .ApplyFunctionSections (mod ) // -ffunction-sections
1074- }
1075-
10761056 // Insert values from -ldflags="-X ..." into the IR.
10771057 err = setGlobalValues (mod , config .Options .GlobalValues )
10781058 if err != nil {
0 commit comments