Closed Bug 2070120 Opened 2 months ago Closed 2 months ago

Build more linux local toolchains against the sysroot

Categories

(Firefox Build System :: Toolchains, task)

task

Tracking

(firefox158 fixed)

RESOLVED FIXED
158 Branch
Tracking Status
firefox158 --- fixed

People

(Reporter: jcristau, Assigned: jcristau)

References

Details

Attachments

(6 external files)

Several toolchains are compiled and linked against the docker image's headers
and libraries rather than against an in-tree sysroot, so the glibc floor of
the shipped binary follows whatever image they happen to be built in. Bug
2010489 moves the toolchain tasks to a Debian 13 image and makes that visible:

toolchain before deb13 with patches
xar 2.34 2.38 2.14
mkbom 2.34 2.38 2.14
winchecksec 2.14 2.34 2.14
upx 2.14 2.38 2.14
gn 2.18 2.38 2.18
wine 2.29 2.38 (not converted, see below)

(max GLIBC_* symbol version, from readelf -V on the real artifacts.)

These are all local-toolchain: true, so mach bootstrap hands them to
developers on arbitrary distributions, and GLIBC_2.38 excludes Ubuntu 22.04
(2.35), Debian 12 (2.36) and Rocky 9 (2.34). gn additionally broke CI:
source-test-vendor-verify-gfx runs it to re-vendor gfx/angle and failed
with

/builds/worker/fetches/gn/gn: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.38' not found

which bug 2065412 works around by moving the static-analysis-build image to
Debian 13.

Toolchains built through sysroot-aware scripts were unaffected throughout:
build-clang.py keeps clang at GLIBC_2.17 and build-rust-based-toolchain.sh
keeps the Rust tools at 2.18. The fix is to make these do the same.

The compiler is not itself the problem: build-binutils.sh uses the image's
gcc with --sysroot in CFLAGS and is unaffected. The conversions here also
switch to the fetched clang, because that is what the existing sysroot-using
scripts do (build-dmg-hfsplus.sh, build-msix-packaging.sh) and, for gn,
because the sysroot's libstdc++ has to be the one in use.

Notes on the individual conversions:

  • gn needs linux64-toolchain-sysroot-gcc10 rather than
    linux64-toolchain-sysroot: it is built as C++23 and uses <concepts> and
    <ranges>, which the libstdc++ 8 in the latter does not have. cctools-port
    and node-22 already use the gcc10 sysroot for the same reason. The symbols
    pulling in GLIBC_2.38 were the __isoc23_str* redirects glibc applies to
    strtol and friends for __cplusplus >= 202302L, so older headers remove
    the redirect rather than papering over it.

  • xar needs an xml2-config shim backed by pkg-config: its configure can
    only locate libxml2 through AC_PATH_PROG(xml2-config), and sysroots ship no
    /usr/bin. Without it the build silently combines the host's libxml2 headers
    with the sysroot's older library.

  • xar also lets us drop libzstd-dev from the toolchain-build image, which
    bug 2010574 only added because Debian 13's openssl pulls zstd into
    pkg-config --static --libs libcrypto. The sysroot's openssl does not. That
    also stops gcc autodetecting zstd, which was silently adding a
    libzstd.so.1 dependency to the gcc toolchains. The explicit
    -DLLVM_ENABLE_ZSTD=OFF and --without-zstd stay, to pin autodetection
    that would otherwise vary with the image's contents.

    Consequences of building xar against the sysroot, for the record: the
    statically linked libcrypto becomes openssl 1.0.1t (xar only uses the EVP
    digest functions, no TLS or certificate code); that libcrypto.a is not
    built PIC, so the binary is no longer a PIE; and the sysroot has lzma.h
    where the image did not, so xar gains lzma support and a liblzma.so.5
    dependency.

  • wine is deliberately left alone. Its configure probes -mabi=ms on the
    host compiler; gcc supports it and clang does not, and when that check fails
    wine sets DLLEXT="" and switches from ELF .dll.so Unix builtins to
    PE-only, which is a structural change to the artifact rather than a
    portability fix. Building with gcc against the sysroot instead would lose
    linux/memfd.h, linux/ntsync.h and linux/userfaultfd.h (jessie's
    linux-libc-dev is 3.16), silently disabling memfd-backed mappings and the
    ntsync fast path. Pinning the task to the Debian 12 image would only buy
    2.38 -> 2.36, still above Ubuntu 22.04's 2.35

