SnowflakePowered / librashader

RetroArch Shaders for All
Mozilla Public License 2.0
77 stars 7 forks source link

glslang (and spirv-cross) may not be linked statically as expected. #76

Closed Mastergatto closed 2 months ago

Mastergatto commented 3 months ago

I have received reports on the failure of loading librashader on Ares, from users that use an Archlinux derivative (Manjaro, CachyOS), and have installed Ares from AUR. Which means they have also installed librashader from AUR, as it is a dependency.

The failure seems to be due to some missing symbols related to GLSL. It seems that glslang is not linked statically during the building of librashader, and thus when starting Ares the library attempts to resolve these symbols at runtime and fails.

The strange thing is that on my system this library seems to work without issues, the shaders and everything. For instance, the size of the generated .so on my PC was 18312640 (from ls -l), while to one of these users it was 14225888 instead.

I'm trying to understand why this behavior seems to be inconsistent across systems, do you have any clue on how to fix this issue? I'm not very familiar with rust, and I'm a bit at loss.

chyyran commented 3 months ago

For reference the glslang bindings are here: https://github.com/SnowflakePowered/glslang-rs

The spirv_cross bindings are here: https://github.com/chyyran/spirv_cross

I was also unable to reproduce this with a fresh Arch container but I suspect its a linker problem more than a Rust problem. If you build with cargo build -vv you can see the output from the linker and see if theres any issues there.

chyyran commented 3 months ago

Maybe its an lto issue? https://bbs.archlinux.org/viewtopic.php?id=265506

Could try building with the release profile over the optimized profile.

Mastergatto commented 3 months ago

Unfortunately the proposed solution doesn't work.

Could this answer on Stackoverflow help with the issue? https://stackoverflow.com/questions/70175641/how-do-i-always-include-a-rust-dependency-when-linking/70179201#70179201

chyyran commented 3 months ago

The StackOverflow solution doesn’t apply to linking C libraries statically, it’s purely for linking Rust libraries.

Linkage paths to C libraries are specified by printing cargo directives which then pass the flags to the system linker:

https://github.com/SnowflakePowered/glslang-rs/blob/master/glslang-sys/build.rs

Either there’s an issue with the output path of the archive not being in the expected place or the link flags are not being passed correctly.

You’ll need the output from cargo build -vv to debug this.

Mastergatto commented 3 months ago

One of the users on Discord kindly has sent me the log of "cargo build -vv" on their system, that I'm attaching here. RUSTC_BOOTSTRAP1_cargobuild-vv.log

chyyran commented 2 months ago

Fixed by disabling LTO in the PKGBUILD