[PATCH][PR python/26832] Better static python detection in configure machinery.

Andrew Burgess andrew.burgess@embecosm.com
Thu Nov 5 09:46:42 GMT 2020


* Romain GEISSLER via Gdb-patches <gdb-patches@sourceware.org> [2020-11-03 23:34:05 +0000]:

> Hi,
> 
> The following patch fixes PR python/26832. My problem is that if I link gdb against a statically linked
> python 3 then all imports using a dynamic python module (like for example "import math" fails with symbol
> not found errors). It obvisouly comes from the fact that gdb wasn't linked with -rdynamic, as the symbols
> actually exists in gdb, but is not part of the dynamic symbol table. A test exists already in configure.ac
> to check exactly this case and use -rdynamic accordingly. However this tests works only for python 2.
> Indeed in python 2 itertools is a C-module, while it is a builtin in python 3, this the check always
> concludes that -rdynamic is not needed for python 3. In order to fix that, we should import a module that
> we know is a C-modules in both python 2 and 3, for example ctypes.
> 
> Tested on Linux x64 with gdb from branch 10 and Python 3.9. I tested only the case where python is linked
> statically.
> 
> Note: I don't have any copyright assignment, yet I do know it exists. I guess that in that case it falls
> under the "trivial" case and it's not needed ?

I'm don't claim to be an expert in this area, but your explanation
makes sense, and the patch seems fine to me.

I think such a small patch could go in as obvious.

Let's wait a week to see if anyone else has any feedback, if not I'm
happy to merge this for you.

Thanks,
Andrew



> 
> Cheers,
> Romain
> 
> 
> gdb/ChangeLog:
> 
> 2020-11-04  Romain Geissler  <romain.geissler@amadeus.com>
> 
> 	PR python/26832
> 
> 	* configure: Re-generate.
> 	* configure.ac: Check for python modules ctypes instead of
> 	itertools.
> 
> 
> From db6f022baeba25bd07d64ecdb8de0133d609feea Mon Sep 17 00:00:00 2001
> From: Romain Geissler <romain.geissler@amadeus.com>
> Date: Tue, 3 Nov 2020 23:07:52 +0000
> Subject: [PATCH] [PATCH][PR python/26832] Better static python detection in
>  configure machinery.
> 
> In python 3, itertools is a builtin module, so whether or not the python
> you link against is a shared or a static one, importing it works. Change
> the import test to ctypes which is a dynamic module in both python 2 and
> 3.
> ---
>  gdb/configure    | 2 +-
>  gdb/configure.ac | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/configure b/gdb/configure
> index aa89158d06d..4a03cd9c3ec 100755
> --- a/gdb/configure
> +++ b/gdb/configure
> @@ -16076,7 +16076,7 @@ main ()
>  {
>  int err;
>            Py_Initialize ();
> -          err = PyRun_SimpleString ("import itertools\n");
> +          err = PyRun_SimpleString ("import ctypes\n");
>            Py_Finalize ();
>            return err == 0 ? 0 : 1;
>    ;
> diff --git a/gdb/configure.ac b/gdb/configure.ac
> index bfc053ed096..1b9548eef3a 100644
> --- a/gdb/configure.ac
> +++ b/gdb/configure.ac
> @@ -1686,7 +1686,7 @@ if test "${gdb_native}" = yes; then
>           [#include "Python.h"],
>           [int err;
>            Py_Initialize ();
> -          err = PyRun_SimpleString ("import itertools\n");
> +          err = PyRun_SimpleString ("import ctypes\n");
>            Py_Finalize ();
>            return err == 0 ? 0 : 1;])],
>         [dynamic_list=true], [], [true])
> -- 
> 2.25.1


More information about the Gdb-patches mailing list