-
Notifications
You must be signed in to change notification settings - Fork 845
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
Linux: Missing SONAME in "libwasmer.so" hinders usage in CMake #2429
Comments
See wasmerio#2429 for more context. I'm copy-pasting the original comment from @MartinKolbAtWork here: > The shared library `libwasmer.so` does not have an `SONAME` > specified. This can be checked using this command: `objdump -p > libwasmer.so | grep SONAME` > > When `libwasmer.so` is consumed in CMake, the **linker produces a > wrong output file due to the missing SONAME**. There is a > workaround for this in CMake, but according to a reply from the > CMake folks, the missing SONAME is a bug that must be fixed by the > library provider: > https://gitlab.kitware.com/cmake/cmake/-/issues/22307#note_971562 > “_The libwasmer.so file should have a SONAME. If it doesn't, that's > a bug in the wasmer package_” > > The problem is **inherent for all Rust builds of cdylibs**: > rust-lang/cargo#5045 The Rust community > did not fix this since 2018 (see issue above), but fortunately it’s > **easy to fix** for library creators. You just need to put the > following code into the `build.rs` of the library: > > ``` > if cfg!(target_os = "linux") { > println!("cargo:rustc-cdylib-link-arg=-Wl,-soname,libwasmer.so"); > } > ``` > > I tried putting these lines into `lib/c-api/build.rs`, and then > `libwasmer.so` was built correctly, including a SONAME entry.
See wasmerio#2429 for more context. I'm copy-pasting the original comment from @MartinKolbAtWork here: > The shared library `libwasmer.so` does not have an `SONAME` > specified. This can be checked using this command: `objdump -p > libwasmer.so | grep SONAME` > > When `libwasmer.so` is consumed in CMake, the **linker produces a > wrong output file due to the missing SONAME**. There is a > workaround for this in CMake, but according to a reply from the > CMake folks, the missing SONAME is a bug that must be fixed by the > library provider: > https://gitlab.kitware.com/cmake/cmake/-/issues/22307#note_971562 > “_The libwasmer.so file should have a SONAME. If it doesn't, that's > a bug in the wasmer package_” > > The problem is **inherent for all Rust builds of cdylibs**: > rust-lang/cargo#5045 The Rust community > did not fix this since 2018 (see issue above), but fortunately it’s > **easy to fix** for library creators. You just need to put the > following code into the `build.rs` of the library: > > ``` > if cfg!(target_os = "linux") { > println!("cargo:rustc-cdylib-link-arg=-Wl,-soname,libwasmer.so"); > } > ``` > > I tried putting these lines into `lib/c-api/build.rs`, and then > `libwasmer.so` was built correctly, including a SONAME entry.
See wasmerio#2429 for more context. I'm copy-pasting the original comment from @MartinKolbAtWork here: > The shared library `libwasmer.so` does not have an `SONAME` > specified. This can be checked using this command: `objdump -p > libwasmer.so | grep SONAME` > > When `libwasmer.so` is consumed in CMake, the **linker produces a > wrong output file due to the missing SONAME**. There is a > workaround for this in CMake, but according to a reply from the > CMake folks, the missing SONAME is a bug that must be fixed by the > library provider: > https://gitlab.kitware.com/cmake/cmake/-/issues/22307#note_971562 > “_The libwasmer.so file should have a SONAME. If it doesn't, that's > a bug in the wasmer package_” > > The problem is **inherent for all Rust builds of cdylibs**: > rust-lang/cargo#5045 The Rust community > did not fix this since 2018 (see issue above), but fortunately it’s > **easy to fix** for library creators. You just need to put the > following code into the `build.rs` of the library: > > ``` > if cfg!(target_os = "linux") { > println!("cargo:rustc-cdylib-link-arg=-Wl,-soname,libwasmer.so"); > } > ``` > > I tried putting these lines into `lib/c-api/build.rs`, and then > `libwasmer.so` was built correctly, including a SONAME entry.
See wasmerio#2429 for more context. I'm copy-pasting the original comment from @MartinKolbAtWork here: > The shared library `libwasmer.so` does not have an `SONAME` > specified. This can be checked using this command: `objdump -p > libwasmer.so | grep SONAME` > > When `libwasmer.so` is consumed in CMake, the **linker produces a > wrong output file due to the missing SONAME**. There is a > workaround for this in CMake, but according to a reply from the > CMake folks, the missing SONAME is a bug that must be fixed by the > library provider: > https://gitlab.kitware.com/cmake/cmake/-/issues/22307#note_971562 > “_The libwasmer.so file should have a SONAME. If it doesn't, that's > a bug in the wasmer package_” > > The problem is **inherent for all Rust builds of cdylibs**: > rust-lang/cargo#5045 The Rust community > did not fix this since 2018 (see issue above), but fortunately it’s > **easy to fix** for library creators. You just need to put the > following code into the `build.rs` of the library: > > ``` > if cfg!(target_os = "linux") { > println!("cargo:rustc-cdylib-link-arg=-Wl,-soname,libwasmer.so"); > } > ``` > > I tried putting these lines into `lib/c-api/build.rs`, and then > `libwasmer.so` was built correctly, including a SONAME entry.
See #2430 for the bug fix. Can you please help us to see if it fixes your issue? Thanks! |
We need to investigate to see if it's worth it :-). Thank you for the proposal! |
Hi @Hywan, Thanks for your fast response. To adjust the
Maybe you should consider using my original change in the Thanks, Martin |
Did you try to ˋcargo clean` before rebuilding the library? I'm surprised it doesn't work. |
Yes, I did a clean build. I'm actually not surprised, because IHMO, the settings from Makefile override the otherwise provided settings. You can try the Makefile build on your own:
After the two build steps, simply check with objdump if SONAME is present: Thanks, Martin |
Hi @Hywan and @syrusakbary, thanks for the provided fix.
After the two build steps, you can check with objdump that SONAME is not present: Could you please reopen the issue and consider the solution that I suggested (using build.rs) or any other solution that works via the Makefile build? Thanks, Martin |
I'm surprised it doesn't work because the |
Meanwhile I'm making sure If you do not want to use it please consider using https://crates.io/crates/cdylib-link-lines instead of hand-crafting. |
Ah nice. Why aren't you using this crate to replace this code https://github.com/lu-zero/cargo-c/blob/03823d03add503326c82045f8a4edfadecdc35dc/src/target.rs#L54-L91 :-) (honest question)? |
I wrote both, ideally I could make a new release of cdylib-link-lines that is in sync with the current cargo-c if there are enough users. |
I'm more concerned about the impact on the CI when compiling |
Pull requests are always welcome :) You can fetch the pre-built cargo-c from the releases and it would have a negligible impact. It would reduce the build time if you could move away some of the custom header logic, but that could be the discussion for another issue I guess :) |
As discussed in wasmerio/wasmer#2429 (comment), it would be ideal if this crate could get synchronized with `cargo-c` which has a very similar code but which supports more targets. That's exactly what this patch does. It changes the code from a `if`+`else` workflow to a `match` version. It also adds support for `android`, `freebsd`, `dragonfly`, `netbsd` and `ios`.
@lu-zero I've updated |
As discussed in wasmerio/wasmer#2429 (comment), it would be ideal if this crate could get synchronized with `cargo-c` which has a very similar code but which supports more targets. That's exactly what this patch does. It changes the code from a `if`+`else` workflow to a `match` version. It also adds support for `android`, `freebsd`, `dragonfly`, `netbsd` and `ios`.
In #2449, I'm using the |
Hi @Hywan, thanks for providing the fix #2449 Let me share some thoughts on this: (1) The (clean) build with this fix included does not create an “libwasmer.so” that has an SONAME. (2) To check if the SONAME is present, the following three statements will do a perfect job. If objdump/grep does not emit any output, then no SONAME is present.
(3) Looking at the code changes, I observed that
Calling
(4) The modified code in
Having an SONAME of “libwasmer.so.2” and the actual file name is “libwasmer.so” will cause client code to break. The client code will compile and link, but at runtime the client program will no longer start. Such an error message will appear:
(5) Creating versioned SONAMES (like libwasmer.so.2) will make life more complicated for both Wasmer development, as well as client code using Wasmer’s shared libraries. SUGGESTION
If you don’t like my suggestion, I’m perfectly fine with this. I can easily live with the CMake workaround that allows me to use “libwasmer.so”. Best, |
@MartinKolbAtWork I've tried this, and the CI doesn't like it. If you've got any idea why, it might be good to share it. (I thought it's because the SONAME doesn't match the output file name (which is |
@MartinKolbAtWork Yeah sorry, it's a stupid error… My Linux machine is now repaired and I can test it. The problem is that real library name is |
OK, #2457 should fix everything. By renaming |
@MartinKolbAtWork Thank you for your patience and for the feature request! |
The shared library
libwasmer.so
does not have anSONAME
specified. This can be checked using this command:objdump -p libwasmer.so | grep SONAME
When
libwasmer.so
is consumed in CMake, the linker produces a wrong output file due to the missing SONAME.There is a workaround for this in CMake, but according to a reply from the CMake folks, the missing SONAME is a bug that must be fixed by the library provider:
https://gitlab.kitware.com/cmake/cmake/-/issues/22307#note_971562
“The libwasmer.so file should have a SONAME. If it doesn't, that's a bug in the wasmer package”
The problem is inherent for all Rust builds of cdylibs: rust-lang/cargo#5045
The Rust community did not fix this since 2018 (see issue above), but fortunately it’s easy to fix for library creators. You just need to put the following code into the
build.rs
of the library:I tried putting these lines into
lib/c-api/build.rs
, and thenlibwasmer.so
was built correctly, including a SONAME entry.Could you please fix this issue?
Thanks
Martin
The text was updated successfully, but these errors were encountered: