decision _start generation by target, add some fake variables

This commit is contained in:
Li Jie
2025-08-16 10:50:12 +08:00
parent 3431354cb2
commit e8bae52f66

View File

@@ -663,6 +663,18 @@ func isWasmTarget(goos string) bool {
return slices.Contains([]string{"wasi", "js", "wasip1"}, goos)
}
func needStart(conf *Config) bool {
if conf.Target == "" {
return !isWasmTarget(conf.Goos)
}
switch conf.Target {
case "wasip2":
return false
default:
return true
}
}
func genMainModuleFile(ctx *context, rtPkgPath string, pkg *packages.Package, needRuntime, needPyInit bool) (path string, err error) {
var (
pyInitDecl string
@@ -717,8 +729,10 @@ define weak void @_start() {
}
`
mainDefine := "define i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr"
if isWasmTarget(ctx.buildConf.Goos) {
if !needStart(ctx.buildConf) && isWasmTarget(ctx.buildConf.Goos) {
mainDefine = "define hidden noundef i32 @__main_argc_argv(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr"
}
if !needStart(ctx.buildConf) {
startDefine = ""
}
mainCode := fmt.Sprintf(`; ModuleID = 'main'