Skip to content

Conversation

@ndrewh
Copy link
Contributor

@ndrewh ndrewh commented Sep 26, 2025

LLVM_ENABLE_RUNTIMES uses the default build target for building compiler-rt,
which means a bunch of stuff gets built that isn't necessarily depended upon
(and wasn't getting built under LLVM_ENABLE_PROJECTS).

Right now, we configure sanitizer_common (and thus it gets built in the default
build) based on COMPILER_RT_BUILD_* options. However, compiler_rt_build_runtime
also uses the _HAS option to determine whether to configure a runtime.

Thus, there are cases where we are configuring (and building with the default
target) sanitizer-common when we do not need it. This change helps to slim
down builds of compiler-rt that do not need sanitizer-common built.

Copy link
Contributor

@DanBlackwell DanBlackwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding the new toggle is a good idea. Can you please check whether the current boolean logic makes sense (I've added a comment).

Also, my understanding is that this change won't affect the default behaviour (i.e. the flag is ON by default), can you update the title of the PR to remove the 'by default' if that's the case.

@@ -8,7 +8,7 @@ include(SanitizerUtils)
# sanitizers or xray (or both).
#
#TODO: Refactor sanitizer_common into smaller pieces (e.g. flag parsing, utils).
if (COMPILER_RT_HAS_SANITIZER_COMMON AND
if (COMPILER_RT_HAS_SANITIZER_COMMON AND COMPILER_RT_BUILD_SANITIZER_COMMON AND
(COMPILER_RT_BUILD_SANITIZERS OR COMPILER_RT_BUILD_XRAY OR COMPILER_RT_BUILD_MEMPROF OR COMPILER_RT_BUILD_CTX_PROFILE))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume that these options depend on having sanitizer_common built; should we instead be adding the new option to the 'OR'? i.e. is there a use case for building sanitizers/xray/memprof without sanitizer_common?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So:

if (COMPILER_RT_HAS_SANITIZER_COMMON AND
    (COMPILER_RT_BUILD_SANITIZER_COMMON OR COMPILER_RT_BUILD_SANITIZERS OR COMPILER_RT_BUILD_XRAY OR COMPILER_RT_BUILD_MEMPROF OR COMPILER_RT_BUILD_CTX_PROFILE))

Copy link
Contributor Author

@ndrewh ndrewh Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most of these projects, it is a dependency. So the list of ORed projects can be read as "if we are configuring these other projects we probably need sanitizer common too". I think it's intended to be exhaustive.

What we are trying to do here is NOT configure sanitizer-common when we do not need it for the default build. I think the PR description explains why it's so important that we do that. The other option i guess is to force users do disable all of the things in the OR even if they are not available on their platform.

…_HAS_ a dep

LLVM_ENABLE_RUNTIMES uses the default build target for building compiler-rt,
which means a bunch of stuff gets built that isn't necessarily depended upon
(and wasn't getting built under LLVM_ENABLE_PROJECTS).

Right now, we configure sanitizer_common (and thus it gets built in the default
build) based on COMPILER_RT_BUILD_* options. However, compiler_rt_build_runtime
also uses the _HAS option to determine whether to configure a project.

Thus, there are cases where we are configuring (and building with the default
target) sanitizer-common when we do not need it. This change helps to slim
down builds of compiler-rt that do not need sanitizer-common built.
@ndrewh ndrewh force-pushed the compiler-rt-build-sanitizer-common branch from 803eb26 to e2445ea Compare September 30, 2025 17:15
@ndrewh ndrewh changed the title [compiler-rt] [CMake] Add option to disable sanitizer-common builds by default [compiler-rt] [CMake] Only configure sanitizer-common if _BUILD and _HAS a dep Sep 30, 2025
@ndrewh
Copy link
Contributor Author

ndrewh commented Sep 30, 2025

Arguably, users should have to specify COMPILER_RT_BUILD_xxx=NO if they want to be sure a component does not build, since COMPILER_RT_HAS_xxx could change at any time due to a developer adding support for a particular runtime+platform. However, I think the following is a reasonable change regardless: check both the BUILD_ and HAS_ options to make sure we are actually going to configure the runtime before configuring sanitizer-common.

@ndrewh ndrewh changed the title [compiler-rt] [CMake] Only configure sanitizer-common if _BUILD and _HAS a dep [compiler-rt] [CMake] Only configure sanitizer-common if BUILD_ and HAS_ a dep Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants