Skip to content

Commit

Permalink
Add target libraries/executables to executable's RPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
billysuh7 committed Nov 6, 2024
1 parent 64a8bb4 commit 2ebc6ea
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 2 deletions.
2 changes: 1 addition & 1 deletion conda-forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build_platform:
linux_aarch64: linux_64
linux_ppc64le: linux_64
conda_build:
error_overlinking: true
error_overlinking: false
conda_forge_output_validation: true
github:
branch_name: main
Expand Down
24 changes: 24 additions & 0 deletions recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ for i in `ls`; do
mkdir -p ${PREFIX}/${targetsDir}
mkdir -p ${PREFIX}/$i
if [[ $i == "bin" ]]; then
for j in `ls "${i}"`; do
[[ -f "bin/${j}" ]] || continue

if grep -qx "${j}" ${RECIPE_DIR}/patchelf_exclude.txt; then
echo "Skipping bin/${j} as it is in the patchelf exclusion list."
continue
fi

echo patchelf --force-rpath --set-rpath "\$ORIGIN/../lib:\$ORIGIN/../${targetsDir}/lib" "${i}/${j}" ...
patchelf --force-rpath --set-rpath "\$ORIGIN/../lib:\$ORIGIN/../${targetsDir}/lib" "${i}/${j}"
done

mkdir -p ${PREFIX}/${targetsDir}/bin
cp -rv $i ${PREFIX}
ln -sv ${PREFIX}/bin/nvcc ${PREFIX}/${targetsDir}/bin/nvcc
Expand All @@ -29,6 +41,18 @@ for i in `ls`; do
elif [[ $i == "include" ]]; then
cp -rv $i ${PREFIX}/${targetsDir}
elif [[ $i == "nvvm" ]]; then
for j in `find "${i}"`; do
if [[ "${j}" =~ /bin/.*$ ]]; then
echo patchelf --force-rpath --set-rpath "\$ORIGIN/../lib64:\$ORIGIN/../../lib:\$ORIGIN/../../${targetsDir}/lib" "${j}" ...
patchelf --force-rpath --set-rpath "\$ORIGIN/../lib64:\$ORIGIN/../../lib:\$ORIGIN/../../${targetsDir}/lib" "${j}"

# Do not patch libnvvm.so for now as it gets corrupted by patchelf. See build.sh for details
#elif [[ "${j}" =~ /lib.*/.*\.so($|\.) && ! -L "${j}" ]]; then
# echo patchelf --force-rpath --set-rpath "\$ORIGIN" "${j}" ...
# patchelf --force-rpath --set-rpath "\$ORIGIN" "${j}"
fi
done

cp -rv $i ${PREFIX}
ln -sv ${PREFIX}/nvvm ${PREFIX}/${targetsDir}/nvvm
fi
Expand Down
14 changes: 13 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ source:
- nvcc.profile.patch.win # [win]

build:
number: 1
number: 2
binary_relocation: false
skip: true # [osx or ppc64le]

outputs:
Expand All @@ -56,9 +57,15 @@ outputs:
- gcc_impl_{{ target_platform }} {{ gcc_constraint }} # [linux]
- arm-variant * {{ arm_variant_type }} # [aarch64]
test:
requires:
- patchelf # [linux]
files:
- patchelf_exclude.txt # [linux]
- test-rpath-nvcc.sh # [linux]
commands:
- test -f $PREFIX/bin/nvcc # [linux]
- test -f $PREFIX/bin/ptxas # [linux]
- bash test-rpath-nvcc.sh # [linux]
about:
home: https://developer.nvidia.com/cuda-toolkit
license_file: LICENSE
Expand Down Expand Up @@ -259,9 +266,14 @@ outputs:
run_constrained:
- arm-variant * {{ arm_variant_type }} # [aarch64]
test:
requires:
- patchelf # [linux]
files:
- test-rpath-nvvm.sh # [linux]
commands:
- test -d $PREFIX/nvvm # [linux]
- test -f $PREFIX/nvvm/bin/cicc # [linux]
- bash test-rpath-nvvm.sh # [linux]
- if not exist %LIBRARY_PREFIX%\nvvm\bin\cicc.exe exit 1 # [win]
- if not exist %LIBRARY_PREFIX%\nvvm\libdevice exit 1 # [win]
about:
Expand Down
4 changes: 4 additions & 0 deletions recipe/patchelf_exclude.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
crt/link.stub
crt/prelink.stub
nvcc.profile
patchelf
43 changes: 43 additions & 0 deletions recipe/test-rpath-nvcc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

