Bug 28500

Summary: Failure to find libgmp
Product: gdb Reporter: 64m
Component: buildAssignee: Andrew Pinski <pinskia>
Severity: critical CC: bldenton, karel.gardas, Mario.Klebsch, pinskia, ro, simon.marchi, sourceware, tromey
Priority: P2    
Version: 11.1   
Target Milestone: 14.1   
Host: Target:
Build: Last reconfirmed: 2022-02-27 00:00:00
Attachments: gdb/config.log
Patch which uses the toplevel configure to find gmp/libmpfr
Patch against the trunk

Description 64m 2021-10-26 18:34:41 UTC
I have tried to compile GDB 11.1. Libgmp is not found even I specified path to it. 

configure: error: GMP is missing or unusable

Configured with:
../../src/gdb-11.1/configure --prefix=/home/mapniv/prog/riscv64-gdb --target=riscv64-none-elf --with-gmp-include=/home/mapniv/prog/gmp/include --with-gmp-lib=/home/mapniv/prog/gmp/lib --with-mpc=/home/mapniv/prog/mpc --with-mpfr=/home/mapniv/prog/mpfr
Comment 1 64m 2021-10-26 18:50:43 UTC
It is most likely related to https://sourceware.org/bugzilla/show_bug.cgi?id=28332
Comment 2 64m 2021-10-26 18:52:48 UTC
It is most likely related to https://sourceware.org/bugzilla/show_bug.cgi?id=28332
Comment 3 Tom Tromey 2022-02-27 20:54:16 UTC
Are your symptoms the same as the ones in bug 28332?
If so I guess we can close as a dup.
Otherwise, we can investigate more.
Maybe the contents of gdb/config.log would be interesting.
Comment 4 64m 2022-03-06 09:55:57 UTC
I'm sorry to answer this late. I thought no one would answer to this bug request. 

No, they are not. I was able to build GDB with GMP installed to standard location, but was unable to build it with GMP installed to custom location.
That is options '--with-gmp', '--with-gmp-lib' and '--with-gmp-include' do not work.
Comment 5 64m 2022-03-06 10:42:36 UTC
Created attachment 14006 [details]

Attached gdb/config.log.
Comment 6 64m 2022-03-06 10:44:52 UTC
Above attachment was generated when building GDB 11.2 and not 11.1.
Comment 7 Tom Tromey 2022-03-06 15:52:04 UTC
Ok, I think there was a thread about this on gdb-patches
last year.  For some reason there are two different sets
of GMP flags to configure, and gdb doesn't respect the
top-level ones:

prentzel. ./configure --help|grep gmp
  --with-gmp-dir=PATH     this option has been REMOVED
  --with-gmp=PATH         specify prefix directory for the installed GMP
                          --with-gmp-include=PATH/include plus
  --with-gmp-include=PATH specify directory for installed GMP include files
  --with-gmp-lib=PATH     specify directory for the installed GMP library
prentzel. ./gdb/configure --help|grep gmp
  --with-libgmp-prefix[=DIR]  search for libgmp in DIR/include and DIR/lib
  --without-libgmp-prefix     don't search for libgmp in includedir and libdir
  --with-libgmp-type=TYPE     type of library to search for (auto/static/shared)

So, I suggest trying the ones that gdb/configure reports.
Top-level configure will pass these down despite the fact
that it doesn't know about them.
Comment 8 Tom Tromey 2022-03-06 15:54:23 UTC
Found the thread, didn't read it yet:

Comment 9 Tom Tromey 2022-03-06 16:09:06 UTC
*** Bug 28625 has been marked as a duplicate of this bug. ***
Comment 10 Tom Tromey 2022-03-06 16:09:14 UTC
*** Bug 28332 has been marked as a duplicate of this bug. ***
Comment 11 Tom Tromey 2022-03-06 16:09:31 UTC
*** Bug 27762 has been marked as a duplicate of this bug. ***
Comment 12 Karel Gardas 2022-05-02 20:13:18 UTC
The bug may also be duplicated on gdb 12.1.
Comment 13 Boris N. 2022-07-28 15:40:50 UTC
Bug still exists in gdb 12.1.

> So, I suggest trying the ones that gdb/configure reports [i.e. --with-gmp-prefix=DIR].

