public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/113401] New: Memory (resource) leak in -ftrampoline-impl=heap
@ 2024-01-15 16:35 fw at gcc dot gnu.org
  2024-01-15 16:50 ` [Bug libgcc/113401] " iains at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: fw at gcc dot gnu.org @ 2024-01-15 16:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113401

            Bug ID: 113401
           Summary: Memory (resource) leak in -ftrampoline-impl=heap
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fw at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64-*, aarch64-*

Consider this test program:

#include <err.h>
#include <errno.h>
#include <pthread.h>

static void *volatile compiler_barrier;

void *
thread_routine (void *ignore)
{
  int local_variable;
  auto int *local_function (void)
  {
    return &local_variable;
  }
  compiler_barrier = local_function;
  return NULL;
}

int
main (void)
{
  for (int i = 0; i < 10000; ++i)
    {
      pthread_t thread;
      int ret = pthread_create (&thread, NULL, thread_routine, NULL);
      if (ret != 0)
        {
          errno = ret;
          err (1, "pthread_create");
        }
      ret = pthread_join (thread, NULL);
      if (ret != 0)
        {
          errno = ret;
          err (1, "pthread_join");
        }
    }
}

With -ftrampoline-impl=stack, I get:

$ \time ./a.out 
0.01user 0.16system 0:00.18elapsed 102%CPU (0avgtext+0avgdata 3008maxresident)k
0inputs+0outputs (0major+68minor)pagefaults 0swaps

With -ftrampoline-impl=heap:

$ \time ./a.out 
0.03user 0.17system 0:00.20elapsed 101%CPU (0avgtext+0avgdata
41796maxresident)k
0inputs+0outputs (0major+10148minor)pagefaults 0swaps

The reason for the maxresident change is that __builtin_nested_func_ptr_created
and __builtin_nested_func_ptr_deleted cache the last trampoline page even if it
is completely unused. This is required for performance reasons. The fix is to
register a TLS destructor to deallocate that page, too. On glibc, that also
fixes another memory leak for -fno-exceptions compilations (the default for C)
if pthread_exit is called with an active trampoline.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-01-22 10:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-15 16:35 [Bug target/113401] New: Memory (resource) leak in -ftrampoline-impl=heap fw at gcc dot gnu.org
2024-01-15 16:50 ` [Bug libgcc/113401] " iains at gcc dot gnu.org
2024-01-15 16:54 ` fw at gcc dot gnu.org
2024-01-21 23:42 ` iains at gcc dot gnu.org
2024-01-22  9:57 ` fw at gcc dot gnu.org
2024-01-22 10:11 ` iains at gcc dot gnu.org
2024-01-22 10:21 ` fw at gcc dot gnu.org
2024-01-22 10:27 ` iains at gcc dot gnu.org
2024-01-22 10:31 ` fw at gcc dot gnu.org
2024-01-22 10:46 ` iains at gcc dot gnu.org

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).