Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Doug Evans <dje@google.com>
Cc: Tom Tromey <tromey@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [patch] Smaller gdb: -rdynamic -> -Wl,--dynamic-list
Date: Sat, 05 Jun 2010 12:45:00 -0000	[thread overview]
Message-ID: <20100605124522.GA31976@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <AANLkTimWI6s_nwGWE0EnfMJw7Ymc99sKM0J95Woadgz_@mail.gmail.com>

On Sat, 05 Jun 2010 04:48:33 +0200, Doug Evans wrote:
>  "ImportError: /usr/grte/v1/k8-linux/lib/python2.4/lib-dynload/itertools.so:
> undefined symbol: PyExc_StopIteration"
> 
> when I did "import itertools".
> 
> I was statically linking libpythonX.Y.a.
> 
> I'm not sure what the right fix is.

This is an open Python bug: http://bugs.python.org/issue4434
(I was not aware of it.)

I doubt how useful is to depend on .so modules while having .a libpython
linked in but I understand my patch broke compatibility with such case.

With libpythonX.Y.so.1.0 the problem does not happen as all the symbols are
present in its .dynsym.  There is an inefficiency Python-2.6.4/Include/pyport.h
uses dllimport and dllimport declarations for the API but it has no support
for gcc __attribute__((visibility)) there and thus libpythonX.Y.so.1.0's
.dynsym is excessively large there.

I was unable to test it as Fedora (13) does not ship libpythonX.Y.a (and it
failed to build one when I tried to).  Could you test it, please?

If some existing python tests were already broken I can drop this new one.

No regressions on {x86_64,x86_64-m32,i686}-fedora13-linux-gnu.


Thanks,
Jan


gdb/
2010-06-05  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* configure.ac <"${have_libpython}" != no>: New workaround of
	python#4434.
	* configure: Regenerate.

