When compiling "make profile-opt", the instrumented python executable segfaults upon exit, even though it appears to run fine. This breaks the build process, because make evaluates the segfault as if the respective compilation step failed. GDB yields the following backtrace for the crash: #0 gcov_exit () at ../../../libgcc/libgcov.c:397 #1 0x00007ffff69b875f in __cxa_finalize (d=0x7ffff7c38a60) at cxa_finalize.c:56 #2 0x00007ffff771b983 in __do_global_dtors_aux () from ./libpython3.4m.so.1.0 #3 0x00007fffffffdd60 in ?? () #4 0x00007ffff7debe6a in _dl_fini () at dl-fini.c:252 Backtrace stopped: frame did not save the PC This problem first appears with changeset 6e2089dbc5ad [1] that introduced tracemalloc. It is still reproducible on today's tip. AFAICT, the mere presence of tracemalloc in the compiled executable causes this crash; I tried commenting out _PyTraceMalloc_Init from pythonrun.c and it did not help. To reproduce: ./configure --enable-shared make profile-opt i'm on x86_64 SUSE Linux, gcc version is 4.8.1 [1] hg.python.org/cpython/rev/6e2089dbc5ad
> This problem first appears with changeset 6e2089dbc5ad [1] that introduced tracemalloc. It is still reproducible on today's tip. It looks like the bug doesn't come from the code of tracemalloc. I removed all functions, Python does still crash. No. The problem just comes from the line "#pragma pack(4)" of: #pragma pack(4) typedef struct { PyObject *filename; int lineno; } frame_t;
Oops, the original code is: --- /* Pack the frame_t structure to reduce the memory footprint on 64-bit architectures: 12 bytes instead of 16. This optimization might produce SIGBUS on architectures not supporting unaligned memory accesses (64-bit IPS CPU?): on such architecture, the structure must not be packed. */ #pragma pack(4) typedef struct #ifdef __GNUC__ __attribute__((packed)) #endif { PyObject *filename; int lineno; } frame_t; --- "#pragma pack(4)" is for Microsoft Visual Studio. For GCC, there is already the "__attribute__((packed))" line. See attached workaround tracemalloc_gcov.patch. But I would interested to understand why it does crash. It might be a GCC or gcov bug.