public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] Fix BZ 11420 -- configure uses incorrect link order when testing libpython
@ 2018-04-17 15:53 Paul Pluzhnikov via gdb-patches
  2018-05-03 15:56 ` Paul Pluzhnikov via gdb-patches
  2018-05-04 14:12 ` Simon Marchi
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Pluzhnikov via gdb-patches @ 2018-04-17 15:53 UTC (permalink / raw)
  To: gdb-patches ml

[-- Attachment #1: Type: text/plain, Size: 823 bytes --]

Greetings,

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.

Attached patch fixes this.

I am not sure about this part of the patch:

-  LIBS="$LIBS $new_LIBS"
+  LIBS="$new_LIBS $LIBS"

I think it's always better to prepend new libraries.

Thanks,

2018-04-17  Paul Pluzhnikov  <ppluzhnikov@google.com>

             PR gdb/11420
             * gdb/configure.ac: Prepend libpython.
             * gdb/python/python-config.py: Likewise.
             * gdb/configure: Regenerate.


-- 
Paul Pluzhnikov

[-- Attachment #2: gdb-bz11420-20180417.txt --]
[-- Type: text/plain, Size: 2385 bytes --]

diff --git a/gdb/configure.ac b/gdb/configure.ac
index 698fc7b834..e1f630cd38 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 c2b2969c39..0d38ed50c0 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':

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-04 14:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-17 15:53 [patch] Fix BZ 11420 -- configure uses incorrect link order when testing libpython Paul Pluzhnikov via gdb-patches
2018-05-03 15:56 ` Paul Pluzhnikov via gdb-patches
2018-05-04 14:12 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).