[SR-6508] rpath order is inconsistent between Darwin and Linux #49058
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
good first issue
Good for newcomers
legacy driver
Area → compiler: the integrated C++ legacy driver. Succeeded by the swift-driver project
Environment
Swift 4.0.2
Additional Detail from JIRA
md5: 2e78181413954a0e98d1e8a39b2b1e69
Issue Description:
On Darwin, the swift compiler takes care to place its own rpath (the location of the swift standard library) after any user-specified rpaths.
swift/lib/Driver/ToolChains.cpp
Lines 1132 to 1160 in cdab55a
On Linux this is not the case
To reproduce, start from a new executable package (
swift package init --type executable
) (called test), and build withswift build -Xlinker -rpath -Xlinker /usr/local/lib
On macOS this produces a binary with a runtime library search path containing 2 entries, as follows:
/usr/local/lib (the user-provided search path)
the location of the swift standard library
To observe this use
otool -l
as follows:On Linux this same command produces a binary whose runtime library search path has 3 entries, as follows:
the location of the swift standard library
/usr/local/lib (the user-provided search path)
$ORIGIN
, a symbol indicating the directory containing the binary (similar to Darwin's@executable_path
).This can be observed with the
readelf
command:It seems strange that the Linux version gives a different order than the Darwin one, I would expect the order to be consistent across platforms. Furthermore, I think the Darwin order is the correct one as it allows each layer to override a lower one (a swiftPM user can override swiftPM's authors which in turn can override swiftc). It's possible that on Darwin, SwiftPM should also insert
@executable_path
between user-specified search paths and compiler-specified ones.The text was updated successfully, but these errors were encountered: