public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Fix "-Wl,--dynamic-list" gdb/configure test
  2016-04-12 15:18 [PATCH 0/2] Fix for PR gdb/16818 (make -Wl,--dynamic-list work again) Pedro Alves
@ 2016-04-12 15:18 ` Pedro Alves
  2016-04-12 15:18 ` [PATCH 2/2] Fix PR gdb/16818, workaround Python's forcing of -export-dynamic Pedro Alves
  1 sibling, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2016-04-12 15:18 UTC (permalink / raw)
  To: gdb-patches

The -Wl,--dynamic-list test is currently broken on Fedora 23, when you
configure with --with-python=python3.4.  We see:

 configure:13741: checking for the dynamic export flag
 configure:13796: gcc -o conftest -g3 -O0  -fno-strict-aliasing -DNDEBUG -fwrapv    -Wl,--dynamic-list=/home/pedro/gdb/mygit/src/gdb/proc-service.list conftest.c -ldl -lncurses -lm -ldl  -lpthread -ldl -lutil -lm -lpython3.4m -Xlinker -export-dynamic >&5
 conftest.c:182:30: fatal error: python3.4/Python.h: No such file or directory
 compilation terminated.
 configure:13796: $? = 1

The correct -I path is in PYTHON_CPPFLAGS:

 PYTHON_CPPFLAGS='-I/usr/include/python3.4m -I/usr/include/python3.4m'

(Other Python-related tests in the file are already doing this.)

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* configure.ac (checking for the dynamic export flag): Add
	$PYTHON_CPPFLAGS to CPPFLAGS.
	* configure: Regenerate.
---
 gdb/configure    | 5 ++++-
 gdb/configure.ac | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index b523deb..2b3c978 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -13775,12 +13775,14 @@ rm -f core conftest.err conftest.$ac_objext \
      CFLAGS="$CFLAGS $PYTHON_CFLAGS"
      old_LIBS="$LIBS"
      LIBS="$LIBS $PYTHON_LIBS"
