-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/compile: "missing function body" error when using the //go:linkname compiler directive #15006
Comments
How do you suggest we fix this? We certainly do want to pass |
This is known and I think the empty assembly file is the accepted fix.
It's a rarely used feature and having an assembly file also make it
standout.
I don't think we should make this unsafe feature easy to use.
|
I agree with Minux. If you're looking at a Go package to import, you might want to know if it does any unsafe trickery. Currently you have to grep for an import of unsafe and look for non-.go files. If we got rid of the requirement for the empty .s file, then you'd have to grep for //go:linkname also. |
It seems the agreement is to add .s file. Closing this. |
actually, I try to fix this with: But it doesn't seem to work. |
@bigfg this issue is closed, please open a new issue. |
What version of Go are you using (
go version
)?go version go1.6 darwin/amd64
go version devel +aa3650f Wed Mar 9 09:13:43 2016 +0000 darwin/amd64
What operating system and processor architecture are you using (
go env
)?Mac OS X 10.9.5 on Intel Core i7-3615QM
What did you do?
The Go manual on Compiler Directives says:
For example let's say (hypothetically) that I wanted to call the
strhash
function defined in theruntime
package, I could do:What did you expect to see?
The code above should build with no special ceremony.
What did you see instead?
The code doesn't build for a silly reason:
This comes from the fact that in
cmd/compile/internal/gc/pgen.go
we do:So in order to pass this check, we need to not have
pure_go
, which comes from the-complete
flag incmd/compile/internal/gc/lex.go
:which is passed from
cmd/go/build.go
under the following circumstances:So one workaround to not be
-complete
is to include an empty.s
file in the package using the//go:linkname
directive, as this will makelen(p.SFiles)
be1
, which in turn will makeextFiles
non-zero, so that the-complete
flag won't get passed and we can pass the check above, and then the code builds and runs as expected. Phew!The text was updated successfully, but these errors were encountered: