From bf27f0e2c76839af8524e053cca271934150a90c Mon Sep 17 00:00:00 2001 From: Paul Pluzhnikov Date: Fri, 4 May 2018 10:07:58 -0400 Subject: [PATCH] configure uses incorrect link order when testing libpython References: https://stackoverflow.com/a/49868387 https://sourceware.org/bugzilla/show_bug.cgi?id=11420 Configure uses "gcc -o conftest -g ... conftest.c -ldl -lncurses -lm -ldl ... -lpthread ... -lpython2.7" when deciding whether give libpython is usable. That of course is the wrong link order, and only works for shared libraries (mostly by accident), and only on some systems. gdb/ChangeLog: PR gdb/11420 * configure.ac: Prepend libpython. * python/python-config.py: Likewise. * configure: Regenerate. --- gdb/ChangeLog | 7 +++++++ gdb/configure | 18 +++++++++--------- gdb/configure.ac | 10 +++++----- gdb/python/python-config.py | 3 +-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1a442407474..c20f2a9d0b5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2018-05-04 Paul Pluzhnikov + + PR gdb/11420 + * configure.ac: Prepend libpython. + * python/python-config.py: Likewise. + * configure: Regenerate. + 2018-05-03 Simon Marchi * Makefile.in (%.c: %.l): Use -t instead of --stdout. diff --git a/gdb/configure b/gdb/configure index f18d78e40e1..1aac9303ac3 100755 --- a/gdb/configure +++ b/gdb/configure @@ -10441,7 +10441,7 @@ $as_echo_n "checking for ${version}... " >&6; } save_CPPFLAGS=$CPPFLAGS save_LIBS=$LIBS CPPFLAGS="$CPPFLAGS $new_CPPFLAGS" - LIBS="$LIBS $new_LIBS" + LIBS="$new_LIBS $LIBS" found_usable_python=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -10478,13 +10478,13 @@ $as_echo "${found_usable_python}" >&6; } version=python2.7 new_CPPFLAGS=${python_includes} - new_LIBS="${python_libs} -lpython2.7" + new_LIBS="-lpython2.7 ${python_libs}" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${version}" >&5 $as_echo_n "checking for ${version}... " >&6; } save_CPPFLAGS=$CPPFLAGS save_LIBS=$LIBS CPPFLAGS="$CPPFLAGS $new_CPPFLAGS" - LIBS="$LIBS $new_LIBS" + LIBS="$new_LIBS $LIBS" found_usable_python=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -10516,13 +10516,13 @@ $as_echo "${found_usable_python}" >&6; } version=python2.6 new_CPPFLAGS=${python_includes} - new_LIBS="${python_libs} -lpython2.6" + new_LIBS="-lpython2.6 ${python_libs}" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${version}" >&5 $as_echo_n "checking for ${version}... " >&6; } save_CPPFLAGS=$CPPFLAGS save_LIBS=$LIBS CPPFLAGS="$CPPFLAGS $new_CPPFLAGS" - LIBS="$LIBS $new_LIBS" + LIBS="$new_LIBS $LIBS" found_usable_python=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -10554,13 +10554,13 @@ $as_echo "${found_usable_python}" >&6; } version=python2.5 new_CPPFLAGS=${python_includes} - new_LIBS="${python_libs} -lpython2.5" + new_LIBS="-lpython2.5 ${python_libs}" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${version}" >&5 $as_echo_n "checking for ${version}... " >&6; } save_CPPFLAGS=$CPPFLAGS save_LIBS=$LIBS CPPFLAGS="$CPPFLAGS $new_CPPFLAGS" - LIBS="$LIBS $new_LIBS" + LIBS="$new_LIBS $LIBS" found_usable_python=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -10592,13 +10592,13 @@ $as_echo "${found_usable_python}" >&6; } version=python2.4 new_CPPFLAGS=${python_includes} - new_LIBS="${python_libs} -lpython2.4" + new_LIBS="-lpython2.4 ${python_libs}" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${version}" >&5 $as_echo_n "checking for ${version}... " >&6; } save_CPPFLAGS=$CPPFLAGS save_LIBS=$LIBS CPPFLAGS="$CPPFLAGS $new_CPPFLAGS" - LIBS="$LIBS $new_LIBS" + LIBS="$new_LIBS $LIBS" found_usable_python=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ diff --git a/gdb/configure.ac b/gdb/configure.ac index 698fc7b8345..e1f630cd388 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -732,7 +732,7 @@ AC_DEFUN([AC_TRY_LIBPYTHON], save_CPPFLAGS=$CPPFLAGS save_LIBS=$LIBS CPPFLAGS="$CPPFLAGS $new_CPPFLAGS" - LIBS="$LIBS $new_LIBS" + LIBS="$new_LIBS $LIBS" found_usable_python=no AC_LINK_IFELSE(AC_LANG_PROGRAM([[#include "Python.h"]], [[Py_Initialize ();]]), @@ -922,19 +922,19 @@ else elif test "${have_python_config}" != failed; then if test "${have_libpython}" = no; then AC_TRY_LIBPYTHON(python2.7, have_libpython, - ${python_includes}, "${python_libs} -lpython2.7") + ${python_includes}, "-lpython2.7 ${python_libs}") fi if test "${have_libpython}" = no; then AC_TRY_LIBPYTHON(python2.6, have_libpython, - ${python_includes}, "${python_libs} -lpython2.6") + ${python_includes}, "-lpython2.6 ${python_libs}") fi if test ${have_libpython} = no; then AC_TRY_LIBPYTHON(python2.5, have_libpython, - ${python_includes}, "${python_libs} -lpython2.5") + ${python_includes}, "-lpython2.5 ${python_libs}") fi if test ${have_libpython} = no; then AC_TRY_LIBPYTHON(python2.4, have_libpython, - ${python_includes}, "${python_libs} -lpython2.4") + ${python_includes}, "-lpython2.4 ${python_libs}") fi fi if test "${have_libpython}" = python2.7 -o "${have_libpython}" = python27; then diff --git a/gdb/python/python-config.py b/gdb/python/python-config.py index c2b2969c392..3e60b86a6fc 100644 --- a/gdb/python/python-config.py +++ b/gdb/python/python-config.py @@ -58,12 +58,11 @@ for opt in opt_flags: print (to_unix_path(' '.join(flags))) elif opt in ('--libs', '--ldflags'): - libs = [] + libs = ['-lpython' + pyver + abiflags] if getvar('LIBS') is not None: libs.extend(getvar('LIBS').split()) if getvar('SYSLIBS') is not None: libs.extend(getvar('SYSLIBS').split()) - libs.append('-lpython'+pyver + abiflags) # add the prefix/lib/pythonX.Y/config dir, but only if there is no # shared library in prefix/lib/. if opt == '--ldflags': -- 2.30.2