theotherjimmy opened PR #14772 from theotherjimmy:s390x-pic to bytecodealliance:main:
This uses the R_390_GOTENT relocation instead of the inline relocations previously emitted.
This is the same issue reported as #2907 but for s390x
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
theotherjimmy updated PR #14772.
theotherjimmy updated PR #14772.
github-actions[bot] added the label isle on PR #14772.
github-actions[bot] added the label cranelift on PR #14772.
github-actions[bot] added the label cranelift:module on PR #14772.
github-actions[bot] commented on PR #14772:
Subscribe to Label Action
cc @avanhatt, @cfallin, @fitzgen, @mmcloughlin
<details>
This issue or pull request has been labeled: "cranelift", "cranelift:module", "isle"Thus the following users have been cc'd because of the following labels:
- avanhatt: isle
- cfallin: isle
- fitzgen: isle
- mmcloughlin: isle
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
theotherjimmy updated PR #14772.
theotherjimmy has marked PR #14772 as ready for review.
theotherjimmy requested wasmtime-compiler-s390x-reviewers for a review on PR #14772.
theotherjimmy removed the review request for wasmtime-compiler-reviewers from PR #14772.
theotherjimmy requested cfallin for a review on PR #14772.
theotherjimmy requested wasmtime-compiler-reviewers for a review on PR #14772.
:memo: uweigand submitted PR review.
:speech_balloon: uweigand created PR review comment:
We can use
LGRL rd, sym@GOTENT, saving one instruction. Also, I do not think it makes sense to support an offset with this relocation - it would be preferable to have no offset here (just likeTlsGd), and perform any offset addition that might be necessary at the ISLE level.
:speech_balloon: uweigand created PR review comment:
We probably want to use
(if-let false (is_pic))here then.
:speech_balloon: uweigand created PR review comment:
In the case where we have a GOT, we might want to move TLS descriptors into the GOT as well (as is done by other static compilers). Otherwise, we can get the same problem with relocations on the text section ...
:speech_balloon: uweigand created PR review comment:
Static compilers would use the PLT here. The only difference is that going via GOT will disable lazy binding, but that may not really be relevant here ... Might still be interesting to see if
brasl func@PLTwould also work.
:speech_balloon: uweigand created PR review comment:
I think if we just hard-code 0 instead of
offsethere, common ISLE logic will already handle offsets elsewhere (via regular addition). But that needs to be verified.
:thumbs_up: cfallin submitted PR review:
Thanks!
cfallin added PR #14772 Implement PIC for s390x to the merge queue.
uweigand commented on PR #14772:
Hi @cfallin I don't think this is ready to merge just yet, see the comments above ...
cfallin removed PR #14772 Implement PIC for s390x from the merge queue.
cfallin commented on PR #14772:
Ah, sorry about that, our reviews raced. Removed from queue and will wait for resolution on the above.
:memo: theotherjimmy submitted PR review.
:speech_balloon: theotherjimmy created PR review comment:
Added there and the 5 other non-pic fallbacks.
:speech_balloon: theotherjimmy edited PR review comment.
theotherjimmy updated PR #14772.
:memo: theotherjimmy submitted PR review.
:speech_balloon: theotherjimmy created PR review comment:
Hard coding an offset here fails tests, so I don't think this is handled with regular addition. I'll add (pun intended) an isle rule for this since it's probably better in isle than rust.
theotherjimmy updated PR #14772.
:memo: theotherjimmy submitted PR review.
:speech_balloon: theotherjimmy created PR review comment:
Resolved with isle. That should allow it to be better maintainable.
theotherjimmy requested uweigand for a review on PR #14772.
theotherjimmy commented on PR #14772:
Please excuse me pushing a middle state by mistake. It should be ready for re-review. I've moved more of logic (offsets) into isle and implemented PLT for function references instead of GOT.
theotherjimmy updated PR #14772.
theotherjimmy updated PR #14772.
:repeat: uweigand submitted PR review:
Looking better, thanks! Still a few issues, mostly related to PLT handling.
:speech_balloon: uweigand created PR review comment:
This doesn't look right. The R_390_PLT32DBL relocation resolves to code (the PLT stub itself), not data. There is no point in loading from the R_390_PLT32DBL relocation, it should only ever be used with direct call (brasl) instructions.
And note that the current code already uses R_390_PLT32DBL for calls. It just sometimes instead uses the
load_symbol_relocindirection. I believe this is because (some?) embedders of Cranelift may not be handling PLT relocations correctly? Normally, the embedder should do the reachability check and create a PLT stub dynamically if the target is not directly reachable.Interestingly, I see in
cranelift/jit/src/compiled_blob.rsthat this is done forReloc::X86GOTPCRel4, but not forReloc::S390xPLTRel32Dbl- that probably should be fixed.But that is a separate problem, I guess. For now, I think the best way is to continue to support both "near" and "far" calls, where near calls use the PLT, and far calls in the PIC case are changes to use GOT indirection instead (as your earlier patch already had it - sorry!). Later we can investigate whether the "far" call case is even needed when all embedders support proper PLT stub generation.
:speech_balloon: uweigand created PR review comment:
This should always use the GOT anyway. The PLT can only be used for calls, where the address is invisible. Whenever an address is visible as a pointer, it must use the GOT, to guarantee correct pointer equality checks.
:speech_balloon: uweigand created PR review comment:
This still intermingles a relocation in the text section. Ideally, this would be emitted in a constant pool somewhere (not sure if the Cranelift constant pool infrastructure already supports relocs on constants ...). But I guess that can be a separate PR.
:speech_balloon: uweigand created PR review comment:
That doesn't look right - there's still cases that use r1 ...
:memo: theotherjimmy submitted PR review.
:speech_balloon: theotherjimmy created PR review comment:
I've reworked the out-of-range calls to use GOT instead.
:memo: theotherjimmy submitted PR review.
:speech_balloon: theotherjimmy created PR review comment:
I'm looking into compiled_blob.rs to see if we need modifications there.
theotherjimmy updated PR #14772.
:memo: uweigand submitted PR review:
This now looks good except for the missing GOT support for regular calls.
:speech_balloon: uweigand created PR review comment:
We need GOT support for regular calls as well, not just tail calls and try_calls.
theotherjimmy updated PR #14772.
theotherjimmy requested uweigand for a review on PR #14772.
:memo: uweigand submitted PR review:
The tests are now all failing, something seems to be missing.
Also, minor nit inline.
:speech_balloon: uweigand created PR review comment:
We now have explicit
(RelocDistance.Far)above, but use a placeholder plus rule priority here. These cases should consistently use the same method (it seems to me if we can avoid rule priorities via explicit choices, that might be preferable).
theotherjimmy updated PR #14772.
theotherjimmy updated PR #14772.
:memo: theotherjimmy submitted PR review.
:speech_balloon: theotherjimmy created PR review comment:
This is to ensure that we use the PIC variant when PIC is enabled (the following line is
(if-let true (is-pic))). I've removed the non-pic case's priority, since it's now explicit and made the PIC rules' priority 1.
:memo: uweigand submitted PR review.
:speech_balloon: uweigand created PR review comment:
What I meant is: the current code never explicitly uses matching against
RelocDistance.Far. Instead we always use a pair of rules, one matching againstRelocDistance.Nearand the other matching against a wildcard_. There is no real difference currently, but if at any point a third member ofRelocDistancewere added, the current code would still work fine.Now, if it would make life easier, I'd be OK with changing this approach to always have some rules matching
RelocDistance.Farand some matchingRelocDistance.Near, but no wildcard in any of the rules.What this patch (still) does, however, is to add a (seemingly random?) mix of sometimes using
RelocDistance.Farand sometimes using a wildcard. Even the three -otherwise repeating- call rule blocks now use different conventions here.This is what I was asking you to fix. Choose one strategy or the other, but then use it consistently.
:memo: theotherjimmy submitted PR review.
:speech_balloon: theotherjimmy created PR review comment:
Good point. I've changed all of them to implicitly match on
RelocDistance.Farinstead, since that's more general and all of them can be expressed that way.
theotherjimmy updated PR #14772.
:thumbs_up: uweigand submitted PR review:
LGTM now, thanks!
:memo: uweigand submitted PR review.
:speech_balloon: uweigand created PR review comment:
Looks good, thanks!
uweigand added PR #14772 Implement PIC for s390x to the merge queue.
:check: uweigand merged PR #14772.
uweigand removed PR #14772 Implement PIC for s390x from the merge queue.
Last updated: Nov 19 2026 at 20:05 UTC