bazel/compile/test: Fix negative compiler-rt tests by using explicit -rtlib=platform#981
Draft
bazel/compile/test: Fix negative compiler-rt tests by using explicit -rtlib=platform#981
Conversation
Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
…or negative tests Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [PR-3851] Fix negative compiler-rt tests failing
bazel/compile/test: Fix negative compiler-rt tests by using explicit -rtlib=platform
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
libclang_rt.builtins.ais physically overlaid into clang's resource directory by thelibclang_rtattribute regardless of thecompiler-rtflag — so clang auto-discovers it even when--@toolchains_llvm//toolchain/config:compiler-rt=Falseis set, causing__divti3to remain defined and the negative tests to fail.Changes
cc_binarytargettest_compiler_rt_no_rt— same source astest_compiler_rtbut addslinkopts = ["-rtlib=platform"]to explicitly suppress clang's resource-directory auto-discovery of compiler-rt builtins:cross_compile_aarch64_no_compiler_rt_test,cross_compile_x86_64_no_compiler_rt_test) updated to use:test_compiler_rt_no_rtin bothdataandenv.BINARY— positive tests remain on:test_compiler_rtunchanged.Original prompt
Problem
In PR envoyproxy#3851 (branch
bazel-compile-rt), the negative compiler-rt tests (cross_compile_aarch64_no_compiler_rt_testandcross_compile_x86_64_no_compiler_rt_test) are failing because__divti3is still showing up as a defined symbol even when--@toolchains_llvm//toolchain/config:compiler-rt=Falseis passed.Root Cause
The
libclang_rtattribute intoolchains_llvm.bzlphysically copieslibclang_rt.builtins.ainto the LLVM distribution's resource directory (lib/clang/<version>/lib/linux/) during thedownload_llvmrepository rule phase (seetoolchain/internal/llvm_distributions.bzlline ~838 inbazel-contrib/toolchains_llvm).The
compiler-rtconfig flag intoolchains_llvmcontrols aselect()incc_toolchain_config.bzl(line 475):Where
compiler_rt_link_flags = ["-rtlib=compiler-rt"].When
compiler-rt=True(the default):-rtlib=compiler-rtis passed → clang uses compiler-rt.When
compiler-rt=False: nothing is passed ([]) → but clang still auto-discoverslibclang_rt.builtins.afrom its resource directory because the file physically exists there from the overlay.Fix
The
cc_binarytargettest_compiler_rtneeds to explicitly tell clang NOT to use compiler-rt when the test expects it to be absent. The cleanest approach matching existingtoolchains_llvmpatterns is to addlinkopts = ["-rtlib=platform"]to thecc_binarytarget used by the negative tests, or better yet, create a separatecc_binarywith that linkopt for the negative tests.However, since we can't change the toolchain's
select()default branch from this repo (that would be an upstreamtoolchains_llvmchange), the best approach withinenvoyproxy/toolshedis:cc_binarytarget (e.g.test_compiler_rt_no_rt) that addslinkopts = ["-rtlib=platform"]to explicitly override clang's auto-discovery of compiler-rt builtins from the resource directory.sh_testtargets to use this new binary instead of:test_compiler_rt.This mirrors how clang's
-rtlib=flag works:-rtlib=compiler-rt→ use compiler-rt builtins (explicit opt-in)-rtlib=platform→ use platform default (libgcc), even if compiler-rt exists in the resource dirFiles to change
All in
bazel/compile/test/:BUILD.bazelAdd a new
cc_binary:Update the two negative test targets (
cross_compile_aarch64_no_compiler_rt_testandcross_compile_x86_64_no_compiler_rt_test) to reference:test_compiler_rt_no_rtinstead of:test_compiler_rtin bothdataandenv.BINARY.No changes needed to
check_compiler_rt.shortest_compiler_rt.ccThe following is the prior conversation context from the user's chat exploration (may be truncated):
User: everything works here except for the no rt test - its still pulling it in
original agent attempt had a patch - but it wasnt needed afaict - at least not for tests - the reverse is true - somethign needs to prevent it being pulled in i think
Assistant:
Let me look at the PR and understand the issue with the "no rt" test.
Assistant: Now let me look at how toolchains_llvm handles the
compiler-rtconfig flag and how thelibclang_rtattribute interacts with it:Assistant: Now I can see the key issue. Let me look more closely at how
compiler_rt_link_flagsis set up and how thelibclang_rtattribute intoolchains_llvminteracts with the linker files.Assistant: Now I understand the full picture. Let me look at how
compiler_rt_link_flagsis constructed and how it interacts with thelibclang_rtoverlay to understand whycompiler-rt=Falseisn't preventing the library from being linked.Assistant: Now I have a clear picture of the problem. Let me look at how the
cc_binarytest_compiler_rtis built — specifically, the key issue is that thelibclang_rtlibrary is physically copied into the LLVM distribution'slib/clang/<version>/lib/directory duringdownload_llvm. This means the library is always present in the distribution, regardless of the--@toolchains_llvm//toolchain/config:compiler-rt=Falseflag.The flag only controls whether
-rtlib=compiler-rtis passed as a link flag (viacompiler_rt_link_flags). But the LLVM distribution'slibfilegroup already includeslib/clang/{LLVM_VERSION}/libwhich now contains the overlaidlibclang_rt.builtins.a. The linker/clang may automatically discover and link againstlibclang_rt.builtins.afrom its resource directory, even without the explicit-rtlib=compiler-rtflag.Here's the core problem:
toolchains_llvm.bzl, the `libcl...This pull request was created from Copilot chat.
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.