From 9017194238e206b948cc7ab21fb12565b4002b95 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Jun 2018 18:15:21 +0200 Subject: [PATCH 1/4] bpo-30345: Add -g to LDFLAGS to ease debug When using PGO+LTO and compile without LDFLAGS=-g, gdb fails to get function arguments: add -g to LDFLAGS to ease debug. --- .../next/Build/2018-06-15-18-18-16.bpo-30345.j-xRE1.rst | 2 ++ configure | 4 ++++ configure.ac | 3 +++ 3 files changed, 9 insertions(+) create mode 100644 Misc/NEWS.d/next/Build/2018-06-15-18-18-16.bpo-30345.j-xRE1.rst 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 000000000000000..1546803b4a2b857 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2018-06-15-18-18-16.bpo-30345.j-xRE1.rst @@ -0,0 +1,2 @@ +When using PGO+LTO and compile without LDFLAGS=-g, gdb fails to get function +arguments: add -g to LDFLAGS to ease debug. diff --git a/configure b/configure index 5187c6ff2b95d45..c2eaf1f4e1b88f1 100755 --- a/configure +++ b/configure @@ -6716,6 +6716,9 @@ then else OPT="-g $WRAP -O3 -Wall" fi + # bpo-30345: When using PGO+LTO and compile without LDFLAGS=-g, + # gdb fails to get function arguments. + LDFLAGS="$LDFLAGS -g" ;; *) OPT="-O3 -Wall" @@ -6737,6 +6740,7 @@ fi + # The -arch flags for universal builds on OSX UNIVERSAL_ARCH_FLAGS= diff --git a/configure.ac b/configure.ac index b13728e37d7b1bd..b6af06d8a54a937 100644 --- a/configure.ac +++ b/configure.ac @@ -1461,6 +1461,9 @@ then else OPT="-g $WRAP -O3 -Wall" fi + # bpo-30345: When using PGO+LTO and compile without LDFLAGS=-g, + # gdb fails to get function arguments. + LDFLAGS="$LDFLAGS -g" ;; *) OPT="-O3 -Wall" From 52fcc1989788045b5b845c40c1408736ec7005d9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Jun 2018 17:29:45 +0200 Subject: [PATCH 2/4] Only add to LDFLAGS when using LTO --- configure.ac | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index b6af06d8a54a937..fc147ec116b6de0 100644 --- a/configure.ac +++ b/configure.ac @@ -1302,6 +1302,11 @@ if test "$Py_LTO" = 'true' ; then esac ;; esac + + # bpo-30345: When using PGO+LTO and compile without -g in $LDFLAGS, + # gdb fails to get function arguments. + LTOFLAGS="$LTOFLAGS -g" + CFLAGS="$CFLAGS $LTOFLAGS" LDFLAGS="$LDFLAGS $LTOFLAGS" fi @@ -1461,9 +1466,6 @@ then else OPT="-g $WRAP -O3 -Wall" fi - # bpo-30345: When using PGO+LTO and compile without LDFLAGS=-g, - # gdb fails to get function arguments. - LDFLAGS="$LDFLAGS -g" ;; *) OPT="-O3 -Wall" From 0913c6cca4bf2027f66a562c2618f37be6af029a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Jun 2018 17:46:04 +0200 Subject: [PATCH 3/4] Respect $ac_cv_prog_cc_g Only add -g if it's supported by the C compiler. --- configure | 12 ++++++++---- configure.ac | 9 ++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/configure b/configure index c2eaf1f4e1b88f1..b314ed29e8ae5d2 100755 --- a/configure +++ b/configure @@ -6427,6 +6427,14 @@ if test "$Py_LTO" = 'true' ; then esac ;; esac + + if test "$ac_cv_prog_cc_g" = "yes" + then + # bpo-30345: When using PGO+LTO and compile without -g in $LDFLAGS, + # gdb fails to get function arguments. + LTOFLAGS="$LTOFLAGS -g" + fi + CFLAGS="$CFLAGS $LTOFLAGS" LDFLAGS="$LDFLAGS $LTOFLAGS" fi @@ -6716,9 +6724,6 @@ then else OPT="-g $WRAP -O3 -Wall" fi - # bpo-30345: When using PGO+LTO and compile without LDFLAGS=-g, - # gdb fails to get function arguments. - LDFLAGS="$LDFLAGS -g" ;; *) OPT="-O3 -Wall" @@ -6740,7 +6745,6 @@ fi - # The -arch flags for universal builds on OSX UNIVERSAL_ARCH_FLAGS= diff --git a/configure.ac b/configure.ac index fc147ec116b6de0..043b71d47468247 100644 --- a/configure.ac +++ b/configure.ac @@ -1303,9 +1303,12 @@ if test "$Py_LTO" = 'true' ; then ;; esac - # bpo-30345: When using PGO+LTO and compile without -g in $LDFLAGS, - # gdb fails to get function arguments. - LTOFLAGS="$LTOFLAGS -g" + if test "$ac_cv_prog_cc_g" = "yes" + then + # bpo-30345: When using PGO+LTO and compile without -g in $LDFLAGS, + # gdb fails to get function arguments. + LTOFLAGS="$LTOFLAGS -g" + fi CFLAGS="$CFLAGS $LTOFLAGS" LDFLAGS="$LDFLAGS $LTOFLAGS" From 4972939b0aea3e7d0ca57ca05b8ebd52a79711b8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Jun 2018 17:47:40 +0200 Subject: [PATCH 4/4] Update NEWS entry --- .../next/Build/2018-06-15-18-18-16.bpo-30345.j-xRE1.rst | 3 +-- configure | 4 ++-- configure.ac | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) 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 index 1546803b4a2b857..f8db09bdbc6684b 100644 --- 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 @@ -1,2 +1 @@ -When using PGO+LTO and compile without LDFLAGS=-g, gdb fails to get function -arguments: add -g to LDFLAGS to ease debug. +Add -g to LDFLAGS when compiling with LTO to get debug symbols. diff --git a/configure b/configure index b314ed29e8ae5d2..d427703f8e860a2 100755 --- a/configure +++ b/configure @@ -6430,8 +6430,8 @@ if test "$Py_LTO" = 'true' ; then if test "$ac_cv_prog_cc_g" = "yes" then - # bpo-30345: When using PGO+LTO and compile without -g in $LDFLAGS, - # gdb fails to get function arguments. + # bpo-30345: Add -g to LDFLAGS when compiling with LTO + # to get debug symbols. LTOFLAGS="$LTOFLAGS -g" fi diff --git a/configure.ac b/configure.ac index 043b71d47468247..b98ceb2b1427ebe 100644 --- a/configure.ac +++ b/configure.ac @@ -1305,8 +1305,8 @@ if test "$Py_LTO" = 'true' ; then if test "$ac_cv_prog_cc_g" = "yes" then - # bpo-30345: When using PGO+LTO and compile without -g in $LDFLAGS, - # gdb fails to get function arguments. + # bpo-30345: Add -g to LDFLAGS when compiling with LTO + # to get debug symbols. LTOFLAGS="$LTOFLAGS -g" fi