From patchwork Tue Apr 12 15:18:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 11710 Received: (qmail 28790 invoked by alias); 12 Apr 2016 15:18:32 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 28595 invoked by uid 89); 12 Apr 2016 15:18:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 12 Apr 2016 15:18:11 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 666CFC04B301 for ; Tue, 12 Apr 2016 15:18:09 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3CFI6Rv010793 for ; Tue, 12 Apr 2016 11:18:08 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/2] Fix PR gdb/16818, workaround Python's forcing of -export-dynamic Date: Tue, 12 Apr 2016 16:18:06 +0100 Message-Id: <1460474286-11973-3-git-send-email-palves@redhat.com> In-Reply-To: <1460474286-11973-1-git-send-email-palves@redhat.com> References: <1460474286-11973-1-git-send-email-palves@redhat.com> 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 * 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"