-
Notifications
You must be signed in to change notification settings - Fork 49
[WIP] internal/build: fix linkname support main.sym #2155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package main | ||
|
|
||
| import _ "unsafe" | ||
|
|
||
| func main() { | ||
| linkdemo() | ||
| } | ||
|
|
||
| func demo() { | ||
| println("demo") | ||
| } | ||
|
|
||
| //go:linkname linkdemo main.demo | ||
| func linkdemo() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,8 +110,15 @@ func genMainModule(ctx *context, rtPkgPath string, pkg *packages.Package, cfg *g | |
| }) | ||
| } | ||
|
|
||
| mainInit := declareNoArgFunc(mainPkg, pkg.PkgPath+".init") | ||
| mainMain := declareNoArgFunc(mainPkg, pkg.PkgPath+".main") | ||
| var pkgPath string | ||
| if pkg.Types.Name() == "main" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| pkgPath = "main" | ||
| } else { | ||
| pkgPath = pkg.PkgPath | ||
| } | ||
|
|
||
| mainInit := declareNoArgFunc(mainPkg, pkgPath+".init") | ||
| mainMain := declareNoArgFunc(mainPkg, pkgPath+".main") | ||
|
|
||
| entryFn := defineEntryFunction(ctx, mainPkg, argcVar, argvVar, argvValueType, entryFunctions{ | ||
| runtimeStub: runtimeStub, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v.Types.Name()is dereferenced without a nil check, unlike the guard added a few lines up infilterTestPackages(if pkg.Types != nil && pkg.Types.Name() == "main", line 692). Elsewhere in this filep.Typesis defensively nil-checked before use. A package withTypes == nil(e.g. an ill-typed or synthetically-loaded dep) reaching this loop would panic. Recommendv.Types != nil && v.Types.Name() == "main"for consistency and crash-safety.