Просмотр исходного кода

Define -D_DEBUG and -DNDEBUG disregarding target platform

I have found out that Windows build omits`Y_ASSERT` statements when compiled in `--build=relwithdebinfo`
The reason is simple: most people know about `ifndef NDEBUG`, yet nobody checks `ifdef _DEBUG` (codesearch queries over util [for NDEBUG](https://a.yandex-team.ru/search?search=NDEBUG%2C%255Eutil%2Cw%2Carcadia%2C%2C200) and [for _DEBUG](https://a.yandex-team.ru/search?search=_DEBUG%2C%255Eutil%2Cw%2Carcadia%2C%2C200)).

This PR makes these two values consistent with each other disregarding the target platform.

https://stackoverflow.com/questions/2290509/debug-vs-ndebug/2290616#2290616
https://learn.microsoft.com/en-us/visualstudio/debugger/enabling-debug-features-in-visual-cpp-d-debug
7bab996a4a9e0db5e11a92d804733f50200b745c
thegeorg 7 месяцев назад
Родитель
Сommit
db9505d66c
3 измененных файлов с 23 добавлено и 16 удалено
  1. 2 4
      build/conf/compilers/msvc_compiler.conf
  2. 21 0
      build/ymake.core.conf
  3. 0 12
      build/ymake_conf.py

+ 2 - 4
build/conf/compilers/msvc_compiler.conf

@@ -28,10 +28,8 @@ when ($IDE_MSVS == "yes") {
     DEBUG_INFO_FLAGS=/Zi /FS
 }
 
-# For the flags regarding runtime library selection, see
-# https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx
-CFLAGS_DEBUG   = /Od /Ob0 /Oi /D_DEBUG /MTd
-CFLAGS_RELEASE = /O2 /Ob2 /Oi /DNDEBUG /MT
+CFLAGS_DEBUG   = /Od /Ob0 /Oi
+CFLAGS_RELEASE = /O2 /Ob2 /Oi
 
 MASMFLAGS=
 _MASM_IO=/nologo /c /Fo${output;suf=${OBJECT_SUF}:SRC} ${input:SRC}

+ 21 - 0
build/ymake.core.conf

@@ -4842,6 +4842,27 @@ when ($CLANG && $DEBUGINFO_LINES_ONLY == "yes" && $NO_DEBUGINFO != "yes") {
     DEBUG_INFO_FLAGS=-gline-tables-only
 }
 
+# NB: Assertions under sanitizers are disabled as they cause
+#     a couple _relocation out of range_ problems plus an
+#     ICE when building contrib/libs/hyperscan/runtime_avx512.
+when ($BUILD_TYPE == "release" || $BUILD_TYPE == "minsizerel" || $BUILD_TYPE == "valgrind-release" || $BUILD_TYPE == "profile" || $BUILD_TYPE == "gprof" || $BUILD_TYPE == "debugnoasserts" || $SANITIZER_TYPE != "") {
+    CFLAGS += -DNDEBUG
+    when ($OS_WINDOWS) {
+        # FIXME: defining _DEBUG on Linux gives more relation problems and breaks certain tests
+        CFLAGS += -U_DEBUG
+        # For the flags regarding runtime library selection, see
+        # https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx
+        CFLAGS += /MT
+    }
+}
+otherwise {
+    CFLAGS += -UNDEBUG
+    when ($OS_WINDOWS) {
+        CFLAGS += -D_DEBUG
+        CFLAGS += /MTd
+    }
+}
+
 # TODO: configurable tar and touch
 PACK_TGZ=${cwd:ARCADIA_BUILD_ROOT} tar -czf ${rootrel:OUTPUT} ${rootrel:INPUT} ${hide;kv:"p AR"} ${hide;kv:"pc light-red"}
 

+ 0 - 12
build/ymake_conf.py

@@ -609,9 +609,6 @@ class Build(object):
         if self.is_size_optimized:
             emit('_BUILD_SIZE_OPTIMIZED', 'yes')
 
-        if self.with_ndebug:
-            emit('_BUILD_WITH_NDEBUG', 'yes')
-
         toolchain_type, compiler_type, linker_type = Compilers[self.tc.type]
         toolchain = toolchain_type(self.tc, self)
         compiler = compiler_type(self.tc, self)
@@ -663,10 +660,6 @@ class Build(object):
         sanitizer = preset('SANITIZER_TYPE')
         return bool(sanitizer) and not is_negative_str(sanitizer)
 
-    @property
-    def with_ndebug(self):
-        return self.build_type in ('release', 'minsizerel', 'valgrind-release', 'profile', 'gprof', 'debugnoasserts')
-
     @property
     def is_valgrind(self):
         return self.build_type == 'valgrind' or self.build_type == 'valgrind-release'
@@ -1598,11 +1591,6 @@ class GnuCompiler(Compiler):
             else:
                 self.optimize = '-O3'
 
-        if self.build.with_ndebug:
-            self.c_defines.append('-DNDEBUG')
-        else:
-            self.c_defines.append('-UNDEBUG')
-
         if self.build.profiler_type in (Profiler.Generic, Profiler.GProf):
             self.c_foptions.append('-fno-omit-frame-pointer')