public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add --with-static-mpfr-gmp for statically linking MPFR/GMP libs
@ 2024-05-27 10:54 Jones Syue 薛懷宗
  2024-05-27 11:01 ` Andrew Pinski
  2024-05-27 12:01 ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Jones Syue 薛懷宗 @ 2024-05-27 10:54 UTC (permalink / raw)
  To: gdb-patches

This patch adds an option to build gdb statically linking with MPFR library
and GMP library, in order to make it more friendly to run gdb on target
machines without manually uploading and locating required MPFR/GMP
libraries on target machines.

When upgrading to latest gdb-14.2 (from old gdb-7) for my cross environment
x86_64[1] & arm[2], run it on target-specific machines, in the first place
it is not able to run, because two libraries are not found, MPFR library
and GMP library, which are required[3][4] for latest gdb-14.2:

$ gdb: error while loading shared libraries: libmpfr.so.6: cannot open
shared object file: No such file or directory
$ ldd gdb | grep -E "mpfr|gmp"
        libmpfr.so.6 => not found
        libgmp.so.10 => not found

After uploading these two libraries to target machines gdb works fine, but
it is a bit not friendly because it needs extra steps to upload libraries
to target machines and guide gdb to locate paths of these libraries.

This patch adds a configure option '--with-static-mpfr-gmp', default is no.
If additionally specifying '--with-static-mpfr-gmp', it would pass
'-l:libmpfr.a -l:libgmp.a' to gnu ld linker[5], and make gdb statically
linking with MPFR library and GMP library, it is more friendly to run gdb
on target machines without considering where is required MPFR/GMP libs. If
this option is not specified by default, it would pass '-lmpfr -lgmp' for
dynamic linking as old days.

* configure.ac: Add --with-static-mpfr-gmp.
* configure: Re-generate.

[1] gcc-4.9.2, glibc-2.21, gmp-6.3.0, mpfr-4.2.1, x86_64-linux-gnu-gcc
[2] gcc-4.8.2, glibc-2.17, gmp-6.3.0, mpfr-4.2.1, arm-linux-gnueabihf-gcc
[3] Commit 3401f947d861 ("Improve documentation of GDB build requirements
    and options)"
[4] Commit 904cb749cf4e ("gdb.texinfo: Document GMP as mandatory
    requirement to build GDB")
[5] https://sourceware.org/binutils/docs/ld/Options.html

Signed-off-by: Jones Syue <jonessyue@qnap.com>
---
 configure    | 19 ++++++++++++++++++-
 configure.ac | 12 +++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 6466b97f3ec0..f2a72c6bec09 100755
--- a/configure
+++ b/configure
@@ -819,6 +819,7 @@ enable_libssp
 enable_libstdcxx
 enable_bootstrap
 enable_pgo_build
+with_static_mpfr_gmp
 with_mpc
 with_mpc_include
 with_mpc_lib
@@ -1601,6 +1602,8 @@ Optional Packages:
   --with-system-zlib      use installed libz
   --with-zstd             Support zstd compressed debug sections
                           (default=auto)
+  --with-static-mpfr-gmp  Statically linking MPFR library and GMP library
+                          (default=no)
   --with-mpc=PATH         specify prefix directory for installed MPC package.
                           Equivalent to --with-mpc-include=PATH/include plus
                           --with-mpc-lib=PATH/lib
@@ -8009,7 +8012,21 @@ if test -d ${srcdir}/gdb ; then
   fi
 fi
 
-gmplibs="-lmpfr -lgmp"
+
+# Check whether --with-static-mpfr-gmp was given.
+if test "${with_static_mpfr_gmp+set}" = set; then :
+  withval=$with_static_mpfr_gmp;
+else
+  with_static_mpfr_gmp=no
+fi
+
+
+if test "${with_static_mpfr_gmp}" = yes; then :
+  gmplibs="-l:libmpfr.a -l:libgmp.a"
+else
+  gmplibs="-lmpfr -lgmp"
+fi
+
 if test x"$require_mpc" = "xyes" ; then
   gmplibs="-lmpc $gmplibs"
 fi
diff --git a/configure.ac b/configure.ac
index 1300a805fd8d..e2b7e3ab6ab5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1556,7 +1556,17 @@ if test -d ${srcdir}/gdb ; then
   fi
 fi
 
-gmplibs="-lmpfr -lgmp"
+AC_ARG_WITH(static-mpfr-gmp,
+[AS_HELP_STRING([--with-static-mpfr-gmp],
+                [Statically linking MPFR library and GMP library (default=no)])],
+[], [with_static_mpfr_gmp=no])
+
+if test "${with_static_mpfr_gmp}" = yes; then :
+  gmplibs="-l:libmpfr.a -l:libgmp.a"
+else
+  gmplibs="-lmpfr -lgmp"
+fi
+
 if test x"$require_mpc" = "xyes" ; then
   gmplibs="-lmpc $gmplibs"
 fi
-- 
2.1.4


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

* Re: [PATCH] Add --with-static-mpfr-gmp for statically linking MPFR/GMP libs
  2024-05-27 10:54 [PATCH] Add --with-static-mpfr-gmp for statically linking MPFR/GMP libs Jones Syue 薛懷宗
@ 2024-05-27 11:01 ` Andrew Pinski
  2024-05-28  2:45   ` Jones Syue 薛懷宗
  2024-05-27 12:01 ` Eli Zaretskii
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Pinski @ 2024-05-27 11:01 UTC (permalink / raw)
  To: Jones Syue 薛懷宗; +Cc: GDB Patches

