Repository navigation
Description
Title: compat/openssl: prefixer fails to link on aarch64 hosts (x86_64 libstdc++.a)
Description:
bazel build --config=openssl cannot build the compat/openssl prefixer tool on a Linux aarch64 host. The tool is compiled for aarch64 but linked against the x86_64 libstdc++.a:
ld.lld: error: external/envoy_toolshed++gcc_extension+gcc_runtime_linux_x86_64/lib64/libstdc++.a(compatibility.o) is incompatible with elf64-littleaarch64
ld.lld: error: external/envoy_toolshed++gcc_extension+gcc_runtime_linux_x86_64/lib64/libstdc++.a(compatibility-debug_list.o) is incompatible with elf64-littleaarch64
... (repeated for every object)
ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
Target //compat/openssl/prefixer:prefixer failed to build
//compat/openssl:prefixed_ossl_source runs the prefixer, so this blocks every --config=openssl build (including //source/exe:envoy-static) on aarch64, although bazel/SSL.md lists "Supported architectures: Linux x86_64, aarch64, ppc64le" for OpenSSL.
Repro steps:
- Host: Linux aarch64 (I used an NVIDIA BlueField-3 DPU). Build container: the
docker.io/envoyproxy/envoy-buildimage pinned in.github/config.yml. Bazel 9.3.2. - Source:
mainat 93aab93 (VERSION.txt= 1.41.0-dev).
bazel build -c opt --config=openssl //compat/openssl/prefixer:prefixer
I only reproduced this on the host above. The cause below is independent of the hardware, so I expect any Linux aarch64 host to behave the same, but I have not checked.
Cause:
At the commit above:
-
compat/openssl/prefixer/BUILD:8-11declareslabel_flag( name = "libstdcxx", build_setting_default = "@gcc_runtime_linux_x86_64//:libstdcxx", )
:libstdcxxis a dependency of theprefixer(BUILD:37; the target is built with-nostdinc++and-nostdlib++), so both the libstdc++ headers andlibstdc++.acome from the x86_64 repository regardless of the CPU the tool is built for. -
MODULE.bazel:187-195declares onlygcc_runtime_linux_x86_64. There is no aarch64 counterpart, althoughsysroot_linux_arm64andllvm_minimal_linux_arm64are already declared in the same file.
Related: #48840 ("compat/openssl: statically link libstdc++ in the prefixer") and #39632 ("bazel: Switch to hermetic gcc toolchains") introduced the hermetic libstdc++ but kept an x86_64-only default. v1.39.6 instead hard-codes external/sysroot_linux_amd64/usr/include/c++/13 in compat/openssl/prefixer/BUILD:24-25.
Suggested fix:
Declare gcc_runtime_linux_aarch64 next to the x86_64 one in MODULE.bazel and make the default of the flag follow the CPU. build_setting_default of a label_flag cannot be a select, so the default becomes an alias that contains the select. I have a patch and will open a PR that references this issue.
With that change, on the same aarch64 host (offline):
//compat/openssl/prefixer:prefixerbuilds.//compat/openssl:prefixed_ossl_sourceand//compat/openssl:bssl-compatbuild
(2845 actions, exit code 0).
Not verified: a full //source/exe:envoy-static build, x86_64 hosts, cross-compilation.
Admin and Stats Output: N/A (build-time failure, no Envoy binary is produced).
Config: --config=openssl (see the command above).
Logs: the linker output is in the description. I can attach the full Bazel log if useful.
Call Stack: N/A (not a crash).
Activity
compat/openssl: select the prefixer's libstdc++ by architecture (envo…
compat/openssl: select the prefixer's libstdc++ by architecture (envo…
compat/openssl: select the prefixer's libstdc++ by architecture (#49166)