33
44# Configuration
55KERNEL_VERSION=" ${1:- 5.10.217} "
6- QEMU_ARCH=" ${QEMU_ARCH:- x86_64} "
6+ # Auto-detect host architecture if QEMU_ARCH not set.
7+ case " $( uname -m) " in
8+ x86_64) _default_arch=" x86_64" ;;
9+ aarch64) _default_arch=" aarch64" ;;
10+ * ) _default_arch=" x86_64" ;;
11+ esac
12+ QEMU_ARCH=" ${QEMU_ARCH:- $_default_arch } "
713DISTRO=" ${DISTRO:- ubuntu} " # debian or ubuntu
814RELEASE=" ${RELEASE:- jammy} " # jammy/noble for ubuntu (with USDT probes), bullseye for debian
915ROOTFS_DIR=$( mktemp -d /tmp/distro-qemu-rootfs.XXXXXX)
@@ -24,7 +30,7 @@ cleanup() {
2430trap cleanup EXIT
2531
2632# Download parcagpu library
27- PARCAGPU_DIR=" ${PARCAGPU_DIR} " ./download-parcagpu.sh
33+ QEMU_ARCH= " ${QEMU_ARCH} " PARCAGPU_DIR=" ${PARCAGPU_DIR} " ./download-parcagpu.sh
2834
2935echo " Building rootfs with $DISTRO $RELEASE ..."
3036
@@ -65,14 +71,13 @@ if ! sudo debootstrap --variant=minbase \
6571 --arch=" $DEBOOTSTRAP_ARCH " \
6672 --cache-dir=" $CACHE_DIR " \
6773 --foreign \
74+ --include=libstdc++6 \
6875 " $RELEASE " " $ROOTFS_DIR " " $MIRROR " ; then
6976 echo " Debootstrap failed, log follows."
7077 cat " $ROOTFS_DIR /debootstrap/debootstrap.log"
7178 exit 1
7279fi
7380
74-
75-
7681# Change ownership of rootfs to current user to avoid needing sudo for subsequent operations
7782sudo chown -R " $( id -u) :$( id -g) " " $ROOTFS_DIR "
7883
124129cp " ${OUTPUT_DIR} " /* .test " $ROOTFS_DIR /"
125130cp " ${PARCAGPU_DIR} /libparcagpucupti.so" " $ROOTFS_DIR /"
126131
127- # Copy stub libcupti .so next to the .so (for the test's preload logic) and
128- # into the RUNPATH (/usr/local/cuda/lib64) as a fallback for the dynamic linker .
132+ # Copy stub libcupti .so into the RUNPATH (/usr/local/cuda/lib64) so the
133+ # dynamic linker resolves the DT_NEEDED entry without a real CUDA install .
129134mkdir -p " $ROOTFS_DIR /usr/local/cuda/lib64"
130135for stub in " ${PARCAGPU_DIR} " /libcupti.so* ; do
131- [ -f " $stub " ] && cp " $stub " " $ROOTFS_DIR /" && cp " $stub " " $ROOTFS_DIR / usr/local/cuda/lib64/"
136+ [ -f " $stub " ] && cp " $stub " " $ROOTFS_DIR /usr/local/cuda/lib64/"
132137done
133138
139+ # Copy libstdc++ into the RUNPATH so the dynamic linker finds it.
140+ # Cross-arch debootstrap doesn't run ldconfig, leaving ld.so.cache incomplete,
141+ # so multiarch paths like /usr/lib/aarch64-linux-gnu/ aren't searched.
142+ LIBSTDCXX=$( find " $ROOTFS_DIR " -name ' libstdc++.so.6*' -type f | head -1)
143+ if [ -n " $LIBSTDCXX " ]; then
144+ cp " $LIBSTDCXX " " $ROOTFS_DIR /usr/local/cuda/lib64/"
145+ echo " Copied $( basename " $LIBSTDCXX " ) to RUNPATH"
146+ fi
147+
134148# List dynamic dependencies for debugging
135149echo " Test binary dependencies:"
136150ldd " ${OUTPUT_DIR} /rtld.test" || true
@@ -160,6 +174,10 @@ mount -t proc proc /proc 2>/dev/null || true
160174mount -t sysfs sys /sys 2>/dev/null || true
161175mount -t debugfs debugfs /sys/kernel/debug 2>/dev/null || true
162176
177+ # Rebuild ld.so cache so the linker finds libraries in multiarch paths
178+ # (e.g. /usr/lib/aarch64-linux-gnu/libstdc++.so.6).
179+ ldconfig 2>/dev/null || true
180+
163181# Enable debug logging
164182export DEBUG_TEST=1
165183
0 commit comments