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

Default wasm32-wasip2 objects to -fPIC by default #495

Closed
wants to merge 1 commit into from

Conversation

alexcrichton
Copy link
Collaborator

This commit updates all of the *.a archives built for the wasm32-wasip2 target to use -fPIC instead of the default non-PIC flag. This makes them suitable for linking into either a dynamic library or a non-dynamic binary without recompiling libc. This is intended to help integrate shared libraries into other precompiled languages, such as Rust's standard library, as it makes its way upstream.

Lots of discussion about this also happened on #429 so I wanted to highlight that this is only happening for the wasm32-wasip2 target and no other targets. For example neither wasm32-wasi nor wasm32-wasip1 are affected. Only users of wasm32-wasip2, of which there aren't too too many, are possibly affected by the runtime overheads here. I have not measured the hypothetical runtime myself, however.

This commit updates all of the `*.a` archives built for the
`wasm32-wasip2` target to use `-fPIC` instead of the default non-PIC
flag. This makes them suitable for linking into either a dynamic library
or a non-dynamic binary without recompiling libc. This is intended to
help integrate shared libraries into other precompiled languages, such
as Rust's standard library, as it makes its way upstream.

Lots of discussion about this also happened on WebAssembly#429 so I wanted to
highlight that this is only happening for the wasm32-wasip2 target and
no other targets. For example neither wasm32-wasi nor wasm32-wasip1 are
affected. Only users of wasm32-wasip2, of which there aren't too too
many, are possibly affected by the runtime overheads here. I have not
measured the hypothetical runtime myself, however.
@alexcrichton
Copy link
Collaborator Author

This is intended to eventually accompany rust-lang/rust#124858 on the Rust side of things.

Copy link
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to see this land.

Hopefully there will not be any issues with linking PIC objects into static binaries, but I will be happy to look into them if they show up.

@TerrorJack
Copy link
Contributor

But for wasm32-wasip2 target, the various .so files have already been built; I'm mildly curious why rust toolchain is unable to use those.

@alexcrichton
Copy link
Collaborator Author

Thinking more on this, that's a good point @TerrorJack. I blindly did this to align with what I was changing the Rust target to do but while it's appropriate in Rust there's no need here in C. The Rust target is changing the default for objects on wasm32-wasip2 to ensure that the precompiled standard library can be used with shared objects but it's not required to. If a shared object is being created though then libc.so will have to come from somewhere and it'll probably be an external clang which already has the bits and pieces and Rust's libc.a won't be used.

Given that I don't think that this is actually necessary, so I'll close this.

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.

3 participants