[patch] -Wl,--dynamic-list: Test also PYTHON_LIBS, not just PYTHON_CFLAGS [Re: [patch] Smaller gdb: -rdynamic -> -Wl,--dynamic-list]

Jan Kratochvil
2012-01-12T18:48:17Z

Hello Doug,

On Sat, 05 Jun 2010 04:48:33 +0200, Doug Evans wrote:
> I've been playing with this a bit and got the following:
>
> "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 found current FSF GDB HEAD always uses -rdynamic with libpython as it
falsely thinks -Wl,--dynamic-list is incompatible:

configure:14652: gcc -o conftest -m64 -ggdb2 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -fno-strict-aliasing -DNDEBUG -fwrapv -lmcheck -Wl,--dynamic-list=./proc-service.list conftest.c -ldl -lncurses -lz -lm >&5
/tmp/ccgMCqKR.o: In function `main':
/home/jkratoch/redhat/gdb-clean/gdb/conftest.c:212: undefined reference to `Py_Initialize'
/home/jkratoch/redhat/gdb-clean/gdb/conftest.c:213: undefined reference to `PyRun_SimpleStringFlags'
/home/jkratoch/redhat/gdb-clean/gdb/conftest.c:214: undefined reference to `Py_Finalize'

It does not make a difference now as with Python it would use -Xlinker
-export-dynamic on top of it anyway due to Python issue10112. But after it
gets fixed in Python GDB could become smaller (+its ld and ld.so faster) with
this patch.

It is mostly obvious it should use all the PYTHON_* compilation flags and not
just PYTHON_CFLAGS. But I would welcome a test on your static libpython.a
config if it does not break anything.

Thanks,
Jan

2012-01-12 Jan Kratochvil <jan.kratochvil@redhat.com>

* configure.ac [${gdb_native} && ${have_libpython}]: Use also
PYTHON_CPPFLAGS and PYTHON_LIBS.
* configure: Regenerate.

--- gdb/configure 2 Jan 2012 02:28:56 -0000 1.336
+++ gdb/configure 12 Jan 2012 18:43:25 -0000
@@ -14631,6 +14631,10 @@ rm -f core conftest.err conftest.$ac_obj
# Problem does not happen for the recommended libpythonX.Y.so linkage.
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $PYTHON_CFLAGS"
+ old_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
+ old_LIBS="$LIBS"
+ LIBS="$LIBS $PYTHON_LIBS"
if test "$cross_compiling" = yes; then :
true
else
@@ -14657,6 +14661,8 @@ rm -f core *.core core.conftest.* gmon.o
fi

CFLAGS="$old_CFLAGS"
+ CPPFLAGS="$old_CPPFLAGS"
+ LIBS="$old_LIBS"
fi
LDFLAGS="$old_LDFLAGS"
fi
--- gdb/configure.ac 4 Jan 2012 08:17:00 -0000 1.152
+++ gdb/configure.ac 12 Jan 2012 18:43:27 -0000
@@ -1576,6 +1576,10 @@ if test "${gdb_native}" = yes; then
# Problem does not happen for the recommended libpythonX.Y.so linkage.
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $PYTHON_CFLAGS"
+ old_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
+ old_LIBS="$LIBS"
+ LIBS="$LIBS $PYTHON_LIBS"
AC_RUN_IFELSE(
AC_LANG_PROGRAM(
[#include "]${have_libpython}[/Python.h"],
@@ -1586,6 +1590,8 @@ if test "${gdb_native}" = yes; then
return err == 0 ? 0 : 1;]),
[dynamic_list=true], [], [true])
CFLAGS="$old_CFLAGS"
+ CPPFLAGS="$old_CPPFLAGS"
+ LIBS="$old_LIBS"
fi
LDFLAGS="$old_LDFLAGS"
fi