Skip to content

Commit dfe4030

Browse files
committed
build: apply ctxreg flags only to llgo IR
1 parent b538ed2 commit dfe4030

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

internal/build/build.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"github.com/goplus/llgo/internal/cabi"
4242
"github.com/goplus/llgo/internal/clang"
4343
"github.com/goplus/llgo/internal/crosscompile"
44+
"github.com/goplus/llgo/internal/ctxreg"
4445
"github.com/goplus/llgo/internal/env"
4546
"github.com/goplus/llgo/internal/firmware"
4647
"github.com/goplus/llgo/internal/flash"
@@ -1231,6 +1232,10 @@ func exportObject(ctx *context, pkgPath string, exportFile string, data []byte)
12311232
if targetTriple != "" && !hasTargetFlag(ctx.crossCompile.CCFLAGS) && !hasTargetFlag(ctx.crossCompile.CFLAGS) {
12321233
args = append(args, "--target="+targetTriple)
12331234
}
1235+
ctxArch := ctxGoarch(ctx.buildConf.Goarch, ctx.crossCompile.LLVMTarget)
1236+
if reserve := ctxreg.ReserveFlags(ctxArch); len(reserve) > 0 {
1237+
args = appendMissingFlags(args, reserve)
1238+
}
12341239
if ctx.shouldPrintCommands(false) {
12351240
fmt.Fprintf(os.Stderr, "# compiling %s for pkg: %s\n", f.Name(), pkgPath)
12361241
fmt.Fprintln(os.Stderr, "clang", args)

internal/crosscompile/crosscompile.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"strings"
1313

1414
"github.com/goplus/llgo/internal/crosscompile/compile"
15-
"github.com/goplus/llgo/internal/ctxreg"
1615
"github.com/goplus/llgo/internal/env"
1716
"github.com/goplus/llgo/internal/flash"
1817
"github.com/goplus/llgo/internal/targets"
@@ -82,11 +81,6 @@ func buildEnvMap(llgoRoot string) map[string]string {
8281
return envs
8382
}
8483

85-
// reserveRegisterFlags returns clang flags to reserve the closure ctx register.
86-
func reserveRegisterFlags(goarch string) []string {
87-
return ctxreg.ReserveFlags(goarch)
88-
}
89-
9084
func appendMissingFlags(dst []string, flags []string) []string {
9185
for i := 0; i < len(flags); i++ {
9286
flag := flags[i]
@@ -279,11 +273,6 @@ func use(goos, goarch string, wasiThreads, forceEspClang bool) (export Export, e
279273
"-Qunused-arguments",
280274
"-Wno-unused-command-line-argument",
281275
}
282-
if reserve := reserveRegisterFlags(goarch); len(reserve) > 0 {
283-
export.CCFLAGS = appendMissingFlags(export.CCFLAGS, reserve)
284-
export.CFLAGS = appendMissingFlags(export.CFLAGS, reserve)
285-
}
286-
287276
// Add sysroot for macOS only
288277
if goos == "darwin" {
289278
sysrootPath, sysrootErr := getMacOSSysroot()
@@ -528,10 +517,6 @@ func UseTarget(targetName string) (export Export, err error) {
528517
cflags = append(cflags, "--target="+config.LLVMTarget)
529518
ccflags = append(ccflags, "--target="+config.LLVMTarget)
530519
}
531-
if reserve := reserveRegisterFlags(config.GOARCH); len(reserve) > 0 {
532-
cflags = appendMissingFlags(cflags, reserve)
533-
ccflags = appendMissingFlags(ccflags, reserve)
534-
}
535520
// Expand template variables in cflags
536521
expandedCFlags := env.ExpandEnvSlice(config.CFlags, envs)
537522
cflags = append(cflags, expandedCFlags...)

0 commit comments

Comments
 (0)