{"abstract":"A distribution hardens its packages with flags its package build passes to the compiler. Code built in the same image without those flags gets only the toolchain's defaults. chard 0.2.1 read that default for gcc and clang on 2026-11-29. On Debian 13, Fedora 44 and CentOS Stream 10 both compilers apply no stack canary, no fortify, no stack-clash protection and partial RELRO; Debian's apply PIE. Ubuntu compiles all four protections, full RELRO included, into gcc; Wolfi's clang and its gcc wrapper apply all four, and Arch's compilers apply the canary. The manylinux and Docker gcc build images apply none of the four.","author":"Mark Esler","content":"A distribution passes hardening flags when it builds its packages. Almost none of those flags are defaults of the compiler it ships. Code you build yourself in that image, without passing those flags, gets only the toolchain\u0026rsquo;s defaults.\nOn Debian 13, Fedora 44 and CentOS Stream 10 cloud images with gcc and clang installed, both compilers at -O2 with no hardening flag build a binary with no stack canary, no fortify (bounds-checked libc calls), no stack-clash protection (stack probing) and only partial RELRO, where full RELRO makes the GOT read-only. On Debian both apply PIE (an executable the kernel can load at a random address). Some distributions\u0026rsquo; compilers apply the four themselves. On Ubuntu 24.04 (gcc 13.2.0 as first shipped, 13.3.0 in 24.04.5), gcc applies all four to an executable (LP#2078989: its specs attach -z now to -pie), and Ubuntu\u0026rsquo;s clang applies PIE alone. On Wolfi clang applies all four, and gcc does when the image\u0026rsquo;s default PATH finds the wrapper (a script that adds flags) at /usr/local/bin/gcc; with /usr/bin/gcc found first, gcc applies only the canary. On Arch both compilers apply the canary and none of the other three.\nBuild images differ the same way. The manylinux images and Docker\u0026rsquo;s gcc images apply none of the four (fortify reads unsupported on manylinux2014); cimg/base, GitHub\u0026rsquo;s ubuntu-slim and the Heroku 24 and Google builders, each with gcc 13.3.0, apply all four to an executable.\nThe OpenSSF guide says to whoever builds a compiler: \u0026ldquo;where practical make the generated compiler\u0026rsquo;s default options the secure options.\u0026rdquo;\nchard 0.2.1 read these defaults on 2026-11-29, on distribution, cloud, container and build images. The tables here are examples. Every reading is at chard.page, which keeps measuring. chard reads no package build, so an off says nothing about a distribution\u0026rsquo;s packages, and no row ranks one distribution against another.\nSystem Compiler canary PIE RELRO fortify stack-clash Debian 13.8 gcc 14.2.0 off on partial off off Debian 13.8 clang 19.1.7 off on partial off off Fedora 44 gcc 16.2.1 off off partial off off Fedora 44 clang 22.1.8 off off partial off off CentOS Stream 10 gcc 14.4.1 off off partial off off CentOS Stream 10 clang 23.1.3 off off partial off off Ubuntu 24.04.5 gcc 13.3.0 on on on on on Ubuntu 24.04.5 clang 18.1.3 off on partial off off Arch Linux gcc 16.2.1 on on partial off off Arch Linux clang 23.1.5 on on partial off off Wolfi, /usr/local/bin first gcc 16.2.0 on on on on on Wolfi, /usr/bin first gcc 16.2.0 on on partial off off Wolfi clang 23.1.6 on on on on on x86_64. \u0026ldquo;on\u0026rdquo; means the compiler applies it with no flag. The Debian, Fedora, CentOS Stream, Ubuntu and Arch lines are each distribution\u0026rsquo;s own image run as a virtual machine; Arch reads the same in its archlinux container. Debian 13.8 and Ubuntu 24.04.5 are point releases; Fedora 44, CentOS Stream 10, Arch and Wolfi are as their repositories stood on 2026-11-29. Wolfi is the wolfi-base container image, read with each PATH order. RELRO on is full RELRO (-z relro -z now); partial is -z relro alone. RELRO is read on a default executable; a shared object or a -no-pie executable from Ubuntu\u0026rsquo;s gcc reads partial.\nHow it was measured chard builds small probe programs with the toolchain under test, runs them, and reads the binaries it built. Every check is built three ways: the flag forced on, forced off, and as configured. A verdict is given only when the forced builds differ as expected, so a compiler that accepts a flag and ignores it does not read on. One exception: some toolchains add the flag after the command line, so the forced-off build still has the protection; there chard reads the as-configured build and records the flag that forced it. Wolfi\u0026rsquo;s gcc wrapper, the nixpkgs wrapper and the clang of Alpine, Arch, CachyOS and Chimera are read that way, for the checks where the flag is appended.\nEvery reading here and on chard.page uses chard\u0026rsquo;s bare-optimized profile: -O2 and no other flag. It has -O2 because glibc applies _FORTIFY_SOURCE only when compiling with optimization.\nA default here is whatever the installed toolchain (driver, compiler, linker and C library) does at -O2 with no hardening flag passed, whether that comes from upstream, from configure options, from a distribution\u0026rsquo;s patches or from a wrapper. The compiler is the one gcc or clang names on the PATH chard is started with, the image\u0026rsquo;s own unless stated. chard runs it in a cleared environment that keeps that PATH and any variable passed with --env.\nOn most distribution and container images the compilers were installed or upgraded for the measurement, from the image\u0026rsquo;s own repositories that day. The install also upgraded dependencies, the C library on some images. The build images and GitHub\u0026rsquo;s runners were measured with the compiler they came with.\nThe package build\u0026rsquo;s flags below are a control, run outside chard on 2026-11-25 in the public images named below: each is what the image\u0026rsquo;s own tool prints, one run each.\nThe package build and the compiler Each image prints what its package build passes: dpkg-buildflags --get on debian:13 and ubuntu:26.04, rpm --eval '%{optflags}' and '%{build_ldflags}' on fedora:44, and /etc/makepkg.conf on archlinux. Each cell reads package build / gcc alone: what the build passes, then what gcc applies by itself on the same release. x86_64.\nProtection Debian 13 Fedora 44 Arch Ubuntu 26.04 stack protector passed / off passed / off not passed / on passed / on _FORTIFY_SOURCE =2 / off =3 / off =3 / off =3 / on stack-clash protection passed / off passed / off passed / off passed / on -fcf-protection (control-flow marking) passed / unsupported (the link drops the marking) passed / off passed / off passed / on PIE not passed / on specs file / off not passed / on not passed / on RELRO -z relro / partial -z relro -z now / partial -z relro -z now / partial -z relro / on -Werror=format-security passed / off passed / off passed / off passed / off -D_GLIBCXX_ASSERTIONS not passed / off passed / off passed / off not passed / off On Debian and Fedora the package build passes most of these and the compiler alone applies PIE or nothing. Arch\u0026rsquo;s file passes no stack protector and no PIE, the two things its gcc does itself. On Ubuntu 26.04 dpkg and gcc both supply most of them.\nDebian\u0026rsquo;s flags are documented in dpkg-buildflags(1).\nRelated: jvoisin/compiler-flags-distro tabulates the flags distributions use to build their packages. Its README says not to expect them in a distribution\u0026rsquo;s compiler.\nDocker\u0026rsquo;s gcc images Docker\u0026rsquo;s official gcc images build their compiler from source on a Debian base. The gcc 14 Dockerfile starts from buildpack-deps:trixie and runs configure with --build, --disable-multilib and --enable-languages=c,c++,fortran,go. Debian 13\u0026rsquo;s own gcc 14.2.0 records a line containing --enable-default-pie. Docker\u0026rsquo;s gcc 14, 15 and 16 read PIE off; Debian 13\u0026rsquo;s gcc, built with that option, reads it on.\nUbuntu 24.04\u0026rsquo;s gcc applies all four protections to an executable; Debian and Fedora apply them only through the package build. An image built on a distribution inherits its compiler, not its package build; the companion piece shows what that means for Python\u0026rsquo;s wheels.\n","date":"2026-11-30","description":"Compile in a distribution's image and you get its compiler's defaults, not the flags its package build passes. On Debian 13, Fedora 44 and CentOS Stream 10, gcc and clang alone apply no stack canary, no fortify, no stack-clash protection and only partial RELRO; Ubuntu 24.04's gcc applies all four to an executable. chard 0.2.1 read these on 2026-11-29.","lastmod":"2026-11-30","readingTime":6,"section":"datagrams","title":"Code You Build Yourself Gets the Compiler's Defaults, Not the Distribution's Flags","url":"https://hexproof.dev/datagrams/cc-is-not-the-package-build/","wordCount":1202}