config_host.mk.in                      |    2 -
 configure.ac                           |   47 +++++++++++++++++++++++++--------
 solenv/gbuild/platform/com_GCC_defs.mk |    4 +-
 3 files changed, 39 insertions(+), 14 deletions(-)

New commits:
commit d235f705b4dda23cfd7b77c500b166016633e46c
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Wed May 25 17:07:17 2022 +0200
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Thu May 26 07:55:50 2022 +0200

    use at least assertions mode if libc++ debug mode is not usable
    
    This way at least e.g. std::vector::operator[] will still check
    bounds even though things like iterator debugging will not work.
    
    Change-Id: If3c550cfec68eee9a19050fc8e60fca07148b4a4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134946
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/config_host.mk.in b/config_host.mk.in
index 9a2cd1343a18..019e1a65561b 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -306,7 +306,6 @@ export HAVE_GNUMAKE_FILE_FUNC=@HAVE_GNUMAKE_FILE_FUNC@
 export HAVE_LD_BSYMBOLIC_FUNCTIONS=@HAVE_LD_BSYMBOLIC_FUNCTIONS@
 export HAVE_LD_HASH_STYLE=@HAVE_LD_HASH_STYLE@
 export HAVE_LIBCPP=@HAVE_LIBCPP@
-export HAVE_LIBCPP_DEBUG=@HAVE_LIBCPP_DEBUG@
 export HAVE_LIBSTDCPP=@HAVE_LIBSTDCPP@
 export HAVE_POSIX_FALLOCATE=@HAVE_POSIX_FALLOCATE@
 export HAVE_WDEPRECATED_COPY_DTOR=@HAVE_WDEPRECATED_COPY_DTOR@
@@ -371,6 +370,7 @@ export LFS_CFLAGS=@LFS_CFLAGS@
 export LIBASSUAN_CFLAGS=$(gb_SPACE)@LIBASSUAN_CFLAGS@
 export LIBASSUAN_LIBS=$(gb_SPACE)@LIBASSUAN_LIBS@
 export LIBBASE_JAR=@LIBBASE_JAR@
+export LIBCPP_DEBUG=@LIBCPP_DEBUG@
 export LIBDIR=@LIBDIR@
 export LIBEOT_CFLAGS=$(gb_SPACE)@LIBEOT_CFLAGS@
 export LIBEOT_LIBS=$(gb_SPACE)@LIBEOT_LIBS@
diff --git a/configure.ac b/configure.ac
index bd9a1c3f8be6..d4cbd2410e0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7423,33 +7423,58 @@ AC_LANG_POP([C++])
 AC_SUBST([HAVE_LIBSTDCPP])
 AC_SUBST([HAVE_LIBCPP])
 
-HAVE_LIBCPP_DEBUG=
+LIBCPP_DEBUG=
 if test -z "$CROSS_COMPILING" -a -n "$HAVE_LIBCPP" -a -n "$ENABLE_DBGUTIL"; 
then
-    # Libc++ supports debug mode only if built for it, Mac libc++ isn't,
+    # Libc++ has two levels of debug mode, assertions mode enabled with 
-D_LIBCPP_DEBUG=0,
+    # and actual debug mode enabled with -D_LIBCPP_DEBUG=1 (and starting with 
LLVM15
+    # assertions mode will be separate and controlled by 
-D_LIBCPP_ENABLE_ASSERTIONS=1,
+    # although there will be backwards compatibility).
+    # Debug mode is supported by libc++ only if built for it, e.g. Mac libc++ 
isn't,
     # and there would be undefined references to debug functions.
     # Moreover std::to_string() has a bug (https://reviews.llvm.org/D125184).
+    # So check if debug mode can be used and disable or downgrade it to 
assertions
+    # if needed.
     AC_MSG_CHECKING([if libc++ has a usable debug mode])
     AC_LANG_PUSH([C++])
-    AC_RUN_IFELSE([AC_LANG_SOURCE([[
-#define _LIBCPP_DEBUG 1
+    libcpp_debug_links=
+    AC_LINK_IFELSE([AC_LANG_SOURCE([[
+#define _LIBCPP_DEBUG 0 // only assertions
+#include <vector>
+int main()
+{
+    std::vector<int> v;
+    v.push_back( 1 );
+    return v[ 3 ];
+}
+]])], [libcpp_debug_links=1])
+    if test -n "$libcpp_debug_links"; then
+        # we can use at least assertions, check if debug mode works
+        AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#define _LIBCPP_DEBUG 1 // debug mode
 #include <string>
 #include <vector>
 int foo(const std::vector<int>& v) { return *v.begin(); }
 int main()
 {
-    std::vector<int> v{ 1, 2 };
+    std::vector<int> v;
+    v.push_back( 1 );
     std::string s = "xxxxxxxxxxxxxxxxxxxxxxxxx" + std::to_string(10);
     return (foo(v) + s.size()) != 0 ? 0 : 1;
 }
 ]])],
-    [AC_MSG_RESULT(yes)
-     HAVE_LIBCPP_DEBUG=1
-    ],
-    [AC_MSG_RESULT(no)]
-    )
+        [AC_MSG_RESULT(yes)
+         LIBCPP_DEBUG=-D_LIBCPP_DEBUG=1
+        ],
+        [AC_MSG_RESULT(no, using only assertions)
+         LIBCPP_DEBUG=-D_LIBCPP_DEBUG=0
+        ]
+        )
+    else
+        AC_MSG_RESULT(no)
+    fi
     AC_LANG_POP([C++])
 fi
-AC_SUBST([HAVE_LIBCPP_DEBUG])
+AC_SUBST([LIBCPP_DEBUG])
 
 dnl ===================================================================
 dnl Check for gperf
diff --git a/solenv/gbuild/platform/com_GCC_defs.mk 
b/solenv/gbuild/platform/com_GCC_defs.mk
index c2db27243457..f16eb8ec282c 100644
--- a/solenv/gbuild/platform/com_GCC_defs.mk
+++ b/solenv/gbuild/platform/com_GCC_defs.mk
@@ -54,8 +54,8 @@ ifeq ($(gb_ENABLE_DBGUTIL),$(true))
 ifneq ($(HAVE_LIBSTDCPP),)
 gb_COMPILERDEFS_STDLIB_DEBUG = -D_GLIBCXX_DEBUG
 else
-ifneq ($(HAVE_LIBCPP_DEBUG),)
-gb_COMPILERDEFS_STDLIB_DEBUG = -D_LIBCPP_DEBUG=1
+ifneq ($(LIBCPP_DEBUG),)
+gb_COMPILERDEFS_STDLIB_DEBUG = $(LIBCPP_DEBUG)
 endif
 endif
 gb_COMPILERDEFS += $(gb_COMPILERDEFS_STDLIB_DEBUG)

Reply via email to