Open LukeMauldin opened 3 years ago
Update - I modified the custom linker script to also strip out -Wl,--as-needed
linker option and that allowed the Rust executable to run like the C executable. I think this issue should remain open because I would like Rust to support these options via configuration OOTB rather than requiring a custom linking script.
Working linker script:
#!/bin/bash
declare -a FILTERARGS
for ITEM in "$@"
do
case "$ITEM" in
-Wl,-znow|-Wl,-zrelro|-Wl,--as-needed)
# do nothing
;;
*)
FILTERARGS+=("$ITEM")
;;
esac
done
echo "invoking: cc ${FILTERARGS[@]}"
cc ${FILTERARGS[@]}
For reference see discussion: https://users.rust-lang.org/t/linux-executable-lazy-loading/65621/24
Summary: On Linux x64 using either Rust 1.55 or Rust 1.57 nightly (a8f2463c6 2021-10-09), I have a simple Rust program that compiles and links against C libraries provided by a software vendor. The Rust program fails to run with
undefined symbol
errors even though theLD_LIBRARY_PATH
is setup correctly. I have built a similar C program which links and runs as expected. Initially it was assumed the problem was due toRELRO
but I wrote a custom linker script that strips off theRELRO
link options and the Rust binary still fails to run. See the linker commands and readelf outputs below.Additional information: The RHEL 7.9 is being used for the Rust and C program compiles. The vendor libraries being linked against are pretty old and were originally built on Suse 10 SP2. The vendor has provided an updated set of libraries that were built on RHEL 7.4 and I verified the Rust program compiled, linked, and runs as expected against the newer vendor libraries. Unfortunately, I need to get Rust linking/running against the older version of the vendor libraries because that is the version of the application still in use by the business. I think the issue is somehow related to the age of the vendor libraries but both C and Go programs (using CGO) will link and run against the vendor libraries and so I think Rust should as well.
Rust linker command:
Custom linker script:
Rust readelf -d
Rust readelf -l
C readelf -d
C readelf -l