zig icon indicating copy to clipboard operation
zig copied to clipboard

Prevent native paths from ending up on the rpath

Open Jan200101 opened this issue 3 years ago • 1 comments

Right now Zig puts native paths on the rpath if either -feach-lib-rpath is passed or the compile is happening for the native OS

On Fedora this will cause errors while packaging because they consider it to be broken (https://fedoraproject.org/wiki/Changes/Broken_RPATH_will_fail_rpmbuild), Debian discourages it when possible (https://wiki.debian.org/RpathIssue), Gentoo and Arch do not appear to have a clear answer but commit logs show that rpaths have been removed from packages in the past.

This also appears to cause portability issues when a binary is compiled on a different distro than it is run on. For example, if a Zig binary that links against SDL2 is compiled on x86_64 Debian it will add /usr/lib to the rpath, which is the 32 bit lib dir on Fedora.

The fix used for the 0.9.1 package in Fedora was #10621 which was reverted (#11265) because it introduced a regression with nixOS since "NativePaths" appears to disect the NIX CFLAGS and LDFLAGS to find where libraries are stored and add them to the rpath.


Since #10621 (which no longer appears to work on 0.10.0) is a regression, what would be the proper way to implement this to curb these issues?

Jan200101 avatar Nov 06 '22 19:11 Jan200101

Looked into what else added onto the rpath, and it appears that build.zig links the resulting binary against libstdc++.so which results in its path being added to the rpath.

https://github.com/ziglang/zig/blob/1d680459197e7ba5e163d99e07fdfe54c2ad9225/lib/std/build.zig#L2552-L2562

On Fedora libstdc++.so is stored under /usr/lib/gcc/x86_64-redhat-linux/12 as a symlink to /usr/lib64/libstdc++.so.6.0.30, so the code isn't wrong about adding an rpath here (since that specific dir is not in the linker path as far as I am aware) but it might be worthwhile to attempt to resolve the symlink and check if the path is part of the FHS.

Jan200101 avatar Nov 07 '22 07:11 Jan200101

Fix reverted in ae2cd5fe263e9d8ddd5719b4795f9cd39b5c0324

andrewrk avatar Oct 19 '23 06:10 andrewrk