1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

libc: Extend __libc_freeres framework (Bug 23329).

The __libc_freeres framework does not extend to non-libc.so objects.
This causes problems in general for valgrind and mtrace detecting
unfreed objects in both libdl.so and libpthread.so.  This change is
a pre-requisite to properly moving the malloc hooks out of malloc
since such a move now requires precise accounting of all allocated
data before destructors are run.

This commit adds a proper hook in libc.so.6 for both libdl.so and
for libpthread.so, this ensures that shm-directory.c which uses
freeit () to free memory is called properly.  We also remove the
nptl_freeres hook and fall back to using weak-ref-and-check idiom
for a loaded libpthread.so, thus making this process similar for
all DSOs.

Lastly we follow best practice and use explicit free calls for
both libdl.so and libpthread.so instead of the generic hook process
which has undefined order.

Tested on x86_64 with no regressions.

Signed-off-by: DJ Delorie <dj@redhat.com>
Signed-off-by: Carlos O'Donell <carlos@redhat.com>
This commit is contained in:
Carlos O'Donell
2018-06-22 09:28:47 -04:00
parent 37d3d244e1
commit 2827ab990a
26 changed files with 245 additions and 53 deletions

View File

@ -251,8 +251,8 @@ get_cached_stack (size_t *sizep, void **memp)
/* Free stacks until cache size is lower than LIMIT. */
void
__free_stacks (size_t limit)
static void
free_stacks (size_t limit)
{
/* We reduce the size of the cache. Remove the last entries until
the size is below the limit. */
@ -288,6 +288,12 @@ __free_stacks (size_t limit)
}
}
/* Free all the stacks on cleanup. */
void
__nptl_stacks_freeres (void)
{
free_stacks (0);
}
/* Add a stack frame which is not used anymore to the stack. Must be
called with the cache lock held. */
@ -302,7 +308,7 @@ queue_stack (struct pthread *stack)
stack_cache_actsize += stack->stackblock_size;
if (__glibc_unlikely (stack_cache_actsize > stack_cache_maxsize))
__free_stacks (stack_cache_maxsize);
free_stacks (stack_cache_maxsize);
}