diff options
| author | Sam James <sam@gentoo.org> | 2024-03-12 22:52:03 +0000 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2024-03-28 00:52:25 -0400 |
| commit | 31314419aac57c45d82578700051f6ed999176af (patch) | |
| tree | ebd5f1487862d1870a04fab0321018464780d3a1 /mesonbuild/compilers/cpp.py | |
| parent | 509a140529328f316702411b8e9940a930340d52 (diff) | |
| download | meson-31314419aac57c45d82578700051f6ed999176af.tar.gz | |
compilers: cpp: don't set stdlib assertion macros if already set
Followup to 90098473d51e6f059e775f1833b0a2ea91c8f8f9.
If the compiler already has one of these assertion macros [0] set, then don't
interfere.
e.g. a Linux distribution might be setting a stricter default than usual. This
is a pitfall many fell into with _FORTIFY_SOURCE and it's why AX_ADD_FORTIFY_SOURCE [1]
was contributed to autoconf-archive.
[0] _GLIBCXX_ASSERTIONS, _LIBCPP_HARDENING_MODE, or _LIBCPP_ENABLE_ASSERTIONS.
[1] https://www.gnu.org/software/autoconf-archive/ax_add_fortify_source.html
Bug: https://github.com/mesonbuild/meson/issues/12962
Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
Diffstat (limited to 'mesonbuild/compilers/cpp.py')
| -rw-r--r-- | mesonbuild/compilers/cpp.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index f0d763b61..2a2f7615d 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -312,7 +312,13 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): if disable: return ['-DNDEBUG'] + # Don't inject the macro if the compiler already has it pre-defined. + for macro in ['_GLIBCXX_ASSERTIONS', '_LIBCPP_HARDENING_MODE', '_LIBCPP_ENABLE_ASSERTIONS']: + if self.defines.get(macro) is not None: + return [] + # Clang supports both libstdc++ and libc++ + # TODO: Pipe through the C++ stdlib impl information to here so we can avoid pollution args.append('-D_GLIBCXX_ASSERTIONS=1') if version_compare(self.version, '>=18'): args.append('-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST') @@ -500,8 +506,13 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler): if disable: return ['-DNDEBUG'] + # Don't inject the macro if the compiler already has it pre-defined. + if self.defines.get('_GLIBCXX_ASSERTIONS') is not None: + return [] + # XXX: This needs updating if/when GCC starts to support libc++. # It currently only does so via an experimental configure arg. + # TODO: Pipe through the C++ stdlib impl information to here so we can avoid pollution return ['-D_GLIBCXX_ASSERTIONS=1'] def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: |
