Containerfile (4678B)
1 # test/libc/glibc/Containerfile — produces a glibc aarch64 sysroot tarball 2 # on stdout. Pinned to Debian bookworm (glibc 2.36). 3 # 4 # Usage (driven by test/libc/glibc/extract.sh): 5 # podman build --platform linux/arm64 -f Containerfile -t kit-glibc-sysroot . 6 # podman run --rm kit-glibc-sysroot > sysroot.tar 7 # 8 # The image's ENTRYPOINT writes a tar of /sysroot to stdout. The extract 9 # script unpacks it into build/glibc-sysroot/ on the host. 10 # 11 # Notes about glibc on Debian (vs. the musl/Alpine variant): 12 # - libc is split across libc.so.6 (the dynamic SO) and 13 # libc_nonshared.a (a few non-shared callbacks pulled in by every 14 # dynamic exe — atexit, __stack_chk_fail_local, etc.). We write a 15 # libc.so linker script that GROUPs them so `clang -lc` resolves 16 # correctly; kit ld links libc.so.6 by path and ignores the script. 17 # - The runtime loader is /lib/ld-linux-aarch64.so.1, distinct from 18 # libc (unlike musl, where ld-musl-aarch64.so.1 *is* libc). That 19 # means the dynamic-link variant of the harness must pass 20 # -dynamic-linker explicitly; kit ld's default is musl. 21 # - Debian uses multi-arch paths: Scrt1.o + crti/crtn live under 22 # /usr/lib/aarch64-linux-gnu, the runtime SOs under 23 # /lib/aarch64-linux-gnu, and headers under both /usr/include and 24 # /usr/include/aarch64-linux-gnu (bits/libc-header-start.h etc.). 25 # The output tree follows the standard FHS layout under /sysroot/ 26 # so both `kit` and `clang --sysroot` work against it. 27 FROM docker.io/arm64v8/debian:bookworm-slim 28 29 # libc6-dev: Scrt1.o, crti.o, crtn.o, libc_nonshared.a + glibc headers 30 # under /usr/include and /usr/include/aarch64-linux-gnu. We 31 # deliberately do NOT stage libc.a or the static -lpthread/-ldl/-lrt 32 # archives: the harness only exercises dynamic-link (static-glibc is 33 # officially discouraged and isn't a real-world deployment shape). 34 # linux-libc-dev: kernel uapi (linux/*, asm/*, asm-generic/*) under 35 # /usr/include — used by syscall numbers etc. Pulled in transitively 36 # by libc6-dev, listed explicitly for clarity. 37 # gcc: pulled in for its *runtime only* (libgcc + crt{begin,end}*.o), staged 38 # below so this is a COMPLETE toolchain sysroot — a standard `clang --sysroot` 39 # cross-link works against it, not just kit. (kit still links its own rt/ for the 40 # soft-float / TF / 128-bit-int helpers; only gcc's runtime objects are copied.) 41 RUN apt-get update \ 42 && apt-get install -y --no-install-recommends \ 43 libc6-dev \ 44 linux-libc-dev \ 45 gcc \ 46 && rm -rf /var/lib/apt/lists/* 47 48 # Stage the artifacts into a standard FHS tree under /sysroot/ so the 49 # result works with both `kit` and a plain `clang --sysroot` cross-link. 50 # usr/include/ — full include tree; the multiarch subdir 51 # (aarch64-linux-gnu/bits/libc-header-start.h etc.) is 52 # preserved inside it so -isystem picks it up. 53 # usr/lib/ — crt objects, libc_nonshared.a, shared SOs, gcc runtime, 54 # and libc.so/libm.so linker scripts for -lc/-lm. 55 # lib/ — dynamic loader (dereferenced, self-contained). 56 RUN set -eux; \ 57 mkdir -p /sysroot/usr/include /sysroot/usr/lib /sysroot/lib; \ 58 cp -r /usr/include/. /sysroot/usr/include/; \ 59 cd /usr/lib/aarch64-linux-gnu; \ 60 cp Scrt1.o crti.o crtn.o libc_nonshared.a \ 61 libdl.a libpthread.a libpthread_nonshared.a librt.a libutil.a \ 62 /sysroot/usr/lib/; \ 63 cp -L /lib/aarch64-linux-gnu/libc.so.6 /sysroot/usr/lib/libc.so.6; \ 64 cp -L /lib/aarch64-linux-gnu/libm.so.6 /sysroot/usr/lib/libm.so.6; \ 65 cp -L /lib/aarch64-linux-gnu/libdl.so.2 /sysroot/usr/lib/libdl.so.2; \ 66 cp -L /lib/aarch64-linux-gnu/libpthread.so.0 /sysroot/usr/lib/libpthread.so.0; \ 67 cp -L /lib/aarch64-linux-gnu/librt.so.1 /sysroot/usr/lib/librt.so.1; \ 68 cp -L /lib/aarch64-linux-gnu/libutil.so.1 /sysroot/usr/lib/libutil.so.1; \ 69 cp -L /lib/ld-linux-aarch64.so.1 /sysroot/lib/ld-linux-aarch64.so.1; \ 70 printf 'GROUP ( libc.so.6 libc_nonshared.a )\n' > /sysroot/usr/lib/libc.so; \ 71 printf 'GROUP ( libm.so.6 )\n' > /sysroot/usr/lib/libm.so; \ 72 cp -aL /usr/lib/gcc /sysroot/usr/lib/gcc; \ 73 cp -L "$(find /usr/lib /lib -name libgcc_s.so.1 | head -1)" /sysroot/usr/lib/libgcc_s.so.1; \ 74 ln -sf libgcc_s.so.1 /sysroot/usr/lib/libgcc_s.so 75 76 # Pin the build for cache reuse and reproducibility audits. 77 RUN set -eux; \ 78 { \ 79 echo "debian bookworm-slim glibc $(dpkg-query -W -f='${Version}' libc6-dev)"; \ 80 echo "linux-libc-dev $(dpkg-query -W -f='${Version}' linux-libc-dev)"; \ 81 uname -m; \ 82 } > /sysroot/PROVENANCE 83 84 ENTRYPOINT ["sh", "-c", "tar -C /sysroot -cf - ."]