Skip to content

Commit

Permalink
compilers: cpp: wire up debugstl for Clang
Browse files Browse the repository at this point in the history
For Clang, we now pass -D_GLIBCXX_DEBUG=1 if debugstl is enabled, and
we also pass -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG.

Per https://discourse.llvm.org/t/building-a-program-with-d-libcpp-debug-1-against-a-libc-that-is-not-itself-built-with-that-define/59176/3,
we can't use _LIBCPP_DEBUG for older Clang versions as it's unreliable unless
libc++ was built with it.

We choose MODE_DEBUG for stldebug while building with assertions will do
MODE_EXTENSIVE.

Signed-off-by: Sam James <[email protected]>
Signed-off-by: Eli Schwartz <[email protected]>
  • Loading branch information
thesamesam authored and eli-schwartz committed Jan 10, 2024
1 parent ce2db13 commit a5fdd37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/markdown/snippets/cpp-stldebug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## `stldebug` gains Clang support

For Clang, we now pass `-D_GLIBCXX_DEBUG=1` if `debugstl` is enabled, and
we also pass `-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG`.
13 changes: 13 additions & 0 deletions mesonbuild/compilers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CPPCompiler.get_options(self)
key = OptionKey('key', machine=self.for_machine, lang=self.language)
opts.update({
key.evolve('debugstl'): coredata.UserBooleanOption(
'STL debug mode',
False,
),
key.evolve('eh'): coredata.UserComboOption(
'C++ exception handling type.',
['none', 'default', 'a', 's', 'sc'],
Expand Down Expand Up @@ -277,6 +281,15 @@ def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]

non_msvc_eh_options(options[key.evolve('eh')].value, args)

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

# We can't do _LIBCPP_DEBUG because it's unreliable unless libc++ was built with it too:
# https://discourse.llvm.org/t/building-a-program-with-d-libcpp-debug-1-against-a-libc-that-is-not-itself-built-with-that-define/59176/3
# Note that unlike _GLIBCXX_DEBUG, _MODE_DEBUG doesn't break ABI. It's just slow.
if version_compare(self.version, '>=18'):
args.append('-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG')

if not options[key.evolve('rtti')].value:
args.append('-fno-rtti')

Expand Down

0 comments on commit a5fdd37

Please sign in to comment.