Skip to content

Commit 92ed645

Browse files
aykevldeadprogram
authored andcommitted
compiler: remove unnecessary main.main call workaround
Since #1571 (in particular, the first commit that sets the main package path), the main package is always named "main". This makes the callMain() workaround in the runtime unnecessary and allows directly calling the main.main function with a //go:linkname pragma.
1 parent 32a5d46 commit 92ed645

File tree

2 files changed

+1
-10
lines changed

2 files changed

+1
-10
lines changed

compiler/compiler.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,6 @@ func CompileProgram(pkgName string, lprogram *loader.Program, machine llvm.Targe
297297
}
298298
irbuilder.CreateRetVoid()
299299

300-
// Conserve for goroutine lowering. Without marking these as external, they
301-
// would be optimized away.
302-
realMain := c.mod.NamedFunction(lprogram.MainPkg().Pkg.Path() + ".main")
303-
realMain.SetLinkage(llvm.ExternalLinkage) // keep alive until goroutine lowering
304-
305-
// Replace callMain placeholder with actual main function.
306-
c.mod.NamedFunction("runtime.callMain").ReplaceAllUsesWith(realMain)
307-
308300
// Load some attributes
309301
getAttr := func(attrName string) llvm.Attribute {
310302
attrKind := llvm.AttributeKindID(attrName)

src/runtime/runtime.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const Compiler = "tinygo"
1010
// package.
1111
func initAll()
1212

13-
// callMain is a placeholder for the program main function.
14-
// All references to this are replaced with references to the program main function by the compiler.
13+
//go:linkname callMain main.main
1514
func callMain()
1615

1716
func GOMAXPROCS(n int) int {

0 commit comments

Comments
 (0)