diff options
author | Ben Hutchings <ben@decadent.org.uk> | 2020-08-29 20:11:26 +0100 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2020-08-29 22:37:26 +0100 |
commit | 9b0bdf020ee950e801868e9220c19ae5711b48f6 (patch) | |
tree | e88779fec3f00c7859595564d8eb85db4ce99c7d | |
parent | 71f13bab4da165c80bd17aa2e5ff8d0798038633 (diff) | |
download | klibc-maint-9b0bdf020ee950e801868e9220c19ae5711b48f6.tar.gz |
test-many-klibcs: Use patchelf to allow running shared-library binaries
Building a chroot requires using sudo, which is a bit unfortunate.
Instead, use patchelf to edit the interpreter filename so we can
run shared-library binaries without installing klibc.so.
-rwxr-xr-x | test-many-klibcs | 69 |
1 files changed, 11 insertions, 58 deletions
diff --git a/test-many-klibcs b/test-many-klibcs index 0c56e8c..c396495 100755 --- a/test-many-klibcs +++ b/test-many-klibcs @@ -5,7 +5,7 @@ # * LLVM toolchain (clang, lld) # * QEMU user-space static binaries (qemu-user-static) # * rsync -# * sudo +# * patchelf build_gnu() { echo "I: Using $("$toolsarch-gcc" --version | head -1)" @@ -40,44 +40,6 @@ build_llvm() { || return } -do_install() { - # Set up a tmpfs in case the current filesystem is mounted nodev - mkdir -p install - if mountpoint install >/dev/null; then - find install -xdev -mindepth 1 -delete || return - else - sudo mount -t tmpfs tmpfs install || return - fi - - # Install klibc itself - make -C "build/$tools-$toolsarch" -f "$PWD/../klibc/Makefile" \ - "ARCH=$arch" "CROSS_COMPILE=$toolsarch-" "KBUILD_SRC=$PWD/../klibc" \ - "${makeflags[@]}" INSTALLROOT="$PWD/install" install \ - || return - - # Install shared-library tests - mkdir install/tests - cp "build/$tools-$toolsarch/usr/klibc/tests"/*.shared install/tests/ || return - - # Some tests need these - mkdir -p install/dev - sudo mknod -m 666 install/dev/null c 1 3 - sudo mknod -m 666 install/dev/zero c 1 5 - mkdir -p install/etc - head -1 /etc/passwd > install/etc/passwd - - # Install statically-linked QEMU inside - case "$arch" in - i386 | x86_64) - ;; - *) - mkdir -p install/bin - install "$(command -v "qemu-$qemuarch-static")" install/bin/ \ - || return - ;; - esac -} - clean() { echo "I: Cleaning" (cd ../klibc && git clean -d -f -x) @@ -96,21 +58,9 @@ run_built() { esac } -run_installed() { - local useropt - - useropt="--userspec=$(id -un):$(id -gn)" - - # XXX We assume build architecture is x86_64 - case "$arch" in - i386 | x86_64) - sudo chroot "$useropt" -- install "$@" - ;; - *) - sudo ${QEMU_CPU:+QEMU_CPU=$QEMU_CPU} chroot "$useropt" -- install "/bin/qemu-$qemuarch-static" -- \ - "$@" - ;; - esac +patch_interp() { + patchelf --set-interpreter "$PWD/build/$tools-$toolsarch/usr/klibc/klibc.so" \ + "$@" } run_test_program() { @@ -126,7 +76,8 @@ run_test_program() { || err=$? ;; shared) - run_installed /tests/"$progname".shared > "$logname" \ + patch_interp "build/$tools-$toolsarch/usr/klibc/tests/$progname.shared" + run_built "build/$tools-$toolsarch/usr/klibc/tests/$progname.shared" > "$logname" \ || err=$? ;; esac @@ -164,7 +115,8 @@ run_shell_static() { run_shell_shared() { local command="$1" - if run_installed /usr/lib/klibc/bin/sh -c "$command"; then + patch_interp "build/$tools-$toolsarch/usr/dash/shared/sh" + if run_built "build/$tools-$toolsarch/usr/dash/shared/sh" -c "$command"; then echo "I: shell '$command': pass" else echo "E: shell '$command': fail" @@ -210,7 +162,8 @@ run_tests() { run_tests_flavour shared || err=1 run_shell_shared "exit" || err=1 - run_shell_shared "/usr/lib/klibc/bin/true; exit" || err=1 + patch_interp "build/$tools-$toolsarch/usr/utils/shared/true" + run_shell_shared "build/$tools-$toolsarch/usr/utils/shared/true; exit" || err=1 return $err } @@ -235,7 +188,7 @@ process() { esac echo "I: Architecture $arch/$tools-$toolsarch: begin" - if clean && build_$tools && do_install && run_tests; then + if clean && build_$tools && run_tests; then echo "I: Architecture $arch/$tools-$toolsarch: pass" else echo "E: Architecture $arch/$tools-$toolsarch: fail" |