Summary: Build the linux local toolchains against the sysroot → Build more linux local toolchains against the sysroot

upx was built with the docker image's headers and libraries, so the
shipped binary's glibc floor followed the image: moving to Debian 13
took it from GLIBC_2.14 to GLIBC_2.38, which excludes Ubuntu 22.04,
Debian 12 and Rocky 9. It is a local-toolchain, so mach bootstrap hands
it to developers on arbitrary distributions.

upx links nothing externally -- UCL and zlib are vendored and built
static, and bzip2, zstd and threads are disabled in its CMakeLists --
so pointing cmake at the sysroot is enough. Follows the same pattern as
build-dmg-hfsplus.sh.

win64-upx shares the script and is unaffected: the new flags are in the
non-Msys branch.

Assignee: nobody → jcristau
Status: NEW → ASSIGNED

mkbom was built with the docker image's compiler, so the shipped
binary's glibc floor followed the image: moving to Debian 13 took it
from GLIBC_2.34 to GLIBC_2.38. It is a local-toolchain, so mach
bootstrap hands it to developers on arbitrary distributions.

bomutils assigns CXXFLAGS and LDFLAGS with = rather than ?= in its
Makefile, so overriding them on the make command line would drop its
own hardening flags. The sysroot flags go into CXX instead.

The task already fetched clang and the sysroot; it just wasn't using
them. Measured locally: GLIBC_2.38 -> GLIBC_2.14.

winchecksec was built with the docker image's headers and libraries, so
the shipped binary's glibc floor followed the image: moving to Debian 13
took it from GLIBC_2.14 to GLIBC_2.34. It is a local-toolchain, so mach
bootstrap hands it to developers on arbitrary distributions.

The task fetched neither clang nor a sysroot, and build-winchecksec.sh
had no case for x86_64-unknown-linux-gnu, so the linux build fell
through with no cmake flags at all. Add the fetches and a linux case
mirroring build-msix-packaging.sh.

win64-winchecksec shares the script and is unaffected. Measured locally:
GLIBC_2.34 -> GLIBC_2.14, and pe-parse's -Werror block still compiles
clean under clang with the sysroot.

gn was built with the docker image's gcc, so the shipped binary's glibc
floor followed the image: moving to Debian 13 took it from GLIBC_2.18 to
GLIBC_2.38. That broke source-test-vendor-verify-gfx, which runs gn to
re-vendor gfx/angle on the static-analysis-build image; bug 2065412
worked around it by moving that image to Debian 13, but the binary is
also a local-toolchain handed to developers on arbitrary distributions.

The symbols pulling in GLIBC_2.38 are the __isoc23_str* redirects glibc
applies to strtol and friends for __cplusplus >= 202302L, and gn is
built as C++23. Building against older headers removes the redirect
rather than papering over it.

gn needs linux64-toolchain-sysroot-gcc10 rather than
linux64-toolchain-sysroot: it uses <concepts> and <ranges>, which the
libstdc++ 8 in the latter does not have. cctools-port and node-22
already use the gcc10 sysroot for the same reason.

build/gen.py bakes CXX, CFLAGS+CXXFLAGS and LDFLAGS into build.ninja at
generation time and has no cxx-vs-cc distinction, so the environment
variables have to be set before it runs. The mac and win64 gn builds set
their own and are unaffected; build-gn-common.sh is untouched.

xar was built with the docker image's headers and libraries even though
its task already fetched clang and a sysroot. Moving to Debian 13 took
the shipped binary from GLIBC_2.34 to GLIBC_2.38 and added a
libzstd.so.1 dependency, by way of deb13's openssl pulling zstd into
pkg-config --static --libs libcrypto. It is a local-toolchain, so mach
bootstrap hands it to developers on arbitrary distributions.

xar's configure can only locate libxml2 through xml2-config, which
sysroots do not ship because they contain no /usr/bin. Left alone it
combines the host's libxml2 headers with the sysroot's library, so pass
a small shim backed by pkg-config.

The sysroot's openssl is 1.0.1t, which does not pull in zstd, so
libzstd-dev is no longer needed in the image; bug 2010574 only added it
for xar. Dropping it also stops gcc autodetecting zstd, which was
silently adding a libzstd.so.1 dependency to the gcc toolchains. The
explicit -DLLVM_ENABLE_ZSTD=OFF and --without-zstd stay: they pin
autodetection that would otherwise vary with the image's contents.

