https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96913
Bug ID: 96913 Summary: gcc-11: __gcov_merge_topn hangs Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: gcov-profile Assignee: unassigned at gcc dot gnu.org Reporter: slyfox at gcc dot gnu.org CC: hubicka at gcc dot gnu.org, marxin at gcc dot gnu.org, mliska at suse dot cz Target Milestone: --- The hang happens on real tauthon-2.8.2 interpreter from PR96394 (no nice reproducer yet). In this instance I tried to build tauthon-2.8.2 against gcc-master. It hangs early when tries to merge topn entry: """ #0 0x00007fd73865e0ce in __GI___libc_read (fd=3, buf=0x406284 <__gcov_var+36>, nbytes=4096) at ../sysdeps/unix/sysv/linux/read.c:26 #1 0x00007fd7385f0090 in __GI__IO_file_xsgetn (fp=0x1295bc0, data=<optimized out>, n=4096) at libioP.h:948 #2 0x00007fd7385e4d1f in __GI__IO_fread (buf=0x406284 <__gcov_var+36>, size=1, count=4096, fp=0x1295bc0) at iofread.c:38 #3 0x00007fd72ab4237e in gcov_read_words (words=2) at ../../../gcc/libgcc/../gcc/gcov-io.c:491 #4 0x00007fd72ab42483 in __gcov_read_counter () at ../../../gcc/libgcc/../gcc/gcov-io.c:528 #5 0x00007fd72ab4190e in gcov_get_counter_target () at ../../../gcc/libgcc/libgcov.h:383 #6 0x00007fd72ab41c6b in __gcov_merge_topn (counters=0x7fd72ab4d320 <__gcov4.encoder_clear>, n_counters=24) at ../../../gcc/libgcc/libgcov-merge.c:114 #7 0x00007fd72ab43569 in merge_one_data ( filename=0x1154290 "/tmp/portage/dev-lang/tauthon-2.8.2/work/x86_64-pc-linux-gnu/build/temp.linux-x86_64-2.8/tmp/portage/dev-lang/tauthon-2.8.2/work/tauthon-2.8.2/Modules/_json.gcda", gi_ptr=0x7fd72ab4a180, summary=0x7ffde7d6e9c0) at ../../../gcc/libgcc/libgcov-driver.c:314 #8 0x00007fd72ab43b1a in dump_one_gcov (gi_ptr=0x7fd72ab4a180, gf=0x7ffde7d6ea00, run_counted=0, run_max=125) at ../../../gcc/libgcc/libgcov-driver.c:492 #9 0x00007fd72ab43cba in gcov_do_dump (list=0x7fd72ab4a180, run_counted=0) at ../../../gcc/libgcc/libgcov-driver.c:555 #10 0x00007fd72ab43d28 in __gcov_dump_one (root=0x7fd72ab4e5c0 <__gcov_root>) at ../../../gcc/libgcc/libgcov-driver.c:578 #11 0x00007fd72ab43d5d in __gcov_exit () at ../../../gcc/libgcc/libgcov-driver.c:600 #12 0x00007fd738c460a3 in _dl_fini () at dl-fini.c:139 #13 0x00007fd7385af564 in __run_exit_handlers (status=0, listp=0x7fd73872a738 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:108 #14 0x00007fd7385af70a in __GI_exit (status=<optimized out>) at exit.c:139 #15 0x00007fd73899534e in Py_Exit () from /tmp/portage/dev-lang/tauthon-2.8.2/work/x86_64-pc-linux-gnu/libtauthon2.8.so.1.0 #16 0x00007fd738995533 in handle_system_exit () from /tmp/portage/dev-lang/tauthon-2.8.2/work/x86_64-pc-linux-gnu/libtauthon2.8.so.1.0 #17 0x00007fd73899588e in PyErr_PrintEx () from /tmp/portage/dev-lang/tauthon-2.8.2/work/x86_64-pc-linux-gnu/libtauthon2.8.so.1.0 #18 0x00007fd738995e44 in PyErr_Print () from /tmp/portage/dev-lang/tauthon-2.8.2/work/x86_64-pc-linux-gnu/libtauthon2.8.so.1.0 #19 0x00007fd7389b851e in RunModule () from /tmp/portage/dev-lang/tauthon-2.8.2/work/x86_64-pc-linux-gnu/libtauthon2.8.so.1.0 #20 0x00007fd7389b9075 in Py_Main () from /tmp/portage/dev-lang/tauthon-2.8.2/work/x86_64-pc-linux-gnu/libtauthon2.8.so.1.0 #21 0x00000000004012ac in main () """ Looks like the problem is in decoding of some tag in __gcov_merge_topn(). There count of entries is huge: """ (gdb) frame 6 #6 0x00007fd72ab41c6b in __gcov_merge_topn (counters=0x7fd72ab4d320 <__gcov4.encoder_clear>, n_counters=24) at ../../../gcc/libgcc/libgcov-merge.c:114 114 gcov_type value = gcov_get_counter_target (); (gdb) list __gcov_merge_topn 96 -- counter 97 */ 98 99 void 100 __gcov_merge_topn (gcov_type *counters, unsigned n_counters) 101 { 102 gcc_assert (!(n_counters % GCOV_TOPN_MEM_COUNTERS)); 103 104 for (unsigned i = 0; i < (n_counters / GCOV_TOPN_MEM_COUNTERS); i++) 105 { (gdb) 106 /* First value is number of total executions of the profiler. */ 107 gcov_type all = gcov_get_counter_ignore_scaling (-1); 108 gcov_type n = gcov_get_counter_ignore_scaling (-1); 109 110 counters[GCOV_TOPN_MEM_COUNTERS * i] += all; 111 112 for (unsigned j = 0; j < n; j++) 113 { 114 gcov_type value = gcov_get_counter_target (); 115 gcov_type count = gcov_get_counter_ignore_scaling (-1); (gdb) 116 117 // TODO: we should use atomic here 118 gcov_topn_add_value (counters + GCOV_TOPN_MEM_COUNTERS * i, value, 119 count, 0, 0); 120 } 121 } 122 } 123 #endif /* L_gcov_merge_topn */ 124 125 #endif /* inhibit_libc */ (gdb) print n $1 = 140325305737200 (gdb) print j $2 = 1896248771 """ Compiler: """ $ ${HOME}/dev/git/gcc-native-quick-ggdb3/gcc/xgcc -B${HOME}/dev/git/gcc-native-quick-ggdb3/gcc -v Reading specs from /home/slyfox/dev/git/gcc-native-quick-ggdb3/gcc/specs COLLECT_GCC=/home/slyfox/dev/git/gcc-native-quick-ggdb3/gcc/xgcc COLLECT_LTO_WRAPPER=/home/slyfox/dev/git/gcc-native-quick-ggdb3/gcc/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc/configure --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu --enable-languages=c,c++ --disable-bootstrap --with-multilib-list=m64 --prefix=/home/slyfox/dev/git/gcc-native-quick-ggdb3/../gcc-native-quick-installed-ggdb3 --disable-nls --without-isl --disable-libsanitizer --disable-libvtv --disable-libgomp --disable-libstdcxx-pch --disable-libunwind-exceptions CFLAGS='-O0 -ggdb3 ' CXXFLAGS='-O0 -ggdb3 ' --enable-valgrind-annotations Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.0.0 20200902 (experimental) (GCC) """ gcc-10 seems to be able to merge profiles.