[3.14] gh-137185: Fix _Py_DumpStack() async signal safety (gh-137187) (gh-137206)

Call backtrace() once when installing the signal handler to ensure that
libgcc is dynamically loaded outside the signal handler.

This fixes a "signal-unsafe call inside of a signal" TSan error from
test_faulthandler.test_enable_fd.
(cherry picked from commit 11a8652e25)

Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-10-07 20:11:46 +02:00 committed by GitHub
parent 93ac6f3472
commit 75de39ba1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 0 deletions

View file

@ -1327,3 +1327,13 @@ _Py_DumpStack(int fd)
PUTS(fd, " <cannot get C stack on this system>\n");
}
#endif
void
_Py_InitDumpStack(void)
{
#ifdef CAN_C_BACKTRACE
// gh-137185: Call backtrace() once to force libgcc to be loaded early.
void *callstack[1];
(void)backtrace(callstack, 1);
#endif
}