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

Add -g to LDFLAGS when compiling with LTO to get debug symbols.
diff --git a/Misc/NEWS.d/next/Build/2018-06-15-18-18-16.bpo-30345.j-xRE1.rst b/Misc/NEWS.d/next/Build/2018-06-15-18-18-16.bpo-30345.j-xRE1.rst
new file mode 100644
index 0000000..f8db09b
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2018-06-15-18-18-16.bpo-30345.j-xRE1.rst
@@ -0,0 +1 @@
+Add -g to LDFLAGS when compiling with LTO to get debug symbols.
diff --git a/configure b/configure
index 4a047e6..a75ca3a 100755
--- a/configure
+++ b/configure
@@ -6481,6 +6481,13 @@
       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
 fi
 
 
diff --git a/configure.ac b/configure.ac
index 913d546..36625f7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1455,6 +1455,13 @@
       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
 fi