-
Notifications
You must be signed in to change notification settings - Fork 3.4k
A way to propagate link-time settings from libraries #14729
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
Comments
I think I remember @floooh asking for this, but that might have been a while ago and/or on Twitter... but maybe there is a previous discussion. |
Interesting idea regarding custom sections. We could perhaps also do something with symbol properties like we do with EMSCRIPTEN_KEEPALIVE? |
Remembered another one where this would be useful - |
Yeah that would work too. Although I think EMSCRIPTEN_KEEPALIVE is just a macro for standard visibility attribute, whereas anything else would still require custom sections. |
One downside this approach is that emscripten would have to inspect / parse all the object files passed to the linker. As of today we don't do that. We do run llvm-nm on them in some circumstances but I've been trying to stop doing that for a while now. |
That's true, but parsing a single section out of Wasm should be very quick - it's designed for this kind of random access. And the benefits for the user outweigh the tooling costs IMO. |
How about adding a completely new |
Idk, that kind of split seems unfortunate as it makes integration with existing build systems harder. Splitting it out also feels wrong because those flags are inherently tied to specific object files - if some object file ends up excluded by the linker as unnecessary, corresponding flags are not needed either. In fact, we already have at least one place where we do this kind of merging & post-processing - EM_JS creates symbols in a custom linking section that are later discovered and postprocesser by Binaryen after linker took care of their merging. Can't we do something similar for those settings? Those settings are slightly different because they need to be handled by Emscripten itself not Binaryen, but other than that the mechanism could be similar - add options to a section that linker understands, let wasm-ld take care of their collection, and read the results just once from the final object file in Emscripten rather than looking at each input. |
Apologies for drive-by comment, but this sounds more like a build system problem to me? For instance cmake's https://cmake.org/cmake/help/latest/command/target_compile_options.html That's how I usually deal with supressing warnings in depedency header files for instance (versus warnings in implementation files which can be handled with the PRIVATE mode). There's also a separate Linker dependencies behave the same ( |
@floooh Sure, such build system options are nice if you control the entire stack and rebuild all the dependencies as part of the project. But often enough a library just builds its own Think of it like |
Yeah, I actually agree. This is why I like Emscripten features like EM_JS() so much, or MSVC's/clang's But I wonder if this specific feature could have unexpected side effects, especially for people who are used to build systems taking care of this. Also I guess those options wouldn't show up on the linker command line, which might make debugging build problems more difficult. In any case, I don't have a "strong opinion" here :) |
That's a good point. I don't think these particular options would have a problem with that - e.g. you can list same function twice in In general, I feel that those being link-time option is more of a current limitation / implementation detail, which is why moving them to library compile-time seems more future-proof. For example, I can totally imagine Asyncify transform becoming smarter in the future and transforming functions within each object file in parallel, and then just doing final call graph transforms during the link phase. |
Assuming you are talking about embedded these options in the source code somehow (e.g #pragma) then yes I agree this sounds reasonable. What I would find odd is actually passing linker flags to the compiler at compile time when running |
i.e. lets follow the |
What I mean by the last comment is that these specific options don't really have to be link-time flags (or at least not just link-time flags), because the transforms they do can be actually done at compile-time in future as an optimisation. So I still think it makes sense to allow them as compile-time flags as well, except for now all they would do is internally store information for the linker. I'm not too opposed to the pragma idea, it just feels less natural for those flags. |
Which flags are you referring too? Marking certain things as part of |
Oh yeah, absolutely. I'm talking about ASYNCIFY / --bind flags themselves. |
Although... Maybe we could just imply ASYNCIFY if we found a function annotated with ASYNCIFY_IMPORTS? That could work too. And same for --bind via EMSCRIPTEN_BINDINGS. |
This would also help use-cases like #15746. |
So I think we can auto-enabled For embind, its a little harder (because part of embind is a native library which needs to part of the link). Do you think its reasonable in your use case to set This, I believe is no different to any other native library that has transitive dependencies. For example if |
While a bit unfortunate, I think that's a reasonable middle ground, I agree Embind is more of a library in that regard. Perhaps we could have a separate conversation about providing a way to link Emscripten-provided
As for this - I haven't actually checked, does this apply only to imports that depend on Embind ( |
Any code that depends on symbols in https://github.com/emscripten-core/emscripten/blob/main/system/lib/embind/bind.cpp I imagine that includes both code that uses |
I'm not actually sure what |
Hmm, turns out all that Which means the block of code will run on startup.. if the object gets included. |
Ah, but that code should still be dependent on imports from |
Although it would be good to check what the names of those imports are / what the error looks like and whether the user can understand why they're getting it & what to do next. |
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
This change introduces a new `EM_JS_DEPS` macros that can be used to specific the JS library dependencies of user code in `EM_JS` and/or `EM_ASM` blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
Did this feature ever end up making it in? In my case I have a header-only library which depends on the program linking with |
This change introduces a new EM_JS_DEPS macros that can be used to specific the JS library dependencies of user code in EM_JS and/or EM_ASM blocks. This is especially important for library authors who don't want to have their users maintain link-time list of required symbols. See #14729
Certain settings - for example,
--bind
,-s ASYNCIFY
,-s ASYNCIFY_IMPORTS=[...]
- are important for successful compilation of the final binary, that is, without those the application won't work.When a library relies on any of those features, currently there is no way it can accept & store those settings as part of its own build. Instead, it must document the list of options the user has to pass at link-time when building their application for a successful build.
This seems like an unfortunate leak of implementation details, especially so for options like
ASYNCIFY_IMPORTS
that require listing names of internal helpers used for an async work.We should find a way to instead accept those options at compile-time of each library, store them in a custom section of the object files, and then read them back and merge with other options in the linker.
cc @sbc100 @kripken
The text was updated successfully, but these errors were encountered: