* [PATCH] ld/gold: Use mallinfo2 over mallinfo if available
@ 2021-03-18 22:09 Khem Raj
2021-03-19 7:55 ` Martin Liška
0 siblings, 1 reply; 3+ messages in thread
From: Khem Raj @ 2021-03-18 22:09 UTC (permalink / raw)
To: binutils
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 | 6 +++++-
4 files changed, 10 insertions(+), 3 deletions(-)
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..83f89150324 100644
--- a/gold/main.cc
+++ b/gold/main.cc
@@ -290,7 +290,11 @@ main(int argc, char** argv)
elapsed.sys / 1000, (elapsed.sys % 1000) * 1000,
elapsed.wall / 1000, (elapsed.wall % 1000) * 1000);
-#ifdef HAVE_MALLINFO
+#ifdef HAVE_MALLINFO2
+ struct mallinfo2 m = mallinfo2();
+ fprintf(stderr, _("%s: total space allocated by malloc: %lld bytes\n"),
+ program_name, static_cast<long long>(m.arena));
+#elif defined(HAVE_MALLINFO)
struct mallinfo m = mallinfo();
fprintf(stderr, _("%s: total space allocated by malloc: %lld bytes\n"),
program_name, static_cast<long long>(m.arena));
--
2.31.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ld/gold: Use mallinfo2 over mallinfo if available
2021-03-18 22:09 [PATCH] ld/gold: Use mallinfo2 over mallinfo if available Khem Raj
@ 2021-03-19 7:55 ` Martin Liška
2021-03-19 8:21 ` Khem Raj
0 siblings, 1 reply; 3+ messages in thread
From: Martin Liška @ 2021-03-19 7:55 UTC (permalink / raw)
To: Khem Raj, binutils
On 3/18/21 11:09 PM, Khem Raj via Binutils 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
Hello.
I support the change as the old mallinfo overflows at 2GB memory.
... snip...
>
> -#ifdef HAVE_MALLINFO
> +#ifdef HAVE_MALLINFO2
> + struct mallinfo2 m = mallinfo2();
> + fprintf(stderr, _("%s: total space allocated by malloc: %lld bytes\n"),
> + program_name, static_cast<long long>(m.arena));
> +#elif defined(HAVE_MALLINFO)
> struct mallinfo m = mallinfo();
> fprintf(stderr, _("%s: total space allocated by malloc: %lld bytes\n"),
> program_name, static_cast<long long>(m.arena));
>
What about making it more compact and not repeating the fprintf?
We have the following in the GCC compiler:
#ifdef HAVE_MALLINFO2
#define MALLINFO_FN mallinfo2
#else
#define MALLINFO_FN mallinfo
#endif
...
fprintf (stderr, " {heap " PRsa (0) "}", SIZE_AMOUNT (MALLINFO_FN ().arena));
Cheers,
Martin
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ld/gold: Use mallinfo2 over mallinfo if available
2021-03-19 7:55 ` Martin Liška
@ 2021-03-19 8:21 ` Khem Raj
0 siblings, 0 replies; 3+ messages in thread
From: Khem Raj @ 2021-03-19 8:21 UTC (permalink / raw)
To: Martin Liška; +Cc: Binutils
On Fri, Mar 19, 2021 at 12:55 AM Martin Liška <mliska@suse.cz> wrote:
>
> On 3/18/21 11:09 PM, Khem Raj via Binutils 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
>
> Hello.
>
> I support the change as the old mallinfo overflows at 2GB memory.
>
> ... snip...
> >
> > -#ifdef HAVE_MALLINFO
> > +#ifdef HAVE_MALLINFO2
> > + struct mallinfo2 m = mallinfo2();
> > + fprintf(stderr, _("%s: total space allocated by malloc: %lld bytes\n"),
> > + program_name, static_cast<long long>(m.arena));
> > +#elif defined(HAVE_MALLINFO)
> > struct mallinfo m = mallinfo();
> > fprintf(stderr, _("%s: total space allocated by malloc: %lld bytes\n"),
> > program_name, static_cast<long long>(m.arena));
> >
>
> What about making it more compact and not repeating the fprintf?
ok will send v2
> We have the following in the GCC compiler:
>
> #ifdef HAVE_MALLINFO2
> #define MALLINFO_FN mallinfo2
> #else
> #define MALLINFO_FN mallinfo
> #endif
> ...
> fprintf (stderr, " {heap " PRsa (0) "}", SIZE_AMOUNT (MALLINFO_FN ().arena));
>
> Cheers,
> Martin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-19 8:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 22:09 [PATCH] ld/gold: Use mallinfo2 over mallinfo if available Khem Raj
2021-03-19 7:55 ` Martin Liška
2021-03-19 8:21 ` Khem Raj
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).