This only works if includes and libraries can be found in DIR/include and DIR/lib which is not always the case. E.g. for multi-arch systems the library path may be in DIR/lib32 or DIR/lib64. It would be nice if the gdb/configure could support the settings passed from the top configure via --with-gmp-include/--with-gmp-lib options. (Same applies to libmpfr which can be specified with --with-mpfr-* configure options but are ignored in gdb/configure.)
Comment 14 Simon Marchi 2022-07-28 16:02:11 UTC
This is really messy.  Basically, the top-level configure has the --with-gmp* flags because we sync that configure script with gcc (which lives in another repo).  But apart from GDB, nothing in binutils-gdb uses GMP.  And when the time came for GDB to use GMP, it was decided for some reason to use the AC_LIB_HAVE_LINKFLAGS macro (I suppose because it was handy), which provides the --with-libgmp-prefix flags.  So in the binutils-gdb repo, we have some --with-gmp* flags at the top-level which don't do anything, but that people use (understandably so), because that's what the top-level "./configure --help" tells them to use.  And then we have the flags that gdb/configure uses that actually do something, but are not sufficient.

I don't know how feasible it is, but I think at this point we should make GDB understand the --with-gmp* flags in addition to the --with-libgmp* flags.
Comment 15 Andrew Pinski 2022-11-08 02:58:10 UTC
I found building with GMP to be useful too. Especially when doing Canadian cross builds. Then you don't need to build GMP seperately for the target you can just use the one that is newly built. Especially when it comes to doing combined builds too (which I still do). I should figure out how to clean up my patches and submit them upstream for this.
Comment 16 Andrew Pinski 2022-11-08 03:01:36 UTC
The only issue with my current patch really is that MPC also becomes a dependency which might be ok.
Comment 17 Andrew Pinski 2022-11-08 07:26:14 UTC
Created attachment 14436 [details]
Patch which uses the toplevel configure to find gmp/libmpfr

I will submit this patch soon; tomorrow. It is based on the gdb 12.1 release but I don't think much has changed there yet.
Note it does change to always require MPFR rather than having it as an optional feature (with a warning) unlike before.

It is better than my previous version which I did because I ran into this issue with gdb 8.3 as it does not cause MPC to be required for gdb now.

I also tested to make sure GMP and MPFR could build when in the source directory and be used just like it is for gcc too.
Comment 18 Andrew Pinski 2022-11-08 08:03:37 UTC
Created attachment 14437 [details]
Patch against the trunk

Will do the changelog tomorrow.
Comment 20 Sourceware Commits 2022-12-21 16:51:45 UTC
The master branch has been updated by Andrew Pinski <pinskia@sourceware.org>:


commit 991180627851801f1999d1ebbc0e569a17e47c74
Author: Andrew Pinski <apinski@marvell.com>
Date:   Tue Nov 8 07:57:18 2022 +0000

    Use toplevel configure for GMP and MPFR for gdb
    This patch uses the toplevel configure parts for GMP/MPFR for
    gdb. The only thing is that gdb now requires MPFR for building.
    Before it was a recommended but not required library.
    Also this allows building of GMP and MPFR with the toplevel
    directory just like how it is done for GCC.
    We now error out in the toplevel configure of the version
    of GMP and MPFR that is wrong.
    OK after GDB 13 branches? Build gdb 3 ways:
    with GMP and MPFR in the toplevel (static library used at that point for both)
    With only MPFR in the toplevel (GMP distro library used and MPFR built from source)
    With neither GMP and MPFR in the toplevel (distro libraries used)
    Changes from v1:
    * Updated gdb/README and gdb/doc/gdb.texinfo.
    * Regenerated using unmodified autoconf-2.69
    Andrew Pinski
            * Makefile.def: Add configure-gdb dependencies
            on all-gmp and all-mpfr.
            * configure.ac: Split out MPC checking from MPFR.
            Require GMP and MPFR if the gdb directory exist.
            * Makefile.in: Regenerate.
            * configure: Regenerate.
            PR bug/28500
            * configure.ac: Remove AC_LIB_HAVE_LINKFLAGS
            for gmp and mpfr.
            Use GMPLIBS and GMPINC which is provided by the
            toplevel configure.
            * Makefile.in (LIBGMP, LIBMPFR): Remove.
            (GMPLIBS, GMPINC): Add definition.
            (CLIBS): Exchange LIBMPFR and LIBGMP
            for GMPLIBS.
            * target-float.c: Make the code conditional on
            HAVE_LIBMPFR unconditional.
            * top.c: Remove code checking HAVE_LIBMPFR.
            * configure: Regenerate.
            * config.in: Regenerate.
            * README: Update GMP/MPFR section of the config
            * doc/gdb.texinfo: Likewise.
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28500
Comment 21 Andrew Pinski 2022-12-21 16:55:01 UTC
Fixed for GDB 14.