Bug 31963 - Crash in _IO_link_in within __gcov_exit
Summary: Crash in _IO_link_in within __gcov_exit
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: stdio (show other bugs)
Version: 2.40
: P2 normal
Target Milestone: 2.40
Assignee: H.J. Lu
URL:
Keywords:
Depends on:
Blocks: 27777
  Show dependency treegraph
 
Reported: 2024-07-08 13:13 UTC by Andreas Schwab
Modified: 2024-07-09 08:15 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Schwab 2024-07-08 13:13:48 UTC
m4 crashes during exit when compiled with -fprofile-generate.  m4 closes all standard streams in an atexit handler (close_stdin from gnulib) which results in _IO_list_all == NULL.  The gcov destructor function then opens a file to write out the profiling data which crashes here:

122               _IO_list_all->file._prevchain = &fp->file._chain;
Comment 1 Andreas Schwab 2024-07-08 13:24:20 UTC
#include <stdio.h>

static void close_stdin (void)
{
  fclose (stdin);
  fclose (stdout);
  fclose (stderr);
}

static void final (void)
{
  FILE *f = fopen ("/dev/null", "w");
  fprintf (f, "final\n");
  fclose (f);
}

int main (void)
{
  close_stdin ();
  final ();
}
Comment 3 Andreas Schwab 2024-07-09 08:15:37 UTC
Fixed in commit 2213b37b70.