-
Notifications
You must be signed in to change notification settings - Fork 570
Support //go:linkname compiler directive #1006
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
Support //go:linkname compiler directive #1006
Conversation
The test exercises linknaming to a function in an importer package, as well as to a function from the importer package. The two cases are distinct because they have different package initialization order and must work both. Currently the test is passing under upstream Go, and panics under GopherJS.
These two types make an internal representation of a go:compile directive.
The implementation roughly follows these steps: - compiler.Compile() gathers all information about go:linkname directives in the source code and does basic correctness checks. - compiler.WritePkgCode() uses this information to generate code that exposes referenced function implementations in the `$linknames` object, which serves as a global registry of sorts. - It also generates code that will "import" those implementations into appropriate packages from `$linknames` one all packages have been defined. This code needs to be delayed because it may be referencing packages which entries in `$packages` object have not been populated yet. This implementation is sufficient to pass our basic test case: ``` $ gopherjs build github.com/gopherjs/gopherjs/tests/testdata/linkname 148 ↵ $ node linkname.js doing one doing two doing imported one: doing internal one: one secret doing three doing imported three: doing internal three: three secret ``` However, a few adjustments to the standard library overlays are still needed to make it run correctly again.
Now that we support go:linkname directive, the time package expects to find this function implementation in the `runtime` package.
@visualfc, you might be interested in taking a look at this PR. I've noticed that your implementation seems to go into infinite recursion when I build the test case from this PR with it. Here's an example stack trace (under Ubuntu, with a limit of 2G of virtual memory to prevent my laptop from going into swapping):
Note that I built the gopherjs binary from your repository at goplusjs/gopherjs@0e65aed, but ran it this repository with this PR checked out. Hope that helps :) |
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.
LGTM. Should we mention these differences from upstream here?
Good idea, although I've created a separate document for compiler directives. |
This was causing a TestNativesDontImportExtraPackages test failure.
0283a84
to
0486ce6
Compare
goplusjs/gopherjs#35 this PR support go:linkname circle import |
GopherJS implementation is a bit more limited that the upsteam's, but should be sufficient for our use cases. The main limitations are:
Fixes #1000.