[v2] ld/gold: Use mallinfo2 over mallinfo if available

Message ID 20210319162712.3581704-1-raj.khem@gmail.com
State New
Headers show
Series
  • [v2] ld/gold: Use mallinfo2 over mallinfo if available
Related show

Commit Message

Alan Modra via Binutils March 19, 2021, 4:27 p.m.
mallinfo has been deprecated in recently glibc releases raising
deprecated-declarations when used, mallinfo2 has been introduced instead
which could be used ahead of mallinfo provided platform supports it

        PR gold/26585
        * main.cc (main):
        Prefer to use mallinfo2 over mallinfo when available.
        * configure.ac: Check for mallinfo2.
        * configure: Regenerate.
        * config.h: Likewise.
---
 gold/config.in    |  3 +++
 gold/configure    |  2 +-
 gold/configure.ac |  2 +-
 gold/main.cc      | 10 +++++++---
 4 files changed, 12 insertions(+), 5 deletions(-)

-- 
2.31.0

Comments

Alan Modra via Binutils March 19, 2021, 9:33 p.m. | #1
> mallinfo has been deprecated in recently glibc releases raising

> deprecated-declarations when used, mallinfo2 has been introduced instead

> which could be used ahead of mallinfo provided platform supports it


Thanks. I've committed the following patch, based on the original one
sent by Duncan Simpson.

The deprecation warnings, while appreciated (I've encountered the
overflow in the arena field quite often), seem premature, as my
(fairly recent) debian distro still does not have mallinfo2() in
glibc. I wouldn't suggest deprecating an old interface until the new
one is widely available.

2021-03-19  Duncan Simpson <dr.duncan.p.simpson@gmail.com>

gold/
        PR gold/26585
        * configure.ac: Add check for mallinfo2.
        * configure: Regenerate.
        * main.cc (main): Use mallinfo2 if available.

-cary
Alan Modra via Binutils March 19, 2021, 10:04 p.m. | #2
On Fri, Mar 19, 2021 at 2:33 PM Cary Coutant <ccoutant@gmail.com> wrote:
>

> > mallinfo has been deprecated in recently glibc releases raising

> > deprecated-declarations when used, mallinfo2 has been introduced instead

> > which could be used ahead of mallinfo provided platform supports it

>

> Thanks. I've committed the following patch, based on the original one

> sent by Duncan Simpson.

>

> The deprecation warnings, while appreciated (I've encountered the

> overflow in the arena field quite often), seem premature, as my

> (fairly recent) debian distro still does not have mallinfo2() in

> glibc. I wouldn't suggest deprecating an old interface until the new

> one is widely available.

>

> 2021-03-19  Duncan Simpson <dr.duncan.p.simpson@gmail.com>

>

> gold/

>         PR gold/26585

>         * configure.ac: Add check for mallinfo2.

>         * configure: Regenerate.

>         * main.cc (main): Use mallinfo2 if available.

>

> -cary



gold/config.in needs to be regenerated as well.
Alan Modra via Binutils March 19, 2021, 10:17 p.m. | #3
On Fri, Mar 19, 2021 at 2:33 PM Cary Coutant <ccoutant@gmail.com> wrote:
>

> > mallinfo has been deprecated in recently glibc releases raising

> > deprecated-declarations when used, mallinfo2 has been introduced instead

> > which could be used ahead of mallinfo provided platform supports it

>

> Thanks. I've committed the following patch, based on the original one

> sent by Duncan Simpson.

>

> The deprecation warnings, while appreciated (I've encountered the

> overflow in the arena field quite often), seem premature, as my

> (fairly recent) debian distro still does not have mallinfo2() in

> glibc. I wouldn't suggest deprecating an old interface until the new

> one is widely available.

>

> 2021-03-19  Duncan Simpson <dr.duncan.p.simpson@gmail.com>

>

> gold/

>         PR gold/26585

>         * configure.ac: Add check for mallinfo2.

>         * configure: Regenerate.

>         * main.cc (main): Use mallinfo2 if available.

>

> -cary



This patch is not correctly handling the issue where its using

      struct mallinfo m = mallinfo2();

