From a1d1946dcba6509f0679f507b57e7b228d32e6f8 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 4 Oct 2022 16:46:29 -0700
Subject: [PATCH] Use DWARF 4 debug information when building using mingw
See this bug for more information:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101377
Fixes https://github.com/libsdl-org/SDL/issues/6139
(cherry picked from commit f18fae4c689a68bd50ce34d6b9c1f014c2f220a2)
---
configure | 36 ++++++++++++++++++++++++++++++++++++
configure.ac | 21 +++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/configure b/configure
index 82e20421524..eae55599604 100755
--- a/configure
+++ b/configure
@@ -22773,6 +22773,41 @@ printf "%s\n" "$have_clang_objc_arc" >&6; }
fi
}
+CheckGDwarf4()
+{
+ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -gdwarf-4 option" >&5
+printf %s "checking for GCC -gdwarf-4 option... " >&6; }
+ have_gcc_gdwarf4=no
+
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$save_CFLAGS -gdwarf-4"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+ int x = 0;
+
+int
+main (void)
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+ have_gcc_gdwarf4=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_gcc_gdwarf4" >&5
+printf "%s\n" "$have_gcc_gdwarf4" >&6; }
+ CFLAGS="$save_CFLAGS"
+
+ if test x$have_gcc_gdwarf4 = xyes; then
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -gdwarf-4"
+ fi
+}
+
CheckVisibilityHidden()
{
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -fvisibility=hidden option" >&5
@@ -28502,6 +28537,7 @@ printf "%s\n" "#define SDL_TIMER_UNIX 1" >>confdefs.h
if test x$enable_loadso = xyes; then
have_loadso=yes
fi
+ CheckGDwarf4
CheckDeclarationAfterStatement
CheckDummyVideo
CheckOffscreenVideo
diff --git a/configure.ac b/configure.ac
index 535597d8556..2dacf44ebd6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1515,6 +1515,26 @@ CheckObjectiveCARC()
fi
}
+dnl See if GCC's -gdwarf-4 is supported
+dnl See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101377 for why this is needed on Windows
+CheckGDwarf4()
+{
+ AC_MSG_CHECKING(for GCC -gdwarf-4 option)
+ have_gcc_gdwarf4=no
+
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$save_CFLAGS -gdwarf-4"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ int x = 0;
+ ]],[])], [have_gcc_gdwarf4=yes],[])
+ AC_MSG_RESULT($have_gcc_gdwarf4)
+ CFLAGS="$save_CFLAGS"
+
+ if test x$have_gcc_gdwarf4 = xyes; then
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -gdwarf-4"
+ fi
+}
+
dnl See if GCC's -fvisibility=hidden is supported (gcc4 and later, usually).
dnl Details of this flag are here: http://gcc.gnu.org/wiki/Visibility
CheckVisibilityHidden()
@@ -3968,6 +3988,7 @@ case "$host" in
if test x$enable_loadso = xyes; then
have_loadso=yes
fi
+ CheckGDwarf4
CheckDeclarationAfterStatement
CheckDummyVideo
CheckOffscreenVideo