@@ -1438,17 +1438,17 @@ func buildPkg(ctx *context, aPkg *aPackage, verbose bool) error {
14381438}
14391439
14401440func exportObject (ctx * context , pkgPath string , exportFile string , pkg llssa.Package ) (string , error ) {
1441- if useInMemoryNativeCodegen (ctx ) {
1441+ if useNativeLLVMCodegen (ctx ) {
14421442 return exportObjectInMemory (ctx , pkgPath , exportFile , pkg )
14431443 }
14441444 return exportObjectWithClang (ctx , pkgPath , exportFile , []byte (pkg .String ()))
14451445}
14461446
1447- func useInMemoryNativeCodegen (ctx * context ) bool {
1448- return useInMemoryNativeCodegenConf (ctx .buildConf )
1447+ func useNativeLLVMCodegen (ctx * context ) bool {
1448+ return useNativeLLVMCodegenConf (ctx .buildConf )
14491449}
14501450
1451- func useInMemoryNativeCodegenConf (conf * Config ) bool {
1451+ func useNativeLLVMCodegenConf (conf * Config ) bool {
14521452 return conf != nil && ! conf .GenLL &&
14531453 conf .Target == "" &&
14541454 conf .Goos == runtime .GOOS &&
@@ -1500,28 +1500,22 @@ func exportObjectInMemory(ctx *context, pkgPath string, exportFile string, pkg l
15001500 return "" , err
15011501 }
15021502 }
1503- buf , err := ctx .prog .TargetMachine ().EmitToMemoryBuffer (pkg .Module (), gllvm .ObjectFile )
1504- if err != nil {
1505- return "" , err
1506- }
1507- defer buf .Dispose ()
15081503
15091504 base := filepath .Base (exportFile )
15101505 objFile , err := os .CreateTemp ("" , base + "-*.o" )
15111506 if err != nil {
15121507 return "" , err
15131508 }
15141509 objFileName := objFile .Name ()
1515- if ctx .shouldPrintCommands (false ) {
1516- fmt .Fprintf (os .Stderr , "# compiling %s for pkg: %s\n " , objFileName , pkgPath )
1517- fmt .Fprintln (os .Stderr , "# using in-memory LLVM object emission" )
1518- }
1519- if _ , err := objFile .Write (buf .Bytes ()); err != nil {
1520- objFile .Close ()
1510+ if err := objFile .Close (); err != nil {
15211511 os .Remove (objFileName )
15221512 return "" , err
15231513 }
1524- if err := objFile .Close (); err != nil {
1514+ if ctx .shouldPrintCommands (false ) {
1515+ fmt .Fprintf (os .Stderr , "# compiling %s for pkg: %s\n " , objFileName , pkgPath )
1516+ fmt .Fprintln (os .Stderr , "# using direct LLVM object emission" )
1517+ }
1518+ if err := ctx .prog .TargetMachine ().EmitToFile (pkg .Module (), objFileName , gllvm .ObjectFile ); err != nil {
15251519 os .Remove (objFileName )
15261520 return "" , err
15271521 }
0 commit comments