I’m trying to cross-compile, on Fedora 34, a simple C/C++ program.
I managed to cross-compile a C program without issues, after installing the required packages. Now, for a simple C++ program, running x86_64-w64-mingw32-g++ on a .o file results in:
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
It seems I might be missing a package. However, it’s hard to find out which one: I have no debug symbols, so gdb cannot provide a stack or backtrace. I tried installing several debuginfo packages, but after doing so, when running gdb on the x86_64-w64-mingw32-g++ process, I get:
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.33-20.fc34.x86_64
However, running that command does not work:
Could not find debuginfo package for the following installed packages:
Could not find debugsource package for the following installed packages:
Now I’m stuck. What can I do to try and fix the segmentation fault?
Ok, so, the idea is that, if my package is not up-to-date, there is a possibility that a debuginfo package simply does not exist for it? I thought every package had one, but maybe they are erased after some time?
The program I was trying to compile was astyle (Artistic Style).
Now, after upgrading my system and the glibc package, I indeed got the debuginfo package. But in the end, it does not help: the process that segfaults is not the main one (it is collect2), so my run with gdb results in the same thing (despite the message about installing debuginfo, the symbols were not useful for me).
I found somewhere that -v -da -Q, given to GCC, outputs things such as the exact command line used; so I used it, and got the exact command line, and after some debugging, I understood the actual cause: when cross-compiling, the make clean step had failed to remove all .os, so the cross-compiler tried to mix ELF object files with Portable Executable ones, and that seemed to trigger the crash. So I unintentionally fuzzed the cross-compiler with some unexpected format that it didn’t like. Cleaning everything and redoing it seems to work.
So, the main takeaways for me are:
cross-compilers are not completely robust in face of exotic input;
debuginfo packages are not always available for every single version of every Fedora package, and updating before installing them might help.