[[ ${target_platform} == "linux-64" ]] && targetsDir="targets/x86_64-linux"
[[ ${target_platform} == "linux-ppc64le" ]] && targetsDir="targets/ppc64le-linux"
[[ ${target_platform} == "linux-aarch64" ]] && targetsDir="targets/sbsa-linux"

errors=""

for item in `find ${PREFIX}/bin -type f`; do
filename=$(basename "${item}")
echo "Artifact to test: ${filename}"

if grep -qx "${filename}" patchelf_exclude.txt; then
echo Skipping ${filename} as it is not subject to testing
continue
fi

pkg_info=$(conda package -w "${item}")
echo "\$PKG_NAME: ${PKG_NAME}"
echo "\$pkg_info: ${pkg_info}"

if [[ ! "$pkg_info" == *"$PKG_NAME"* ]]; then
echo "Not a match, skipping ${item}"
continue
fi

echo "Match found, testing ${item}"

rpath=$(patchelf --print-rpath "${item}")
echo "${item} rpath: ${rpath}"

if [[ ${item} =~ /bin/ && $rpath != "\$ORIGIN/../lib:\$ORIGIN/../${targetsDir}/lib" ]]; then
errors+="${item}\n"
elif [[ $(objdump -x ${item} | grep "PATH") == *"RUNPATH"* ]]; then
errors+="${item}\n"
fi
done

if [[ $errors ]]; then
echo "The following items were found with an unexpected RPATH:"
echo -e "${errors}"
exit 1
fi
41 changes: 41 additions & 0 deletions recipe/test-rpath-nvvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

[[ ${target_platform} == "linux-64" ]] && targetsDir="targets/x86_64-linux"
[[ ${target_platform} == "linux-ppc64le" ]] && targetsDir="targets/ppc64le-linux"
[[ ${target_platform} == "linux-aarch64" ]] && targetsDir="targets/sbsa-linux"

errors=""

for item in `find ${PREFIX}/nvvm/bin -type f`; do
filename=$(basename "${item}")
echo "Artifact to test: ${filename}"

pkg_info=$(conda package -w "${item}")
echo "\$PKG_NAME: ${PKG_NAME}"
echo "\$pkg_info: ${pkg_info}"

if [[ ! "$pkg_info" == *"$PKG_NAME"* ]]; then
echo "Not a match, skipping ${item}"
continue
fi

echo "Match found, testing ${item}"

rpath=$(patchelf --print-rpath "${item}")
echo "${item} rpath: ${rpath}"

if [[ ${item} =~ /nvvm/bin/ && $rpath != "\$ORIGIN/../lib64:\$ORIGIN/../../lib:\$ORIGIN/../../${targetsDir}/lib" ]]; then
errors+="${item}\n"
# lib64/libnvvm.so patching is being skipped so let's not test it
#elif [[ ${item} =~ nvvm/lib64/ && $rpath != "\$ORIGIN" ]]; then
# errors+="${item}\n"
elif [[ $(objdump -x ${item} | grep "PATH") == *"RUNPATH"* ]]; then
errors+="${item}\n"
fi
done

if [[ $errors ]]; then
echo "The following items were found with an unexpected RPATH:"
echo -e "${errors}"
exit 1
fi

0 comments on commit 2ebc6ea

Please sign in to comment.