I am after some suggestions as to how to go about debugging a significant problem that I cannot reduce to a minimal example.
The problem: I compile my application which links to a number of different libraries. The flags include:
-static-libstdc++ -static-libgcc -pipe -std=c++1z -fno-PIC -flto=10 -m64 -O3 -flto=10 -fuse-linker-plugin -fuse-ld=gold -UNDEBUG -lrt -ldl
The compiler is gcc-7.3.0, compiled against binutils-2.30. Boost is compiled with the same flags as the rest of the program, and linked statically.
When the program is linked, I get various warnings about relocation refers to discarded section, both in my own code, and in boost. For instance:
/tmp/ccq2Ddku.ltrans13.ltrans.o:<artificial>:function boost::system::(anonymous namespace)::generic_error_category::message(int) const: warning: relocation refers to discarded section
Then when I run the program, it segfaults on destruction, with the backtrace:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff7345a49 in __run_exit_handlers () from /lib64/libc.so.6
#2 0x00007ffff7345a95 in exit () from /lib64/libc.so.6
#3 0x00007ffff732eb3c in __libc_start_main () from /lib64/libc.so.6
#4 0x000000000049b3e3 in _start ()
The function pointer attempting to be called is 0x0.
If I remove using static-libstdc++, the linker warnings and runtime segfault go away.
If I change from c++1z to c++14, the linker warnings and runtime segfault go away.
If I remove -flto, the linker warnings and runtime segfault go away.
If I add "-g" to the compile flags, the linker warnings and runtime segfault go away.
I have tried asking gold for extra debugging, by specifying -Wl,--debug=all, but it tells me seemingly nothing relevant.
If I try and use a small section of the code that appears relevant, compile and link it separately but to the same boost libraries (ie. attempting to produce minimal example), there are no linker warnings, and the program runs to completion without issues.
Help! What can I do to narrow the problem down?