Hello Josef, I try to fix a problem with SMP support with golang relate to nested mutex call. As I mention couple month ago here https://lists.genode.org/pipermail/users/2020-October/007269.html
I still have a problem with nested jmp_slot() related to call to strlen() during stack unwind call and related nested mutex leading to deadlock. Seems that strlen() was instantiated as a call to shared libc from libgcc compiled and linked to main test-go. This is a part of compiled
What I found is the following
#0 strlen (str=str@entry=0x127d029 "zR") at /var/services/homes/admin/gen/21.02/contrib/libc-3ec28a350593879749a015a584ed24ffd7d3edce/src/lib/libc/lib/libc/string/strlen.c:100 #1 0x00000000011a8ca5 in get_cie_encoding (cie=0x127d020) at /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:300 #2 0x00000000011a93a3 in get_fde_encoding (f=0x12a8e8c) at /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.h:157 #3 _Unwind_IteratePhdrCallback (info=<optimized out>, size=<optimized out>, ptr=0x405fe190) at /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde-dip.c:418 #4 0x00000000000eba9e in dl_iterate_phdr (callback=callback@entry=0x11a8f60 <_Unwind_IteratePhdrCallback>, data=data@entry=0x405fe190) at /var/services/homes/admin/gen/21.02/repos/base/src/lib/ldso/exception.cc:53 #5 0x00000000011aa1cf in _Unwind_Find_FDE (pc=0x11a8797 <_Unwind_Backtrace+55>, bases=bases@entry=0x405fe4c8) at /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde-dip.c:469 #6 0x00000000011a6783 in uw_frame_state_for (context=context@entry=0x405fe420, fs=fs@entry=0x405fe270) at /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2.c:1257 #7 0x00000000011a77a0 in uw_init_context_1 (context=context@entry=0x405fe420, outer_cfa=outer_cfa@entry=0x405fe6d0, outer_ra=0x119ad62 <backtrace_full+180>) at /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2.c:1586 #8 0x00000000011a8798 in _Unwind_Backtrace (trace=0x119abbc <unwind>, trace_argument=0x405fe700) at /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind.inc:295 #9 0x000000000119ad62 in backtrace_full (state=0x29000, skip=0x0, callback=0x119804e <callback>, error_callback=0x1198503 <error_callback>, data=0x405fe770) at /var/services/homes/admin/gen/21.02/contrib/libbacktrace-cabcd83bc903137f607eda3a65eb09feaa5f507e/src/lib/gcc/libbacktrace/backtrace.c:127 #9 0x000000000119ad62 in backtrace_full (state=0x29000, skip=0x0, callback=0x119804e <callback>, error_callback=0x1198503 <error_callback>, data=0x405fe770) at /var/services/homes/admin/gen/21.02/contrib/libbacktrace-cabcd83bc903137f607eda3a65eb09feaa5f507e/src/lib/gcc/libbacktrace/backtrace.c:127 #10 0x00000000011985d1 in runtime_callers (skip=0x2, locbuf=0xc42000e8d8, m=0x20, keep_thunks=0x0) at /var/services/homes/admin/gen/21.02/contrib/libgo-281260d9bdc27fefb62c00310025c54e1e629a2e/src/lib/gcc/libgo/runtime/go-callers.c:207
this is compiled inside toolchain, disassembly from here: /usr/local/genode/tool/19.05/lib/gcc/x86_64-pc-elf/8.3.0/64/libgcc_eh.a
0000000000000460 <get_cie_encoding>: get_cie_encoding(): /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:293 460: 55 push %rbp 461: 48 89 fd mov %rdi,%rbp 464: 53 push %rbx /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:299 465: 48 8d 5f 09 lea 0x9(%rdi),%rbx /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:300 469: 48 89 df mov %rbx,%rdi /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:293 46c: 48 83 ec 18 sub $0x18,%rsp /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:300 470: e8 00 00 00 00 callq 475 <get_cie_encoding+0x15>
call above inside test-go linked to strlen() to inside libc, as you see from stack above and from disassemble test-go, where it call shared libc instance: 00000000011a8c90 <get_cie_encoding>: get_cie_encoding(): /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:293 11a8c90: 55 push %rbp 11a8c91: 48 89 fd mov %rdi,%rbp 11a8c94: 53 push %rbx /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:299 11a8c95: 48 8d 5f 09 lea 0x9(%rdi),%rbx /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:300 11a8c99: 48 89 df mov %rbx,%rdi /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:293 11a8c9c: 48 83 ec 18 sub $0x18,%rsp /genodelabs-genode-2491eee/contrib/gcc-3cade18cf9defeefa714aa91de3b157fbad4aa18/src/noux-pkg/gcc/libgcc/unwind-dw2-fde.c:300 11a8ca0: e8 db 6b 00 00 callq 11af880 strlen@plt
inside callstack you can see a call to dl_iterate_phdr which contain in the very beginning extern "C" int dl_iterate_phdr(int (*callback) (Phdr_info *info, size_t size, void *data), void *data) { int err = 0; Phdr_info info;
Mutex::Guard guard(mutex());
so, we take same mutex twice here and in attempt to search for strlen() from @plt via jmp_slot… This happens only with SMP, if I use UP configuration it is not happens.
Frankly, I am stuck a bit… this lib is a part of general toolchain, not clear why this stack unwind staff call shared libc… may be it is necessary to recompile toolchain and library and force strlen() to be expanded to inlined one?
Sincerely, Alexander