Disable RTTI in the toolchain (#7552)

This reduces object sizes which is desirable for linking speed.

zygoloid did some analysis to determine if any of our code requires RTTI
for `dynamic_cast` here:
https://github.com/carbon-language/carbon-lang/pull/7532#discussion_r3611196721:
> The only thing I found is that libc++ requires dynamic_cast in order
for std::print to correctly write Unicode to terminals on Windows

We use `llvm::print` functionality, not `std::print`, so this doesn't
affect our toolchain.

Note that libc++ and libc++abi are built with RTTI enabled. It is
explicitly allowed to use different compiler flags when building these
libraries even though they share some headers with users of the
libraries, so this does not cause ODR violations.
This commit is contained in:
Dana Jansens
2026-07-31 20:09:48 +00:00
committed by GitHub
parent 6e9e871b74
commit db88edfa1e
2 changed files with 4 additions and 0 deletions
@@ -67,6 +67,7 @@ clang_feature = feature(
actions = ACTION_NAME_GROUPS.all_cpp_compile_actions,
flag_groups = [flag_group(flags = [
"-fno-exceptions",
"-fno-rtti",
"-std=c++20",
])],
),
+3
View File
@@ -574,6 +574,9 @@ cc_library(
# than the client (our toolchain) uses, even though they both include
# the same headers from the libraries.
"-fexceptions",
# Like exceptions, these libraries are built internally with RTTI
# enabled, while the toolchain is built without.
"-frtti",
],
hdrs_check = "strict",
includes = [