Skip to content

Commit

Permalink
[profiling] Ensure shared library name has no soname set.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexJF committed May 2, 2024
1 parent 5683b74 commit f5c7e88
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions build-profiling-ffi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ library_prefix="lib"
remove_rpath=0
fix_macos_rpath=0
symbolizer=0
strip_soname=0

# Rust provides this note about the link libraries:
# note: Link against the following native artifacts when linking against this
Expand All @@ -60,6 +61,7 @@ case "$target" in
# on alpine musl, Rust adds some weird runpath to cdylibs
remove_rpath=1
symbolizer=1
strip_soname=1
;;

"x86_64-apple-darwin"|"aarch64-apple-darwin")
Expand All @@ -75,6 +77,7 @@ case "$target" in
expected_native_static_libs=" -ldl -lrt -lpthread -lgcc_s -lc -lm -lrt -lpthread -lutil -ldl -lutil"
native_static_libs=" -ldl -lrt -lpthread -lc -lm -lrt -lpthread -lutil -ldl -lutil"
symbolizer=1
strip_soname=1
;;

"x86_64-pc-windows-msvc")
Expand Down Expand Up @@ -138,6 +141,16 @@ cp -v "$CARGO_TARGET_DIR/${target}/release/${static_library_name}" "$destdir/lib
shared_library_name="${shared_library_rename}"
static_library_name="${static_library_rename}"

# Because of the rename above, if the library has a soname (which would be set to the old name with the _ffi suffix)
# we need to remove it otherwise when dynamically loading it'll try to find a library with the _ffi suffix which won't
# exist.
# NOTE: Not all environments result in the library having a soname. Ivo and I weren't able to determine when able to
# pinpoint exactly what causes it to be there or not. But enforcing a removal here does fix identified loading
# issues on the cases where it does exist.
if [[ "$strip_soname" -eq 1 ]]; then
patchelf --set-soname "" "$destdir/lib/${shared_library_name}"
fi

if [[ "$remove_rpath" -eq 1 ]]; then
patchelf --remove-rpath "$destdir/lib/${shared_library_name}"
fi
Expand Down

0 comments on commit f5c7e88

Please sign in to comment.