Skip to content
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

[WebAssembly] Use absolute pointers #31676

Closed

Conversation

MaxDesiatov
Copy link
Contributor

WebAssembly target uses absolute pointers, as explained by @kateinoigakukun on Swift Forums:

It's due to the design of WebAssembly and LLVM support.
If LLVM supports substruction relocation type on WebAssembly like R_X86_64_PC32 or X86_64_RELOC_SUBTRACTOR, this issue can be solved easily.

But LLVM doesn't support this relocation type because of the design of WebAssembly.

First, R_X86_64_PC32 and X86_64_RELOC_SUBTRACTOR are mainly used to generate PIC but WebAssembly doesn't require PIC because it doesn't support dynamic linking. In addition, the memory space also begins at 0, so it's unnecessary to relocate at load time. All absolute addresses can be embedded in wasm binary file directly.

As confirmed by @jckarter:

I agree using an absolute pointer in place of relative is the way to go.

Related to SR-9307.

@MaxDesiatov MaxDesiatov changed the title [WebAssembly] Use absolute pointers #ifdef __WASM__ [WebAssembly] Use absolute pointers when targeting WASM May 10, 2020
@MaxDesiatov MaxDesiatov changed the title [WebAssembly] Use absolute pointers when targeting WASM [WebAssembly] Use absolute pointers May 10, 2020
@MaxDesiatov
Copy link
Contributor Author

@compnerd could you have a look at this please? Thanks!

@compnerd
Copy link
Member

This seems fine, but doesn’t IRGen need to be updated as well?

@MaxDesiatov
Copy link
Contributor Author

@compnerd it does, would you like me to include that in this PR or a separate PR?

@compnerd
Copy link
Member

Yes please, could you make those changes as part of this PR?

@jckarter
Copy link
Contributor

Similar to #31811, it'd be nice if we could make this behavior conditional on the Runtime template argument, instead of using conditional compilation. That would make it easier to support cross-platform reflection tools where a non-wasm host tool wants to use MetadataReader to inspect a wasm binary or running process.

@MaxDesiatov MaxDesiatov changed the base branch from master to main September 24, 2020 08:41
@MaxDesiatov
Copy link
Contributor Author

@swift-ci please smoke test

@MaxDesiatov
Copy link
Contributor Author

@jckarter I'm happy to make this conditional based on the Runtime template argument, but I'm not sure how that argument should be passed. detail::applyRelativeOffset takes only two template arguments, should I add a third one with typename Runtime? Maybe applyRelativeOffset should become a member function of Runtime?

Also, even with that approach the point of use of detail::applyRelativeOffset doesn't take any template arguments for runtime. How would I pass it at the point of use then?

@kateinoigakukun
Copy link
Member

From our forum discussion, we are going to use absolute pointer only for function pointer #42094

@kateinoigakukun kateinoigakukun deleted the maxd/wasm-absolute-pointers branch June 30, 2023 02:24
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.

None yet

4 participants