-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Set SONAME for shared library on Linux #2998
Set SONAME for shared library on Linux #2998
Conversation
Fix for issue: #2996
Subscribe to Label Actioncc @peterhuene
This issue or pull request has been labeled: "wasmtime:c-api"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
Thanks! Poking around the artifacts on the CI build it looks like Before merging, though, can you explain a bit more why this is necessary? (ideally in a code comment in the build script as well). Personally I don't have any experience with this aspect of a dynamic library, so I'm curious why this hasn't also come up before! |
As I'm currently in the process of packaging Wasmtime for Fedora, I was actually looking at the exact same thing (missing Regarding this PR, I'm concerned by the fact this |
I think versioning will need to be done outside of the cargo build as cargo doesn't support renaming the shared library for the version. It always outputs |
Hi @alexcrichton, As explained in the issue 2996 the reason for this change is that shared libraries without SONAME are not easy to use within CMake. Actually, the CMake guys consider shared libraries without an SONAME as a bug. Basically, I don’t care how setting the SONAME is achieved. Using a “build.rs” script is one way of achieving this. Using “cargo-c” would also be an option. In the end, what is important, is that the downloaded libs (e.g. https://github.com/bytecodealliance/wasmtime/releases/download/v0.28.0/wasmtime-v0.28.0-x86_64-linux-c-api.tar.xz) as well as the libs built via command line (e.g. Thanks, Martin |
Right yeah I understand that CMake wants SONAME, but I'm asking a possibly depeer questions which is 'why?'. What is SONAME? Why do packagers and CMake want this value set? Why isn't it set by default in linkers? Is there a reasonable default to set? If we need to support different SONAME values depending on the context then the binary artifacts we distribute probably want to use the Basically I have no idea what SONAME is so I don't know how to answer these questions myself. |
Hi @alexcrichton , the SONAME attribute provides the name of a shared library, because the using the filename of the library has proven not to be flexible enough.
A special trick that SONAMES are used for is library versioning. You can, for example, ship a new version of a library with a filename The Wikipedia article mentions that As mentioned, the SONAME of shared libraries is read by linkers. With this information they create Hope that helps. Best regards |
Personally I'd prefer to not be in the business of versioning the ABI/API of this just yet, it's not necessarily stable enough that we track all the minutae of changing APIs over time and will remember to bump versions here and there. I still don't really understand what this field does unfortunately. I don't know why linkers don't place it in there by default, why if In any case can you add some comments to the build script as to why the value is being added? If |
A DT_NEEDED entry in an ELF file defines that a shared library is being depended on. Without the dynamic linker has no idea that the shared library is necessary at all. It's value defines the filename of the shared library as looked up in the LD_LIBRARY_PATH. |
Hi @alexcrichton , I’m terribly sorry that my educational skills aren’t good enough to explain this topic in enough depth. The problem does not appear when staying in the Rust world. It appears when libraries created in Rust are to be used in C/C++. What the Rust build-chain produces is not in line what the C/C++ world considers as a good C-ABI citizen. The already mentioned My ask is to add C-ABI compatibility to the Wasmtime library, in order to enhance its acceptance and increase its usage in the C/C++ community. This could be done via Sorry again, and best regards |
A thought on what might allow us to provide some sort of ABI version, which would allow us to produce an SONAME that can be relied upon: could we add an SONAME based on the git commit hash? E.g., if we stamped our .so with an SONAME of |
That would require the C world to rename libwasmtime.so in to that filename for the dynamic linker to be able to find it. If anything, cargo should be doing this rename and setting the SONAME. |
Sure, as part of this we would have to rename the .so to match the SONAME we choose (probably as part of our CI scripts that package up the tarball?). |
Then the SONAME should be set in CI too using |
@MartinKolbAtWork oh not your fault at all! I just find this all confusing, but it seems like we're all just catering to the gods of old who decided to design SONAME this way. I get the impression it wasn't designed for a nice user experience nowadays, but alas. @cfallin my impression of a scheme like that is that it would break |
With the caveat that I'm out of my depth here, I poked around on my own box (Fedora 34) and found that a bunch of libraries have files However I'm not able to discern how @MartinKolbAtWork perhaps you can help us out here -- would it be idiomatic to use a git-hash as a version, and if so, how might we make this work in a way that allows |
Hi @alexcrichton , @cfallin, et al, Thanks for all the comments. Let’s face today’s reality: We ship our software to production (or to customers) via containers. This container contains the application along with the exact version of the shared libraries that are needed to run the application. There’s no longer a large Linux server that applications are installed on, where we need to consider other/older versions of the same library to be present. My main goal is to make the simplest use-case very simple. The simplest use-case is that I use a shared library like “libwasmtime.so”, and I don’t care about versioning, I just use my current built/downloaded version of “libwasmtime.so” and link and package it with an application. My center of expertise is C/C++, and when @alexcrichton asked me for a PR I did my best to provide a solution that fits into the Rust universe. I saw that Wasmtime already used “build.rs” files at some places, so I simply picked that approach. I know that the same can be achieved via linker settings in “rustflags” of “.cargo/config/toml”. Another approach is using creates like “cargo-c”. As my experience in Rust is far from being an expert, I leave the final decision on how to solve this to experts like @alexcrichton . I added another commit to my PR, fixing some “cargo fmt” issues that I introduced with my explanatory comments. TL;DR Thanks, Martin |
Thank you @MartinKolbAtWork As the SONAME is something used for versioning and backwards-compatibility information, it is somewhat ironical to add it unversioned! However, I agree that it can fix your immediate concern (CMake compatibility), even if this unversioned SONAME fails its original purpose. As a proper versioning and guaranty of API compatibility adds complexity, I understand that this PR may be a simpler "fix". Regarding Fedora packaging of Wasmtime (which has to deal with ABI versioning, as any other Linux distribution), I think I'll use cargo-c, which is handy for C-ABI compatible libraries (BTW, cargo-c should support in the near future multiple pre-generated header files as used by Wasmtime). I've found out that the SONAME set in |
Hm so I think the best solution given all this might be for us to publish unversioned SONAME binaries from our CI, but to not apply a SONAME by default? That would involve running |
Hi @alexcrichton , can you explain what your suggestion means for binaries created via Thanks, Martin |
Right yeah anything built with |
Hi @alexcrichton, We have not taken a final decision yet, but usually we prefer building software on our own machines, with toolchains curated to our needs. Currently we build the c-api part: This means that the suggested solution will not work for us. But actually, I don’t want to push too much for a solution that might be a specific solution for our use-case only. Thanks for your time and your support. |
I think |
@MartinKolbAtWork does @bjorn3's command work for you? That should effectively do the same thing as this PR when executed locally. |
Hi @alexcrichton and @bjorn3 , Thanks for your hints. The statement mentioned by @bjorn3 creates indeed a However, doing it this way is just another workaround, that is no improvement compared to the workaround that I can use on CMake side. Using cargo to build the needed packages is one thing, but passing compiler/linker commands breaks encapsulation, because you need white-box knowledge to know if this works. If, in the future, there should be changes in the internal compiler/linker settings inside the builds, this setting might even interfere with these. I assumed that the Wasmtime committers have the intention to make the usage of I’m a big fan of Wasmtime, and I think to promote the success of Wasmtime, you have to make it as easy as possible to use it. Providing the SONAME at packaging time is IMO a step in the right direction, but it does not help people who build Wasmtime on their own. I assume that my PR which tries to integrate SONAME via Thanks for the time and energy that you spent on my request and thanks for your suggestions and workarounds. Best, Martin |
Hi @alexcrichton, could you please link any updates or PRs related to the SONAME (e.g. the suggested plan to add the SONAME thru packaging) to the issue I opened: #2996 Thanks, |
Sure yeah, FWIW I still think this is worthwhile to do as part of the release build process, even if we don't necessarily do it by default, but it's fine for that to happen as a future PR. |
Fix for issue:
#2996