bpo-30345: Add -g to LDFLAGS for LTO (GH-7709) (GH-7824)

Add -g to LDFLAGS when compiling with LTO to get debug symbols.
(cherry picked from commit 06fe77a84bd29d51506ab2ff703ae585a6121af2)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
diff --git a/configure b/configure
index e038964..3e52e60 100755
--- a/configure
+++ b/configure
@@ -6482,6 +6482,14 @@
       esac
       ;;
   esac
+
+  if test "$ac_cv_prog_cc_g" = "yes"
+  then
+      # bpo-30345: Add -g to LDFLAGS when compiling with LTO
+      # to get debug symbols.
+      LTOFLAGS="$LTOFLAGS -g"
+  fi
+
   CFLAGS="$CFLAGS $LTOFLAGS"
   LDFLAGS="$LDFLAGS $LTOFLAGS"
 fi