From 9926c4ed6a9b84765320733db8594bf7ee46dcbc Mon Sep 17 00:00:00 2001 From: xgopilot Date: Sun, 16 Nov 2025 04:35:41 +0000 Subject: [PATCH] build: apply review feedback on main module generation - Change pkg.PkgPath to pkg.ID for better debugging support - Add comment explaining syscall.init weak stub declaration - Simplify sizeTypeForArch to use prog.Uintptr() directly - Remove unused runtime import Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: cpunion <8459+cpunion@users.noreply.github.com> --- internal/build/main_module.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/internal/build/main_module.go b/internal/build/main_module.go index 760177ce..2c3f7e58 100644 --- a/internal/build/main_module.go +++ b/internal/build/main_module.go @@ -22,7 +22,6 @@ package build import ( "go/token" "go/types" - "runtime" "github.com/goplus/llgo/internal/packages" llvm "github.com/goplus/llvm" @@ -32,7 +31,7 @@ import ( func genMainModule(ctx *context, rtPkgPath string, pkg *packages.Package, needRuntime, needPyInit bool) Package { prog := ctx.prog - mainPkg := prog.NewPackage("", pkg.PkgPath+".main") + mainPkg := prog.NewPackage("", pkg.ID+".main") argcVar := mainPkg.NewVarEx("__llgo_argc", prog.Pointer(prog.Int32())) argcVar.Init(prog.Zero(prog.Int32())) @@ -59,6 +58,7 @@ func genMainModule(ctx *context, rtPkgPath string, pkg *packages.Package, needRu } runtimeStub := defineWeakNoArgStub(mainPkg, "runtime.init") + // Define syscall.init as a weak stub to allow linking even when syscall package is not imported defineWeakNoArgStub(mainPkg, "syscall.init") var pyInit llssa.Function @@ -215,11 +215,5 @@ func newEntrySignature(argvType types.Type) *types.Signature { } func sizeTypeForArch(prog llssa.Program, arch string) llssa.Type { - if arch == "" { - arch = runtime.GOARCH - } - if is32Bits(arch) { - return prog.Uint32() - } - return prog.Uint64() + return prog.Uintptr() }