https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103629
Bug ID: 103629 Summary: Possible miscompilation triggered by -fvisibility=hidden Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mathieu.malaterre at gmail dot com Target Milestone: --- Executive summary: --- ``` % LD_LIBRARY_PATH=./openvdb/openvdb ./openvdb/openvdb/cmd/vdb_view zsh: segmentation fault LD_LIBRARY_PATH=./openvdb/openvdb ./openvdb/openvdb/cmd/vdb_view ``` Actual bug description: --- Upon recompilation of openvdb-8.1.0 within a Debian/sid environment, the initialization logic starts to fails and eventually lead to a segfault. Inspection of the gdb backtrace does not pinpoint any obvious mistake: % LD_LIBRARY_PATH=./openvdb/openvdb gdb ./openvdb/openvdb/cmd/vdb_view GNU gdb (Debian 10.1-2) 10.1.90.20210103-git Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./openvdb/openvdb/cmd/vdb_view... (gdb) r --help Starting program: /home/malat/openvdb-8.1.0/obj-x86_64-linux-gnu/openvdb/openvdb/cmd/vdb_view --help [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7ffff6da0640 (LWP 31308)] [New Thread 0x7ffff659f640 (LWP 31309)] [New Thread 0x7ffff5d9e640 (LWP 31310)] [New Thread 0x7ffff559d640 (LWP 31311)] Thread 1 "vdb_view" received signal SIGSEGV, Segmentation fault. 0x00007ffff78d3228 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (gdb) bt full #0 0x00007ffff78d3228 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 No symbol table info available. #1 0x00007ffff7cac65a in openvdb::v8_1::Grid<openvdb::v8_1::tree::Tree<openvdb::v8_1::tree::RootNode<openvdb::v8_1::tree::InternalNode<openvdb::v8_1::tree::InternalNode<openvdb::v8_1::tree::LeafNode<bool, 3u>, 4u>, 5u> > > >::gridType[abi:cxx11]() () at /usr/include/c++/11/bits/unique_ptr.h:173 No locals. #2 openvdb::v8_1::Grid<openvdb::v8_1::tree::Tree<openvdb::v8_1::tree::RootNode<openvdb::v8_1::tree::InternalNode<openvdb::v8_1::tree::InternalNode<openvdb::v8_1::tree::LeafNode<bool, 3u>, 4u>, 5u> > > >::registerGrid () at ./openvdb/openvdb/Grid.h:981 No locals. #3 openvdb::v8_1::initialize () at ./openvdb/openvdb/openvdb.cc:94 lock = {_M_device = @0x7ffff7fca760} #4 0x0000555555574c40 in main (argc=<optimized out>, argv=0x7fffffffe4f8) at ./openvdb/openvdb/cmd/openvdb_view.cc:67 printInfo = <optimized out> viewer = {<No data fields>} allGrids = std::vector of length 1, capacity -2932030871777 = {std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1027951951, weak count 1836017710) = {get() = 0x7fffffffe720}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1831822701, weak count 1952541792) = {get() = 0x0}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1869361010, weak count 795631970) = {get() = 0x7fffffffe784}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1330792515, weak count 1314870350) = {get() = 0x7fffffffe7b4}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1027885383, weak count 808988978) = {get() = 0x7fffffffe7f1}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1397966163, weak count 1598967624) = {get() = 0x7fffffffe817}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1380275029, weak count 1818324284) = {get() = 0x7fffffffe875}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 841837938, weak count 1868772916) = {get() = 0x7fffffffe899}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1027888976, weak count 1836017710) = {get() = 0x7fffffffe8bc}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1701670760, weak count 1818324270) = {get() = 0x7fffffffe8cf}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1348426066, weak count 1028150336) = {get() = 0x7fffffffe938}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1280262912, weak count 1397640532) = {get() = 0x7fffffffef49}, std::shared_ptr<const openvdb::v8_1::GridBase> (empty) = { get() = 0x7fffffffefa0}, std::shared_ptr<const openvdb::v8_1::GridBase> (expired, weak count 0) = {get() = 0x21}, <error reading variable: Cannot access memory at address 0x78bfc07>, <error reading variable: Cannot access memory at address 0x1008>, <error reading variable: Cannot access memory at address 0x6c>, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 64, weak count -1) = {get() = 0x3}, <error reading variable: Cannot access memory at address 0x40>, <error reading variable: Cannot access memory at address 0x13>, std::shared_ptr<const openvdb::v8_1::GridBase> (expired, weak count 0) = {get() = 0x7}, std::shared_ptr<const openvdb::v8_1::GridBase> (empty) = {get() = 0x8}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count -461158174, weak count 1280594159) = {get() = 0x9}, <error reading variable: Cannot access memory at address 0xc74>, <error reading variable: Cannot access memory at address 0xc74>, <error reading variable: Cannot access memory at address 0xc74>, <error reading variable: Cannot access memory at address 0xc74>, std::shared_ptr<const openvdb::v8_1::GridBase> (empty) = {get() = 0x17}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1418260266, weak count 1475371345) = {get() = 0x19}, std::shared_ptr<const openvdb::v8_1::GridBase> (empty) = {get() = 0x1a}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 796156268, weak count 1852141678) = {get() = 0x1f}, std::shared_ptr<const openvdb::v8_1::GridBase> (use count 1701670760, weak count 1818324270) = {get() = 0xf}, std::shared_ptr<const openvdb::v8_1::GridBase> (empty) = {get() = 0x0}, <error reading variable: Cannot access memory at address 0xf061525488ef2ae4>, <error reading variable: Cannot access memory at address 0x616d2f656d6f6837>, [--trimmed--] <error reading variable: Cannot access memory at address 0x776569765f626c>, <error reading variable allGrids (Cannot access memory at address 0x7ffffffff000)> indent = "" printGLInfo = <optimized out> printVersionInfo = <optimized out> filenames = std::vector of length 4398042310015, capacity 134217727 = {<error reading variable filenames (Cannot access memory at address 0x1)> numFiles = <optimized out> progName = 0x7fffffffe763 "vdb_view" status = 0 (gdb) Steps: ``` debian-sid $ dget -u http://deb.debian.org/debian/pool/main/o/openvdb/openvdb_8.1.0-3.dsc debian-sid $ cd openvdb-8.1.0 debian-sid $ debuild ``` The above should fails the `help2man` steps which basically simply does: ``` $ cd obj-x86_64-linux-gnu $ LD_LIBRARY_PATH=./openvdb/openvdb ./openvdb/openvdb/cmd/vdb_view --help ``` 1. It should be noticed that the openvdb binaries uploaded in Debian bullseye (current stable) are working as expected. 2. It should also be noticed that removing of the flag `-fvisibility=hidden` makes the symptom go away. As discussed on the gcc-help mailing list, I've been working on reducing the bug to something useful, but failed to. `c-vise` does not seems to produce anything meaningful within two hours timelapse. I've been unable to provide the necessary time to do a brute-force approach (#ifdef-ing the code), so far. References: * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=997080 * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1001136 % gcc --version gcc (Debian 11.2.0-12) 11.2.0 % apt-cache policy libtbb2 libtbb2: Installed: 2020.3-1 Candidate: 2020.3-1 Version table: *** 2020.3-1 500 % /lib/x86_64-linux-gnu/libc.so.6 GNU C Library (Debian GLIBC 2.32-5) stable release version 2.32. Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiled by GNU CC version 10.3.1 20211117. libc ABIs: UNIQUE IFUNC ABSOLUTE For bug reporting instructions, please see: <http://www.debian.org/Bugs/>.