[-- Attachment #1: Type: text/plain, Size: 4942 bytes --]

On Mon, May 27, 2024, 3:54 AM Jones Syue 薛懷宗 <jonessyue@qnap.com> wrote:

> This patch adds an option to build gdb statically linking with MPFR library
> and GMP library, in order to make it more friendly to run gdb on target
> machines without manually uploading and locating required MPFR/GMP
> libraries on target machines.
>
> When upgrading to latest gdb-14.2 (from old gdb-7) for my cross environment
> x86_64[1] & arm[2], run it on target-specific machines, in the first place
> it is not able to run, because two libraries are not found, MPFR library
> and GMP library, which are required[3][4] for latest gdb-14.2:
>
> $ gdb: error while loading shared libraries: libmpfr.so.6: cannot open
> shared object file: No such file or directory
> $ ldd gdb | grep -E "mpfr|gmp"
>         libmpfr.so.6 => not found
>         libgmp.so.10 => not found
>
> After uploading these two libraries to target machines gdb works fine, but
> it is a bit not friendly because it needs extra steps to upload libraries
> to target machines and guide gdb to locate paths of these libraries.
>
> This patch adds a configure option '--with-static-mpfr-gmp', default is no.
> If additionally specifying '--with-static-mpfr-gmp', it would pass
> '-l:libmpfr.a -l:libgmp.a' to gnu ld linker[5], and make gdb statically
> linking with MPFR library and GMP library, it is more friendly to run gdb
> on target machines without considering where is required MPFR/GMP libs. If
> this option is not specified by default, it would pass '-lmpfr -lgmp' for
> dynamic linking as old days.
>
> * configure.ac: Add --with-static-mpfr-gmp.
> * configure: Re-generate.
>


Since this touches the toplevel configure, it should also be sent to
binutils@ and gcc-patches@ (gcc source base is technically the main version
of it and it is shared between all 3).
Second this only seems to work with gnu ld. It won't work with Mac os ld or
Solaris ld.

Also for gcc, the additional, mpc should be linked statically if either are
linked that way.

It might be just better to place the sources of gmp/mpfr to the toplevel
src directory to get them statically linking without worry about any extra
options. Since that works today.

Thanks,
Andrew


> [1] gcc-4.9.2, glibc-2.21, gmp-6.3.0, mpfr-4.2.1, x86_64-linux-gnu-gcc
> [2] gcc-4.8.2, glibc-2.17, gmp-6.3.0, mpfr-4.2.1, arm-linux-gnueabihf-gcc
> [3] Commit 3401f947d861 ("Improve documentation of GDB build requirements
>     and options)"
> [4] Commit 904cb749cf4e ("gdb.texinfo: Document GMP as mandatory
>     requirement to build GDB")
> [5] https://sourceware.org/binutils/docs/ld/Options.html
>
> Signed-off-by: Jones Syue <jonessyue@qnap.com>
> ---
>  configure    | 19 ++++++++++++++++++-
>  configure.ac | 12 +++++++++++-
>  2 files changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index 6466b97f3ec0..f2a72c6bec09 100755
> --- a/configure
> +++ b/configure
> @@ -819,6 +819,7 @@ enable_libssp
>  enable_libstdcxx
>  enable_bootstrap
>  enable_pgo_build
> +with_static_mpfr_gmp
>  with_mpc
>  with_mpc_include
>  with_mpc_lib
> @@ -1601,6 +1602,8 @@ Optional Packages:
>    --with-system-zlib      use installed libz
>    --with-zstd             Support zstd compressed debug sections
>                            (default=auto)
> +  --with-static-mpfr-gmp  Statically linking MPFR library and GMP library
> +                          (default=no)
>    --with-mpc=PATH         specify prefix directory for installed MPC
> package.
>                            Equivalent to --with-mpc-include=PATH/include
> plus
>                            --with-mpc-lib=PATH/lib
> @@ -8009,7 +8012,21 @@ if test -d ${srcdir}/gdb ; then
>    fi
>  fi
>
> -gmplibs="-lmpfr -lgmp"
> +
> +# Check whether --with-static-mpfr-gmp was given.
> +if test "${with_static_mpfr_gmp+set}" = set; then :
> +  withval=$with_static_mpfr_gmp;
> +else
> +  with_static_mpfr_gmp=no
> +fi
> +
> +
> +if test "${with_static_mpfr_gmp}" = yes; then :
> +  gmplibs="-l:libmpfr.a -l:libgmp.a"
> +else
> +  gmplibs="-lmpfr -lgmp"
> +fi
> +
>  if test x"$require_mpc" = "xyes" ; then
>    gmplibs="-lmpc $gmplibs"
>  fi
> diff --git a/configure.ac b/configure.ac
> index 1300a805fd8d..e2b7e3ab6ab5 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1556,7 +1556,17 @@ if test -d ${srcdir}/gdb ; then
>    fi
>  fi
>
> -gmplibs="-lmpfr -lgmp"
> +AC_ARG_WITH(static-mpfr-gmp,
> +[AS_HELP_STRING([--with-static-mpfr-gmp],
> +                [Statically linking MPFR library and GMP library
> (default=no)])],
> +[], [with_static_mpfr_gmp=no])
> +
> +if test "${with_static_mpfr_gmp}" = yes; then :
> +  gmplibs="-l:libmpfr.a -l:libgmp.a"
> +else
> +  gmplibs="-lmpfr -lgmp"
> +fi
> +
>  if test x"$require_mpc" = "xyes" ; then
>    gmplibs="-lmpc $gmplibs"
>  fi
> --
> 2.1.4
>
>

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

* Re: [PATCH] Add --with-static-mpfr-gmp for statically linking MPFR/GMP libs
  2024-05-27 10:54 [PATCH] Add --with-static-mpfr-gmp for statically linking MPFR/GMP libs Jones Syue 薛懷宗
  2024-05-27 11:01 ` Andrew Pinski
@ 2024-05-27 12:01 ` Eli Zaretskii
  2024-05-28  2:59   ` Jones Syue 薛懷宗
  1 sibling, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-05-27 12:01 UTC (permalink / raw)
  To: Jones Syue 薛懷宗; +Cc: gdb-patches

> From: Jones Syue 薛懷宗 <jonessyue@qnap.com>
> Date: Mon, 27 May 2024 10:54:12 +0000
> 
> +if test "${with_static_mpfr_gmp}" = yes; then :
> +  gmplibs="-l:libmpfr.a -l:libgmp.a"

I don't see this -l:LIBRARY.a syntax documented in the GCC manual.  Is
it universally accepted by compilers?

Thanks.

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

* Re: [PATCH] Add --with-static-mpfr-gmp for statically linking MPFR/GMP libs
  2024-05-27 11:01 ` Andrew Pinski
@ 2024-05-28  2:45   ` Jones Syue 薛懷宗
  0 siblings, 0 replies; 5+ messages in thread
From: Jones Syue 薛懷宗 @ 2024-05-28  2:45 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: GDB Patches

> Since this touches the toplevel configure, it should also be sent to 
> binutils@ and gcc-patches@ (gcc source base is technically the main 
> version of it and it is shared between all 3).
> Second this only seems to work with gnu ld. It won't work with Mac os ld 
> or Solaris ld.
Thank you Andrew for kind feedback!
I will go back to wiki first about these related mailing lists.
Yes im working on cross-compiling for linux specific target machine and gnu
ld linker is preferred by default; will find out otherway for compatibility
with various systems likd macOS ld or Solaris ld.

> Also for gcc, the additional, mpc should be linked statically if either 
> are linked that way.

Sure will go back to read mpc extensions based on mpfr/gmp.

> It might be just better to place the sources of gmp/mpfr to the toplevel 
> src directory to get them statically linking without worry about any 
> extra options. Since that works today.

This sounds great! will try to put them on toplevel src directory tree.

--

Regards,
Jones Syue | 薛懷宗
QNAP Systems, Inc.

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

* Re: [PATCH] Add --with-static-mpfr-gmp for statically linking MPFR/GMP libs
  2024-05-27 12:01 ` Eli Zaretskii
@ 2024-05-28  2:59   ` Jones Syue 薛懷宗
  0 siblings, 0 replies; 5+ messages in thread
From: Jones Syue 薛懷宗 @ 2024-05-28  2:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

> I don't see this -l:LIBRARY.a syntax documented in the GCC manual.  Is
> it universally accepted by compilers?

Thank you Eli for kind feedback!
iiuc this '-l:LIBRARY.a' syntax is specific for gnu ld linker, quoted from
gnu ld manual: https://sourceware.org/binutils/docs/ld/Options.html

-l namespec
--library=namespec

Add the archive or object file specified by namespec to the list of files 
to link. This option may be used any number of times. If namespec is of 
the form :filename, ld will search the library path for a file called 
filename, otherwise it will search the library path for a file called 
libnamespec.a.

This '-l:LIBRARY.a' syntax looks like not compatible with Solaris ld or 
macOS ld, perhaps use alternate like '-Bstatic' or '-Wl,-Bstatic' to pass
it to various ld, will dig further with developer manuals.

--

Regards,
Jones Syue | 薛懷宗
QNAP Systems, Inc.

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

end of thread, other threads:[~2024-05-28  2:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-27 10:54 [PATCH] Add --with-static-mpfr-gmp for statically linking MPFR/GMP libs Jones Syue 薛懷宗
2024-05-27 11:01 ` Andrew Pinski
2024-05-28  2:45   ` Jones Syue 薛懷宗
2024-05-27 12:01 ` Eli Zaretskii
2024-05-28  2:59   ` Jones Syue 薛懷宗

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