it should have been

     struct mallinfo2 m = mallinfo2();

Would you mind taking the patch I posted and review the delta and
apply it to fix it ?
Alan Modra via Binutils March 19, 2021, 10:32 p.m. | #4
Oops, fixed both problems. Sorry -- the posted patch had broken line
endings, so I applied it by hand and missed that one crucial part.

-cary

On Fri, Mar 19, 2021 at 3:17 PM Khem Raj <raj.khem@gmail.com> wrote:
>

> On Fri, Mar 19, 2021 at 2:33 PM Cary Coutant <ccoutant@gmail.com> wrote:

> >

> > > mallinfo has been deprecated in recently glibc releases raising

> > > deprecated-declarations when used, mallinfo2 has been introduced instead

> > > which could be used ahead of mallinfo provided platform supports it

> >

> > Thanks. I've committed the following patch, based on the original one

> > sent by Duncan Simpson.

> >

> > The deprecation warnings, while appreciated (I've encountered the

> > overflow in the arena field quite often), seem premature, as my

> > (fairly recent) debian distro still does not have mallinfo2() in

> > glibc. I wouldn't suggest deprecating an old interface until the new

> > one is widely available.

> >

> > 2021-03-19  Duncan Simpson <dr.duncan.p.simpson@gmail.com>

> >

> > gold/

> >         PR gold/26585

> >         * configure.ac: Add check for mallinfo2.

> >         * configure: Regenerate.

> >         * main.cc (main): Use mallinfo2 if available.

> >

> > -cary

>

>

> This patch is not correctly handling the issue where its using

>

>       struct mallinfo m = mallinfo2();

>

> it should have been

>

>      struct mallinfo2 m = mallinfo2();

>

> Would you mind taking the patch I posted and review the delta and

> apply it to fix it ?

Patch

diff --git a/gold/config.in b/gold/config.in
index aaad1bee706..ca0b9d2e2f9 100644
--- a/gold/config.in
+++ b/gold/config.in
@@ -124,6 +124,9 @@ 
 /* Define to 1 if you have the `mallinfo' function. */
 #undef HAVE_MALLINFO
 
+/* Define to 1 if you have the `mallinfo2' function. */
+#undef HAVE_MALLINFO2
+
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
diff --git a/gold/configure b/gold/configure
index e264a65ac3c..b9f062b68eb 100755
--- a/gold/configure
+++ b/gold/configure
@@ -9967,7 +9967,7 @@  case "$ac_cv_search_dlopen" in
 esac
 
 
-for ac_func in mallinfo posix_fallocate fallocate readv sysconf times mkdtemp
+for ac_func in mallinfo mallinfo2 posix_fallocate fallocate readv sysconf times mkdtemp
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/gold/configure.ac b/gold/configure.ac
index eed45664093..1716a779416 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -636,7 +636,7 @@  case "$ac_cv_search_dlopen" in
 esac
 AC_SUBST(DLOPEN_LIBS)
 
-AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times mkdtemp)
+AC_CHECK_FUNCS(mallinfo mallinfo2 posix_fallocate fallocate readv sysconf times mkdtemp)
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
 # Use of ::std::tr1::unordered_map::rehash causes undefined symbols
diff --git a/gold/main.cc b/gold/main.cc
index ea77ca3ebbe..2b06466f829 100644
--- a/gold/main.cc
+++ b/gold/main.cc
@@ -290,10 +290,14 @@  main(int argc, char** argv)
               elapsed.sys / 1000, (elapsed.sys % 1000) * 1000,
               elapsed.wall / 1000, (elapsed.wall % 1000) * 1000);
 
-#ifdef HAVE_MALLINFO
-      struct mallinfo m = mallinfo();
+#if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2)
+#ifdef HAVE_MALLINFO2
+  #define MALLINFO_FN mallinfo2
+#else
+  #define MALLINFO_FN mallinfo
+#endif
       fprintf(stderr, _("%s: total space allocated by malloc: %lld bytes\n"),
-	      program_name, static_cast<long long>(m.arena));
+	      program_name, static_cast<long long>(MALLINFO_FN().arena));
 #endif
       File_read::print_stats();
       Archive::print_stats();