Skip to content

internal/fakecgo: generalize and update trampoline generation#397

Open
gdams wants to merge 3 commits intoebitengine:mainfrom
gdams:trampolines
Open

internal/fakecgo: generalize and update trampoline generation#397
gdams wants to merge 3 commits intoebitengine:mainfrom
gdams:trampolines

Conversation

@gdams
Copy link
Contributor

@gdams gdams commented Jan 23, 2026

Updates gen.go to generate trampolines for arm, arm64, loong64, and riscv64, 386 alongside amd64.

What issue is this addressing?

What type of issue is this addressing?

feature

What this PR does | solves

  • Added architecture definitions for additional platforms.
  • Simplified instruction generation: removed custom call instructions in favor of a standard CALL instruction which works across the supported architectures (including simplified syntax for loong64 and riscv64).
  • Updated build constraints in generated files to !cgo only, relying on file naming conventions (ztrampolines_$GOARCH.s) for architecture selection.
  • Regenerated ztrampolines_*.s files to reflect these changes. internal/fakecgo: generalize and update trampoline generation

@hajimehoshi
Copy link
Member

Interesting, but does this change mean our callback.go will be much more different from the original one in the Go repository?

@qmuntal
Copy link
Contributor

qmuntal commented Jan 23, 2026

Interesting, but does this change mean our callback.go will be much more different from the original one in the Go repository?

The approach hasn't changed, it's just that the linknames and the variable declarations have been moved into another file. It's true that some comments are lost in the process, although those comments are copied verbatim from upstream, so one can look there to understand what's happening. The only comment that should be kept (in my opinion) is the one that is specific to purego, the one that start with // In Go 1.20 the race detector was rewritten to pure Go. We could also add a note in callbacks.go pointing to zcallbacks.go.

@qmuntal
Copy link
Contributor

qmuntal commented Jan 23, 2026

Note that this not only simplifies adding and maintaining architectures, but will also be used as part of the #343 fix.

@hajimehoshi
Copy link
Member

hajimehoshi commented Jan 23, 2026

My concern was this would make it harder to synchronize callbacks.go and other files with the original ones. Even in the current situation, callbacks.go and the original one is quite different. This might be ok but I am not sure. @TotallyGamerJet What do you think?

@gdams
Copy link
Contributor Author

gdams commented Jan 23, 2026

My concern was this would make it harder to synchronize callbacks.go and other files with the original ones. Even in the current situation, callbacks.go and the original one is quite different. This might be ok but I am not sure. @TotallyGamerJet What do you think?

Happy to revert the callback.go templating if you're really against this although I do see some benefit to templating it, especially as it grows!

@TotallyGamerJet
Copy link
Collaborator

Ehh I'm not confident that templating callbacks.go is really necessary. I rather wait until it gets uncomfortably large and then consider it

@gdams
Copy link
Contributor Author

gdams commented Jan 27, 2026

Ehh I'm not confident that templating callbacks.go is really necessary. I rather wait until it gets uncomfortably large and then consider it

Shall I revert the callback changes then and just leave the trampolines?

@TotallyGamerJet
Copy link
Collaborator

Shall I revert the callback changes then and just leave the trampolines?

Yes, I'm still trying to figure out how I feel about the trampoline generation. If we can't generate the entire file I'm leaning to not doing it at all because then it becomes confusing if changes should be made to the static trampoline file or the generated one

gdams added 2 commits January 30, 2026 14:18
Updates `gen.go` to generate trampolines for `arm64`, `loong64`, and `riscv64` alongside `amd64`.

Changes include:
- Added architecture definitions for additional platforms.
- Simplified instruction generation: removed custom `CallFormat` in favor of a standard `CALL` instruction which works across the supported architectures (including simplified syntax for loong64 and riscv64).
- Updated build constraints in generated files to `!cgo` only, relying on file naming conventions (`ztrampolines_$GOARCH.s`) for architecture selection.
- Regenerated `ztrampolines_*.s` files to reflect these changes.
internal/fakecgo: generalize and update trampoline generation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants