Commit Graph
6 Commits
Author SHA1 Message Date
Dana Jansens db88edfa1e 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.
2026-07-31 20:09:48 +00:00
Dana Jansens 239ad9fe8b Disable C++ exceptions in the toolchain (#7532)
Pass `-fno-exceptions` when building the toolchain. We do not use
exceptions, so we do not have any try/catch in main, so uncaught
exceptions just unwind and exit. They do not hit our signal handler and
we do not print the stack trace.

Instead of adding a try/catch in main, and redirecting that, we can
build with `-fno-exceptions`. This turns any throw into an `abort()`.
And indeed with that flag, the following code crashes and prints a stack
trace:
```cpp
  std::variant<int, bool> a = {1};
  std::get<bool>(a);
```

Note that libc++ and libc++abi need to be built with exceptions 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.

Fixes #5225
2026-07-30 20:15:03 +00:00
Chandler Carruth a1a9c02cdc Refactor Bazel toolchain to use rules_cc action groups (#7086)
Rather than defining our own action groups, work to re-use the
`rules_cc` ones, as they are (much) more comprehensive. Also, completely
eliminate the `codegen` action group as it was not well used. For
example, `-march` flags and `-O` flags change the preprocessor macros
defined. There isn't a really great "codegen" heuristic, so just pass
those flags to all compiles which is simpler anyways.

I'm tempted to do the same with preprocessor actions, but maybe it makes
sense to have that one stay separate.

Assisted-by: Antigravity with Gemini
2026-04-21 16:40:24 +00:00
Chandler Carruth c23230140d Fix OS config features and use them to move OS-specific flags (#6608)
This PR merges the OS-specific Clang flags into the main Clang flags
features using feature-based constraints instead of separate features
conditionally added. Similarly for libc++. This also move flags to more
correctly live in the Clang flag set vs. the libc++ flag set as some of
these flags were specific to using libc++.

To make this change, the libc++ feature needs to be computed rather than
being fixed, as we need to add search paths based on the installed
location of LLVM and Clang.

All of this only works when the OS-config flags work. The earlier PR
adding these had a bug -- _none_ of the OS features would ever be
enabled. This didn't result in a problem as the initial use was only to
_disable_ flags on the wrong OS. Now that we're enabling flags, we have
to get it right by marking all of these as `enabled`.
2026-01-16 01:13:38 +00:00
Chandler Carruth acf9a8bfd4 Move the libc++ hardening to be part of libcxx_feature (#6607)
This also switches it to only apply to C++ compiles rather than all
compiles.
2026-01-16 00:01:29 +00:00
Chandler Carruth 386a8a8a0b Extract C++-specific features into their own file (#6606)
This leaves behind project-specific features such as the system header
management of our dependencies and the fancy cache management string.

No expected changes here, but yet another slightly different order of
flags.
2026-01-15 14:40:29 +00:00