+     old_CPPFLAGS="$CPPFLAGS"
+     CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
      if test "$cross_compiling" = yes; then :
   true
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include "${have_libpython}/Python.h"
+#include "Python.h"
 int
 main ()
 {
@@ -13802,6 +13804,7 @@ fi
 
      LIBS="$old_LIBS"
      CFLAGS="$old_CFLAGS"
+     CPPFLAGS="$old_CPPFLAGS"
    fi
    LDFLAGS="$old_LDFLAGS"
 fi
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 70452d3..4476545 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1722,9 +1722,11 @@ if test "${gdb_native}" = yes; then
      CFLAGS="$CFLAGS $PYTHON_CFLAGS"
      old_LIBS="$LIBS"
      LIBS="$LIBS $PYTHON_LIBS"
+     old_CPPFLAGS="$CPPFLAGS"
+     CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
      AC_RUN_IFELSE(
        AC_LANG_PROGRAM(
-         [#include "]${have_libpython}[/Python.h"],
+         [#include "Python.h"],
          [int err;
           Py_Initialize ();
           err = PyRun_SimpleString ("import itertools\n");
@@ -1733,6 +1735,7 @@ if test "${gdb_native}" = yes; then
        [dynamic_list=true], [], [true])
      LIBS="$old_LIBS"
      CFLAGS="$old_CFLAGS"
+     CPPFLAGS="$old_CPPFLAGS"
    fi
    LDFLAGS="$old_LDFLAGS"
 fi
-- 
2.5.5

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

* [PATCH 2/2] Fix PR gdb/16818, workaround Python's forcing of -export-dynamic
  2016-04-12 15:18 [PATCH 0/2] Fix for PR gdb/16818 (make -Wl,--dynamic-list work again) Pedro Alves
  2016-04-12 15:18 ` [PATCH 1/2] Fix "-Wl,--dynamic-list" gdb/configure test Pedro Alves
@ 2016-04-12 15:18 ` Pedro Alves
  1 sibling, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2016-04-12 15:18 UTC (permalink / raw)
  To: gdb-patches

GDB's use of --dynamic-list to only export the proc-service symbols is
broken due to Python's "python-config --ldflags" saying we should link
with -export-dynamic, causing us to export _all_ extern symbols
anyway.  On Fedora 23:

 $ python-config --ldflags
 -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic
 $ python3.4-config --ldflags
  -L/usr/lib64 -lpython3.4m -lpthread -ldl  -lutil -lm  -Xlinker -export-dynamic

Having GDB export all its symbols leads to issues such as PR gdb/16818
(GDB crashes when using name for target remote hostname:port), where a
GDB symbol unintentionally preempts a symbol in one of the NSS modules
glibc loads into the process.  NSS modules should not define symbols
outside the implementation namespace or the relevant standards, but,
alas, that's a longstanding and hard to fix issue.  See libc-alpha
discussion at:

  [symbol name space issues with NSS modules]
  https://sourceware.org/ml/libc-alpha/2016-04/msg00130.html

Python should instead be either using GCC's symbol visibility feature
or -Wl,--dynamic-list as well, to only export Python API symbols, but,
it doesn't.  There are bugs open upstream for that:

  [Use -Wl,--dynamic-list=x.list, not -Xlinker -export-dynamic]
  http://bugs.python.org/issue10112

  [Use GCC visibility attrs in PyAPI_*]
  http://bugs.python.org/issue11410

But that's taking a long while to resolve.

I thought of working around this Python issue by making GDB build with
-fvisibility=hidden, as Jan suggests in Python issue 10112, as then
Python's "-Xlinker -export-dynamic" has no effect.  However, that
would need to be done in the whole source tree (bfd, libiberty, etc.),
and I think that would break GCC plugins, as I believe those have
access to all of GCCs symbols, by "design".  So we'd need a new
configure switch, or have the libraries in the tree detect which of
GCC or GDB is being built, but that doesn't work, because the answer
can be "both" with combined builds...

So this patch instead works around Python's bug, by simply sed'ing
away "-Xlinker -export-dynamic" from the result of python-config.py
--ldflags, making -Wl,--dynamic-list work again as it used to.  It's
ugly, but so is the bug...

Note that if -Wl,--dynamic-list doesn't work, we always link with
-rdynamic, so static Python should still work.

Tested on F23 with --python=python (Python 2.7) and
--python=python3.4.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* configure.ac (PYTHON_LIBS): Sed away "-Xlinker -export-dynamic".
	* configure: Regenerate.
---
 gdb/configure    | 14 ++++++++++++++
 gdb/configure.ac | 14 ++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/gdb/configure b/gdb/configure
index 2b3c978..077219c 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -9458,6 +9458,14 @@ else
   CONFIG_SRCS="$CONFIG_SRCS python/python.c"
 fi
 
+# Work around Python http://bugs.python.org/issue10112.  See also
+# http://bugs.python.org/issue11410, otherwise -Wl,--dynamic-list has
+# no effect.  Note that the only test after this that uses Python is
+# the -rdynamic/-Wl,--dynamic-list test, and we do want that one to be
+# run without -export-dynamic too.
+PYTHON_LIBS=`echo $PYTHON_LIBS | sed -e 's/-Xlinker -export-dynamic//'`
+
+
 
 
  if test "${have_libpython}" != no; then
@@ -13771,6 +13779,12 @@ rm -f core conftest.err conftest.$ac_objext \
      # 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.
+
+     # Note the workaround for Python
+     # http://bugs.python.org/issue10112 earlier has removed
+     # -export-dynamic from PYTHON_LIBS.  That's exactly what we want
+     # here too, as otherwise it'd make this -Wl,--dynamic-list test
+     # always pass.
      old_CFLAGS="$CFLAGS"
      CFLAGS="$CFLAGS $PYTHON_CFLAGS"
      old_LIBS="$LIBS"
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 4476545..0fe261f 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1024,6 +1024,14 @@ else
   CONFIG_OBS="$CONFIG_OBS python.o"
   CONFIG_SRCS="$CONFIG_SRCS python/python.c"
 fi
+
+# Work around Python http://bugs.python.org/issue10112.  See also
+# http://bugs.python.org/issue11410, otherwise -Wl,--dynamic-list has
+# no effect.  Note that the only test after this that uses Python is
+# the -rdynamic/-Wl,--dynamic-list test, and we do want that one to be
+# run without -export-dynamic too.
+PYTHON_LIBS=`echo $PYTHON_LIBS | sed -e 's/-Xlinker -export-dynamic//'`
+
 AC_SUBST(PYTHON_CFLAGS)
 AC_SUBST(PYTHON_CPPFLAGS)
 AC_SUBST(PYTHON_LIBS)
@@ -1718,6 +1726,12 @@ if test "${gdb_native}" = yes; then
      # 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.
+
+     # Note the workaround for Python
+     # http://bugs.python.org/issue10112 earlier has removed
+     # -export-dynamic from PYTHON_LIBS.  That's exactly what we want
+     # here too, as otherwise it'd make this -Wl,--dynamic-list test
+     # always pass.
      old_CFLAGS="$CFLAGS"
      CFLAGS="$CFLAGS $PYTHON_CFLAGS"
      old_LIBS="$LIBS"
-- 
2.5.5

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

* [PATCH 0/2] Fix for PR gdb/16818 (make -Wl,--dynamic-list work again)
@ 2016-04-12 15:18 Pedro Alves
  2016-04-12 15:18 ` [PATCH 1/2] Fix "-Wl,--dynamic-list" gdb/configure test Pedro Alves
  2016-04-12 15:18 ` [PATCH 2/2] Fix PR gdb/16818, workaround Python's forcing of -export-dynamic Pedro Alves
  0 siblings, 2 replies; 3+ messages in thread
From: Pedro Alves @ 2016-04-12 15:18 UTC (permalink / raw)
  To: gdb-patches

GDB's use of --dynamic-list to only export the proc-service symbols is
broken due to Python's "python-config --ldflags" saying we should link
with -export-dynamic, causing gdb to export _all_ its extern symbols
anyway.

Having GDB export all its symbols leads to symbol conflicts issues
such as PR gdb/16818 (GDB crashes when using name for target remote
hostname:port), where a GDB symbol (timeval_add, in libiberty)
unintentionally preempts a symbol in one of the NSS modules glibc
loads into the process.

More info in patch #2.

Regardless, it'd be good to get back GDB's dynamic symbol table size
optimization anyway, for size and load time reasons alone -- this
strips away ~300KB from GDB's binary.

Pedro Alves (2):
  Fix "-Wl,--dynamic-list" gdb/configure test
  Fix PR gdb/16818, workaround Python's forcing of -export-dynamic

 gdb/configure    | 19 ++++++++++++++++++-
 gdb/configure.ac | 19 ++++++++++++++++++-
 2 files changed, 36 insertions(+), 2 deletions(-)

-- 
2.5.5

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

end of thread, other threads:[~2016-04-12 15:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-12 15:18 [PATCH 0/2] Fix for PR gdb/16818 (make -Wl,--dynamic-list work again) Pedro Alves
2016-04-12 15:18 ` [PATCH 1/2] Fix "-Wl,--dynamic-list" gdb/configure test Pedro Alves
2016-04-12 15:18 ` [PATCH 2/2] Fix PR gdb/16818, workaround Python's forcing of -export-dynamic Pedro Alves

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).