Skip to content

Commit

Permalink
add test for correct glibc bound
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Nov 28, 2024
1 parent b7dd1ca commit 65e6c5d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test:
requires:
- patchelf # [linux]
files:
- test-glibc-bound.sh
- test-rpath-main.sh
commands:
# Note that the version of libcufile does not match
Expand All @@ -41,6 +42,7 @@ test:
- test -f $PREFIX/targets/{{ target_name }}/lib/libcufile.so.{{ full_version }}
- test -f $PREFIX/targets/{{ target_name }}/lib/libcufile_rdma.so.{{ full_version }}
- bash test-rpath-main.sh
- bash test-glibc-bound.sh

outputs:
- name: libcufile
Expand Down
26 changes: 26 additions & 0 deletions recipe/test-glibc-bound.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
set -ex

LIB_PATH=$PREFIX/lib/libcufile.so.0
# resolve symlinks
LIB_PATH=$(readlink -f $LIB_PATH)
# the upper bound of glibc symbols that we find linked in the library
# may at most be the same as c_stdlib_version, which is the lower bound
# at runtime enforced by the package metadata
GLIBC_UPPER_BOUND=${c_stdlib_version}

# get glibc versions from the symbols linked in the library; entries look like
# 212: 0000000000000000 0 FUNC GLOBAL DEFAULT UND log2f@GLIBC_2.27 (14)
# 235: 0000000000000000 0 FUNC GLOBAL DEFAULT UND fopen@GLIBC_2.17 (3)
found_versions=$(readelf -Ws $LIB_PATH | sed -n 's/.*@GLIBC_\([0-9.]*\).*/\1/p' | sort -u)
# check that we've actually found something
[[ $(echo "$found_versions" | wc -l) -lt 1 ]] && exit 1

# Compare each version we found against the upper bound
for version in $found_versions; do
# if `max(ver, upper) != upper`, we found a violation
if [[ $(printf '%s\n' "$version" "$GLIBC_UPPER_BOUND" | sort -V | tail -n 1) != "$GLIBC_UPPER_BOUND" ]]; then
echo "Error: Found symbol from glibc $version, which exceeds upper bound $GLIBC_UPPER_BOUND."
exit 1
fi
done

0 comments on commit 65e6c5d

Please # to comment.