Skip to content

Commit

Permalink
build: enable extra runtime checks in libstdc++/libc++ in debug mode
Browse files Browse the repository at this point in the history
Change-Id: I1e8b99ccd68b67ae6b3c92236987a0549d86809d
  • Loading branch information
Pesa committed Jan 15, 2024
1 parent 0a67556 commit a9d7db1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion .waf-tools/default-compiler-flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def getGeneralFlags(self, conf):

def getDebugFlags(self, conf):
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in debug mode"""
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['_DEBUG']}
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': []}

def getOptimizedFlags(self, conf):
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in optimized mode"""
Expand Down Expand Up @@ -174,6 +174,9 @@ def getDebugFlags(self, conf):
'-Wno-error=maybe-uninitialized', # Bug #1615
]
flags['LINKFLAGS'] += self.__linkFlags
# Enable assertions in libstdc++
# https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
flags['DEFINES'] += ['_GLIBCXX_ASSERTIONS=1']
return flags

def getOptimizedFlags(self, conf):
Expand Down Expand Up @@ -235,6 +238,13 @@ def getGeneralFlags(self, conf):
def getDebugFlags(self, conf):
flags = super().getDebugFlags(conf)
flags['CXXFLAGS'] += self.__cxxFlags
# Enable assertions in libc++
if self.getCompilerVersion(conf) >= (18, 0, 0):
# https://libcxx.llvm.org/Hardening.html
flags['DEFINES'] += ['_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE']
elif self.getCompilerVersion(conf) >= (15, 0, 0):
# https://releases.llvm.org/15.0.0/projects/libcxx/docs/UsingLibcxx.html#enabling-the-safe-libc-mode
flags['DEFINES'] += ['_LIBCPP_ENABLE_ASSERTIONS=1']
return flags

def getOptimizedFlags(self, conf):
Expand Down

0 comments on commit a9d7db1

Please sign in to comment.