[PATCH] Use size_t for mallinfo fields.
Adhemerval Zanella
adhemerval.zanella@linaro.org
Wed Sep 2 13:34:09 GMT 2020
On 02/09/2020 10:19, Martin Liška wrote:
> On 9/1/20 7:26 PM, Joseph Myers wrote:
>> There are several key pieces missing from the mallinfo2 commit.
>>
>> * mallinfo2 is not added to GLIBC_2.33 in malloc/Versions. So it's not
>> exported from shared glibc, so it can't actually be used at all.
>>
>> * Once a function is exported from shared libc, all the ABI test baselines
>> need updating accordingly.
>>
>> * Any new function needs a testcase added to the testsuite. If there were
>> such a test, it would have shown up the first problem of the function not
>> being exported (that's why there should be tests even for e.g. syscall
>> wrappers for syscalls that don't do anything useful as non-root - simply
>> testing that it's possible to compile and link a call to each public
>> function is useful).
>>
>> * Any new function should be mentioned as a new feature in the NEWS file.
>>
>> * Any deprecation should be listed under "Deprecated and removed features,
>> and other changes affecting compatibility:" in the NEWS file.
>>
>
> Hello.
>
> Thank you for the hints Joseph. There's patch that survives regression tests.
>
> Martin> From 18528c416f23be7dafe4a9bf631c91b6cbb3e0cb Mon Sep 17 00:00:00 2001
> From: Martin Liska <mliska@suse.cz>
> Date: Wed, 2 Sep 2020 15:17:25 +0200
> Subject: [PATCH] mallinfo2: add missing bits
>
> The patch adds the function to Versions and both tests
> now test the function. The function is also mentioned in NEWS.
You still need to run 'make update-abi' for each supported architecture
and ABI variations to update each libc.abilist. And the missing symbol in
the libc.abilist should have raised a failure in the make check.
> ---
> NEWS | 5 ++++-
> malloc/Versions | 3 +++
> malloc/tst-malloc-tcache-leak.c | 17 +++++------------
> malloc/tst-mxfast.c | 12 ++----------
> 4 files changed, 14 insertions(+), 23 deletions(-)
>
> diff --git a/NEWS b/NEWS
> index 06e43e0453..b21e5244ab 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -20,9 +20,12 @@ Major new features:
> The 32-bit RISC-V port requires at least Linux 5.4, GCC 7.1 and binutils
> 2.28.
>
> +* A new function mallinfo2 (replaces mallinfo) uses size_t for values returned
> + in mallinfo2 struct.
> +
> Deprecated and removed features, and other changes affecting compatibility:
>
> - [Add deprecations, removals and changes affecting compatibility here]
> +* Function mallinfo is deprecated.
>
> Changes to build and runtime requirements:
>
> diff --git a/malloc/Versions b/malloc/Versions
> index 2357cff3da..94c8ba8040 100644
> --- a/malloc/Versions
> +++ b/malloc/Versions
> @@ -64,6 +64,9 @@ libc {
> GLIBC_2.26 {
> reallocarray;
> }
> + GLIBC_2.33 {
> + mallinfo2;
> + }
> GLIBC_PRIVATE {
> # Internal startup hook for libpthread.
> __libc_malloc_pthread_startup;
> diff --git a/malloc/tst-malloc-tcache-leak.c b/malloc/tst-malloc-tcache-leak.c
> index 2a7a0646c5..ae5e1fd252 100644
> --- a/malloc/tst-malloc-tcache-leak.c
> +++ b/malloc/tst-malloc-tcache-leak.c
> @@ -29,7 +29,6 @@
> #include <malloc.h>
> #include <pthread.h>
> #include <assert.h>
> -#include <libc-diag.h>
>
> #include <support/check.h>
> #include <support/support.h>
> @@ -61,7 +60,7 @@ static int
> do_test (void)
> {
> pthread_t *thread;
> - struct mallinfo info_before, info_after;
> + struct mallinfo2 info_before, info_after;
> void *retval;
>
> /* This is an arbitrary choice. We choose a total of THREADS
> @@ -73,15 +72,11 @@ do_test (void)
> pthread_t required to run the test. */
> thread = (pthread_t *) xcalloc (1, sizeof (pthread_t));
>
> - /* The test below covers the deprecated mallinfo function. */
> - DIAG_PUSH_NEEDS_COMMENT;
> - DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wdeprecated-declarations");
> -
> - info_before = mallinfo ();
> + info_before = mallinfo2 ();
>
> assert (info_before.uordblks != 0);
>
> - printf ("INFO: %d (bytes) are in use before starting threads.\n",
> + printf ("INFO: %ld (bytes) are in use before starting threads.\n",
> info_before.uordblks);
>
> for (int loop = 0; loop < threads; loop++)
I think should be '%zu' since uordblks is a size_t.
> @@ -91,8 +86,8 @@ do_test (void)
> free (retval);
> }
>
> - info_after = mallinfo ();
> - printf ("INFO: %d (bytes) are in use after all threads joined.\n",
> + info_after = mallinfo2 ();
> + printf ("INFO: %ld (bytes) are in use after all threads joined.\n",
> info_after.uordblks);
>
> /* We need to compare the memory in use before and the memory in use
Same as before.
> @@ -109,8 +104,6 @@ do_test (void)
> if (info_after.uordblks > (info_before.uordblks + threads))
> FAIL_EXIT1 ("Memory usage after threads is too high.\n");
>
> - DIAG_POP_NEEDS_COMMENT;
> -
> /* Did not detect excessive memory usage. */
> free (thread);
> exit (0);
> diff --git a/malloc/tst-mxfast.c b/malloc/tst-mxfast.c
> index 8afee0f9d5..0a41e1112c 100644
> --- a/malloc/tst-mxfast.c
> +++ b/malloc/tst-mxfast.c
> @@ -21,13 +21,12 @@
> the fast bins. */
>
> #include <malloc.h>
> -#include <libc-diag.h>
> #include <support/check.h>
>
> int
> do_test (void)
> {
> - struct mallinfo m;
> + struct mallinfo2 m;
> char *volatile p1;
> char *volatile p2;
>
> @@ -37,14 +36,7 @@ do_test (void)
> p2 = malloc (512);
> free (p1);
>
> - /* The test below covers the deprecated mallinfo function. */
> - DIAG_PUSH_NEEDS_COMMENT;
> - DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wdeprecated-declarations");
> -
> - m = mallinfo ();
> -
> - DIAG_POP_NEEDS_COMMENT;
> -
> + m = mallinfo2 ();
> /* This will fail if there are any blocks in the fastbins. */
> TEST_COMPARE (m.smblks, 0);
>
> --
> 2.28.0
More information about the Libc-alpha
mailing list