Other consequences worth knowing:

  • the statically linked libcrypto becomes the sysroot's openssl 1.0.1t.
    xar only uses the EVP digest functions, no TLS or certificate code.
  • that libcrypto.a is not built PIC, so the binary can no longer be a
    PIE.
  • the sysroot has lzma.h where the image did not, so xar gains lzma
    support and a liblzma.so.5 dependency.

Measured locally: GLIBC_2.38 -> GLIBC_2.14, configure resolves libxml
2.9.1 with no host/sysroot split, and create/extract roundtrips pass for
sha1, sha256 and md5 with gzip, bzip2 and no compression.

was silently adding a libzstd.so.1 dependency to the gcc toolchains

Would it be possible to add a test for this?

(In reply to Sylvestre Ledru [:Sylvestre] from comment #6)

was silently adding a libzstd.so.1 dependency to the gcc toolchains

Would it be possible to add a test for this?

You'd have to be more specific. But either way, libzstd.so.1 isn't a particularly esoteric dependency these days, so this is a note on that non-obvious change in passing more than pointing out a problem, IMO.

Pushed by jcristau@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/28b8040e2a82 https://hg.mozilla.org/integration/autoland/rev/179e4d446c09 Build upx against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/46399accbe58 https://hg.mozilla.org/integration/autoland/rev/0799d4a17b5d Build mkbom against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/a45e8e65b478 https://hg.mozilla.org/integration/autoland/rev/39c4a9096d74 Build winchecksec against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/a0dd954afbd5 https://hg.mozilla.org/integration/autoland/rev/62ccf0249627 Build gn against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/49f78a104ff6 https://hg.mozilla.org/integration/autoland/rev/cf1f1ba27fad Build xar against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille
Pushed by agoloman@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/61fc3283e0d9 https://hg.mozilla.org/integration/autoland/rev/79b6454b241f Revert "Bug 2070120, Bug 2010489, Bug 2010555, Bug 2010574, Bug 2010541 - Build xar against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille" for causing spidermonkey bustages.

Backed out for causing spidermonkey bustages.

Flags: needinfo?(jcristau)

The task already fetched a sysroot but never used it: build-breakpad-injector.sh
writes a mozconfig with no --with-sysroot, and the bootstrapped sysroot only
applies when bootstrap is enabled, which it isn't under MOZ_AUTOMATION. So the
build used the docker image's libstdc++ headers and the library's ABI floor
followed the image, going from GLIBCXX_3.4.29 to GLIBCXX_3.4.31 on Debian 13.

Debian 12 provides GLIBCXX_3.4.30, so the resulting libbreakpadinjector.so
could not be dlopen'd there, and every jit-test that injects it failed with
MOZ_CRASH(Failed to load library).

Use sysroot-x86_64-linux-gnu rather than linux64-toolchain-sysroot: the
injector is built as C++20 and the latter only has libstdc++ 8. That also
matches the sibling minidump-stackwalk task and ordinary Firefox builds.

The resulting library needs GLIBC_2.14 and GLIBCXX_3.4, i.e. rather better
than the GLIBC_2.34 and GLIBCXX_3.4.29 it needed before Debian 13.

2 things:

Flags: needinfo?(jcristau)
Pushed by jcristau@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/806f31014c5d https://hg.mozilla.org/integration/autoland/rev/ef8d1477898e Build upx against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/64ff9411a29e https://hg.mozilla.org/integration/autoland/rev/0247d847e764 Build mkbom against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/dd45a84324c8 https://hg.mozilla.org/integration/autoland/rev/f864c8fa9ebe Build winchecksec against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/96ec88b22c5e https://hg.mozilla.org/integration/autoland/rev/86b6471c5819 Build gn against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/79403252a584 https://hg.mozilla.org/integration/autoland/rev/75ced0b58195 Build xar against the sysroot. r=firefox-build-system-reviewers,sylvestre,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/284996810d73 https://hg.mozilla.org/integration/autoland/rev/37b80b85bc44 Build the breakpad injector against the sysroot. r=firefox-build-system-reviewers,ahochheiden
See Also: → 2072487
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: