Skip to content

Commit

Permalink
compilers: cpp: wire up stdlib assertions
Browse files Browse the repository at this point in the history
None of the options set here affect ABI and are intended for detecting constraint
violations.

For GCC, we simply need to set -D_GLIBCXX_ASSERTIONS.

For Clang, the situation is far more complicated:
* LLVM 18 uses a 'hardened mode' (https://libcxx.llvm.org/Hardening.html).
  There are several levels of severity available here. I've chosen
  _LIBCPP_HARDENING_MODE_EXTENSIVE as the strongest-but-one. The strongest
  one (_DEBUG) doesn't affect ABI still but is reserved for stldebug.

* LLVM 15 uses a similar approach to libstdc++ called '_LIBCPP_ENABLE_ASSERTIONS'

Note that LLVM 17 while in development had fully deprecated _LIBCPP_ENABLE_ASSERTIONS
in favour of hardened, but changed its mind last-minute: https://discourse.llvm.org/t/rfc-hardening-in-libc/73925/4.

Signed-off-by: Sam James <[email protected]>
  • Loading branch information
thesamesam committed Jan 7, 2024
1 parent dc2dfb7 commit aba3dfa
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions mesonbuild/compilers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]
args.append('-fno-exceptions')
if not options[key.evolve('rtti')].value:
args.append('-fno-rtti')

if options[key.evolve('debugstl')].value:
args.append('-D_GLIBCXX_DEBUG=1')
return args
Expand Down

0 comments on commit aba3dfa

Please sign in to comment.