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

Martin Liška mliska@suse.cz
Fri Mar 19 07:55:18 GMT 2021


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


More information about the Binutils mailing list