gdb/testsuite/
2010-06-05  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.python/python.exp (pythonX.Y/lib-dynload/*.so): New.

--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1470,16 +1470,39 @@ if test ${build} = ${host} -a ${host} = ${target} ; then
       # Older GNU ld supports --export-dynamic but --dynamic-list it does not.
       RDYNAMIC="-Wl,--dynamic-list=${srcdir}/proc-service.list"
       LDFLAGS="$LDFLAGS $RDYNAMIC"
-      AC_TRY_LINK([], [],
-		  [found="-Wl,--dynamic-list"
-		   RDYNAMIC='-Wl,--dynamic-list=$(srcdir)/proc-service.list'],
-		  [RDYNAMIC="-rdynamic"
-		   LDFLAGS="$old_LDFLAGS $RDYNAMIC"
-		   AC_TRY_LINK([], [],
-			       [found="-rdynamic"],
-			       [found="no"
-				# Error on its usage by .mh file.
-				RDYNAMIC="no-rdynamic-available"])])
+      dynamic_list=false
+      if test "${have_libpython}" = no; then
+	AC_TRY_LINK([], [], [dynamic_list=true])
+      else
+	# Workaround http://bugs.python.org/issue4434 where static
+	# libpythonX.Y.a would get its symbols required for
+	# pythonX.Y/lib-dynload/*.so modules hidden by -Wl,--dynamic-list.
+	# Problem does not happen for the recommended libpythonX.Y.so linkage.
+	old_CFLAGS="$CFLAGS"
+	CFLAGS="$CFLAGS $PYTHON_CFLAGS"
+	AC_RUN_IFELSE(
+	  AC_LANG_PROGRAM(
+	    [#include "]${have_libpython}[/Python.h"],
+	    [int err;
+	     Py_Initialize ();
+	     err = PyRun_SimpleString ("import itertools\n");
+	     Py_Finalize ();
+	     return err == 0 ? 0 : 1;]),
+	  [dynamic_list=true], [], [true])
+	CFLAGS="$old_CFLAGS"
+      fi
+      if $dynamic_list;then
+	found="-Wl,--dynamic-list"
+	RDYNAMIC='-Wl,--dynamic-list=$(srcdir)/proc-service.list'
+      else
+	RDYNAMIC="-rdynamic"
+	LDFLAGS="$old_LDFLAGS $RDYNAMIC"
+	AC_TRY_LINK([], [],
+		    [found="-rdynamic"],
+		    [found="no"
+		     # Error on its usage by .mh file.
+		     RDYNAMIC="no-rdynamic-available"])
+      fi
       AC_SUBST(RDYNAMIC)
       LDFLAGS="$old_LDFLAGS"
       AC_MSG_RESULT($found)
--- a/gdb/configure
+++ b/gdb/configure
@@ -14199,7 +14199,9 @@ $as_echo_n "checking for the dynamic export flag... " >&6; }
       # Older GNU ld supports --export-dynamic but --dynamic-list it does not.
       RDYNAMIC="-Wl,--dynamic-list=${srcdir}/proc-service.list"
       LDFLAGS="$LDFLAGS $RDYNAMIC"
-      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+      dynamic_list=false
+      if test "${have_libpython}" = no; then
+	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 int
@@ -14211,12 +14213,51 @@ main ()
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  found="-Wl,--dynamic-list"
-		   RDYNAMIC='-Wl,--dynamic-list=$(srcdir)/proc-service.list'
+  dynamic_list=true
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+      else
+	# Workaround http://bugs.python.org/issue4434 where static
+	# libpythonX.Y.a would get its symbols required for
+	# pythonX.Y/lib-dynload/*.so modules hidden by -Wl,--dynamic-list.
+	# Problem does not happen for the recommended libpythonX.Y.so linkage.
+	old_CFLAGS="$CFLAGS"
+	CFLAGS="$CFLAGS $PYTHON_CFLAGS"
+	if test "$cross_compiling" = yes; then :
+  true
 else
-  RDYNAMIC="-rdynamic"
-		   LDFLAGS="$old_LDFLAGS $RDYNAMIC"
-		   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include "${have_libpython}/Python.h"
+int
+main ()
+{
+int err;
+	     Py_Initialize ();
+	     err = PyRun_SimpleString ("import itertools\n");
+	     Py_Finalize ();
+	     return err == 0 ? 0 : 1;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  dynamic_list=true
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+	CFLAGS="$old_CFLAGS"
+      fi
+      if $dynamic_list;then
+	found="-Wl,--dynamic-list"
+	RDYNAMIC='-Wl,--dynamic-list=$(srcdir)/proc-service.list'
+      else
+	RDYNAMIC="-rdynamic"
+	LDFLAGS="$old_LDFLAGS $RDYNAMIC"
+	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 int
@@ -14231,14 +14272,12 @@ if ac_fn_c_try_link "$LINENO"; then :
   found="-rdynamic"
 else
   found="no"
-				# Error on its usage by .mh file.
-				RDYNAMIC="no-rdynamic-available"
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
+		     # Error on its usage by .mh file.
+		     RDYNAMIC="no-rdynamic-available"
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+      fi
 
       LDFLAGS="$old_LDFLAGS"
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $found" >&5
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -80,3 +80,6 @@ gdb_test "source $srcdir/$subdir/source2.py" "yes"
 
 gdb_test "python print gdb.current_objfile()" "None"
 gdb_test "python print gdb.objfiles()" "\\\[\\\]"
+
+# Test http://bugs.python.org/issue4434 workaround in configure.ac
+gdb_test "python import itertools; print 'IMPOR'+'TED'" "IMPORTED" "pythonX.Y/lib-dynload/*.so"


  reply	other threads:[~2010-06-05 12:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-13 13:27 Jan Kratochvil
2010-05-13 15:47 ` H.J. Lu
2010-05-16 21:08   ` Jan Kratochvil
2010-05-27 19:58     ` Tom Tromey
2010-05-28 23:11       ` Jan Kratochvil
2010-06-05  2:48         ` Doug Evans
2010-06-05 12:45           ` Jan Kratochvil [this message]
2010-06-08 15:23             ` Doug Evans
2010-06-08 16:08               ` Jan Kratochvil
2010-06-08 16:12                 ` Doug Evans
2010-06-08 17:37                   ` Jan Kratochvil
2012-01-12 19:28           ` [patch] -Wl,--dynamic-list: Test also PYTHON_LIBS, not just PYTHON_CFLAGS [Re: [patch] Smaller gdb: -rdynamic -> -Wl,--dynamic-list] Jan Kratochvil
2010-06-13 19:58     ` [patch] Smaller gdb: -rdynamic -> -Wl,--dynamic-list Andreas Schwab
2010-06-13 20:17       ` Andreas Schwab
2010-06-15 17:31         ` Tom Tromey
2010-06-15 19:09           ` Jan Kratochvil
2010-06-15 20:36           ` Jan Kratochvil
2010-06-21 18:26             ` Tom Tromey
2010-06-23 10:13               ` Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100605124522.GA31976@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox