using gcc version 14.0.0 20231028 (experimental) [master r14-4988-g5d2a360f0a5] (GCC) that contains the fix for #111936 This simple example [1] when run as a single executable prints all symbols in the stacktrace when the nested functions are in a shared library their names are missing c++ -std=c++23 testStacktrace.cpp -lstdc++exp -g -DINMAIN -DINLIB ; ./a.out 0# nested_func2(int) at /afs/cern.ch/user/i/innocent/public/ctest/testStacktrace.cpp:13 1# nested_func(int) at /afs/cern.ch/user/i/innocent/public/ctest/testStacktrace.cpp:18 2# func(int) at /afs/cern.ch/user/i/innocent/public/ctest/testStacktrace.cpp:26 3# main at /afs/cern.ch/user/i/innocent/public/ctest/testStacktrace.cpp:31 4# at :0 5# _start at :0 6# c++ -std=c++23 testStacktrace.cpp -lstdc++exp -g -DINLIB -fpic -shared -o liba.so ; c++ -std=c++23 testStacktrace.cpp -lstdc++exp -g -DINMAIN -L. -la -Wl,-rpath=. ; ./a.out 0# at :0 1# at :0 2# func(int) at /afs/cern.ch/user/i/innocent/public/ctest/testStacktrace.cpp:26 3# main at /afs/cern.ch/user/i/innocent/public/ctest/testStacktrace.cpp:31 4# at :0 5# _start at :0 6# [1] cat testStacktrace.cpp //compile and run with either // c++ -std=c++23 testStacktrace.cpp -lstdc++exp -g -DINMAIN -DINLIB; ./a.out // or // c++ -std=c++23 testStacktrace.cpp -lstdc++exp -g -DINLIB -fpic -shared -o liba.so;c++ -std=c++23 testStacktrace.cpp -lstdc++exp -g -DINMAIN -L. -la -Wl,-rpath=.; ./a.out // #include <iostream> #include <stacktrace> #ifdef INLIB int nested_func2(int c) { std::cout << std::stacktrace::current() << '\n'; return c + 1; } int nested_func(int c) { return nested_func2(c + 1); } #else int nested_func(int c); #endif #ifdef INMAIN int func(int b) { return nested_func(b + 1); } int main() { std::cout << func(777); return 0; } #endif
I'm not sure if this is a libstdc++ problem or should be component=libbacktrace
I suspect libbacktrace even if I do not have ways to test it outside std::stacktrace
What OS and processor? Is this x86 GNU/Linux?
intel x86_64 uname -a Linux patatrack01 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Thu May 18 10:27:05 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux boost::backtrace works can provide example
so if I add to std::cout << std::stacktrace::current() << '\n'; I get what needed Dl_info dlinfo; for (auto & entry : std::stacktrace::current() ) { dladdr((const void*)(entry.native_handle()),&dlinfo); std::cout << dlinfo.dli_sname << ' ' << dlinfo.dli_fname <<'\n'; } c++ -std=c++23 testStacktrace.cpp -lstdc++exp -g -DINLIB -fpic -shared -o liba.so -ldl ; c++ -std=c++23 testStacktrace.cpp -lstdc++exp -g -DINMAIN -L. -la -Wl,-rpath=. ; ./a.out 0# at :0 1# at :0 2# func(int) at /data/user/innocent/MallocProfiler/tests/testStacktrace.cpp:44 3# main at /data/user/innocent/MallocProfiler/tests/testStacktrace.cpp:49 4# at :0 5# _start at :0 6# _Z12nested_func2i ./liba.so _Z11nested_funci ./liba.so of course not de-mangled.... so is it a feature or a defect? I'm not sure how the implementation works (did not look to the code) dladdr can be slow and may "hang" in some situations. so it would be useful to have an option that the "name" is not immediately resolved and have a function that returns the name from the native_handle "asynchronously"
Sorry, made the (almost) full exercise: read the doc in https://en.cppreference.com/w/cpp/utility/stacktrace_entry and the code in stacktrace header file and in libstdc++-v3/src/c++23/stacktrace.cc (have not read the specs in the C++23 standard) indeed the entry implementation has just the handle as data member and the details are retrieved when the "Query" methods are called. This appears to happen in stacktrace_entry::_Info::_M_populate(native_handle_type pc) which in turn calls ::__glibcxx_backtrace_pcinfo if this fails it calls ::__glibcxx_backtrace_syminfo so most probably the issue is in this last function unless there is a problem with the logic in _M_populate that I failed to identify.
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/635073.html
Thanks Ian for the patch. For testing I will need the full git diff (including the makefile itself as my autoconf is not compatible with gcc14). Backports down to gcc12 will be appreciated. Could you please notify here when the patch enters the various main branches?
*** Bug 111315 has been marked as a duplicate of this bug. ***
I think we can mark this as confirmed since there is a patch submitted and the duplicated bug confirmed that patch fixes the issue.
vincenzo: the patch in the linked e-mail is the complete diff. There are no changes to generated Makefile.in files.
confirm that the patch solves the issue c++ -std=c++23 testStacktrace.cpp -lstdc++exp -g -DINLIB -fpic -shared -o liba.so -ldl;c++ -std=c++23 testStacktrace.cpp -lstdc++exp -g -DINMAIN -L. -la -Wl,-rpath=.; ./a.out 0# nested_func2(int) at /data/user/innocent/MallocProfiler/tests/testStacktrace.cpp:63 1# nested_func(int) at /data/user/innocent/MallocProfiler/tests/testStacktrace.cpp:93 2# func(int) at /data/user/innocent/MallocProfiler/tests/testStacktrace.cpp:101 3# main at /data/user/innocent/MallocProfiler/tests/testStacktrace.cpp:106 4# __libc_start_main at :0 5# _start at :0 6# what is the last empty entry is a different story I suppose (not an issue at the moment). Thanks again for the fast action
The master branch has been updated by Ian Lance Taylor <ian@gcc.gnu.org>: https://gcc.gnu.org/g:2b64e4a54042fb8f75f1c1429eb1c13afb9fa118 commit r14-5173-g2b64e4a54042fb8f75f1c1429eb1c13afb9fa118 Author: Ian Lance Taylor <iant@golang.org> Date: Mon Nov 6 15:09:18 2023 -0800 libstdc++: use -D_GNU_SOURCE when building libbacktrace PR libbacktrace/111315 PR libbacktrace/112263 * acinclude.m4: Set -D_GNU_SOURCE in BACKTRACE_CPPFLAGS and when grepping link.h for dl_iterate_phdr. * configure: Regenerate.
The releases/gcc-13 branch has been updated by Ian Lance Taylor <ian@gcc.gnu.org>: https://gcc.gnu.org/g:8484e3479fe80aebdc4a2406473aef906055b4f8 commit r13-8006-g8484e3479fe80aebdc4a2406473aef906055b4f8 Author: Ian Lance Taylor <iant@golang.org> Date: Mon Nov 6 15:12:05 2023 -0800 libstdc++: use -D_GNU_SOURCE when building libbacktrace PR libbacktrace/111315 PR libbacktrace/112263 * acinclude.m4: Set -D_GNU_SOURCE in BACKTRACE_CPPFLAGS and when grepping link.h for dl_iterate_phdr. * configure: Regenerate.
The releases/gcc-12 branch has been updated by Ian Lance Taylor <ian@gcc.gnu.org>: https://gcc.gnu.org/g:56909c9d4842925749cd9e061ef4afa0501f85e9 commit r12-9961-g56909c9d4842925749cd9e061ef4afa0501f85e9 Author: Ian Lance Taylor <iant@golang.org> Date: Mon Nov 6 15:12:41 2023 -0800 libstdc++: use -D_GNU_SOURCE when building libbacktrace PR libbacktrace/111315 PR libbacktrace/112263 * acinclude.m4: Set -D_GNU_SOURCE in BACKTRACE_CPPFLAGS and when grepping link.h for dl_iterate_phdr. * configure: Regenerate.
Fix committed.
Thanks, Ian!