https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122460
Bug ID: 122460
Summary: Linking is broken when linking with MinGW crt object
files compiled with LTO enabled and either codeview
debugging information or -ffunction-sections
-fdata-sections -Wl,--gc-sections are also on
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: tanksherman27 at gmail dot com
Target Milestone: ---
Created attachment 62652
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62652&action=edit
Preprocessed source for reproducer
The g++ in question gives the following output for -v:
vertig0@LAPTOP-K7UH3HRE UCRT64 /c/Users/vertig0/Downloads/gcc
# g++ -v
Using built-in specs.
COLLECT_GCC=C:\msys64\ucrt64\bin\g++.exe
COLLECT_LTO_WRAPPER=C:/msys64/ucrt64/lib/gcc/x86_64-w64-mingw32/15.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-15.1.0/configure --prefix=/ucrt64
--with-local-prefix=/ucrt64/local
--with-native-system-header-dir=/ucrt64/include --libexecdir=/ucrt64/lib
--enable-bootstrap --enable-checking=release --with-arch=nocona
--with-tune=generic --enable-mingw-wildcard --enable-languages=c,lto,c++
--enable-shared --enable-static --enable-libatomic --enable-threads=win32
--enable-graphite --enable-fully-dynamic-string
--enable-libstdcxx-backtrace=yes --enable-libstdcxx-threads
--enable-libstdcxx-filesystem-ts --enable-libstdcxx-time
--disable-libstdcxx-pch --enable-lto --disable-libgomp --enable-tls
--disable-libssp --disable-multilib --disable-rpath --disable-win32-registry
--disable-nls --disable-werror --disable-symvers --with-libiconv
--with-system-zlib --with-gmp=/ucrt64 --with-mpfr=/ucrt64 --with-mpc=/ucrt64
--with-isl=/ucrt64 --with-pkgversion='Rev6, Built by MSYS2 project'
--with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as
--with-gnu-ld --disable-libstdcxx-debug --enable-plugin
--with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: win32
Supported LTO compression algorithms: zlib zstd
gcc version 15.1.0 (Rev6, Built by MSYS2 project)
For the given simple program:
#include <iostream>
int main() {
std::cout << "C++" << std::endl;
}
g++ fails to link it with assembler errors resulting if the MinGW crt the
program is being linked with was compiled with LTO enabled, that is to say, the
crt has LTO IR within its object files, and either -g -gcodeview or
-ffunction-sections -fdata-sections -Wl,--gc-sections are enabled (The failure
to link also happens if both -g -gcodeview -ffunction-sections -fdata-sections
-Wl,--gc-sections are specified together on the command line, though again only
when the crt was compiled with LTO enabled). Without the codeview workaround
patch from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120051 applied, I get
an ICE and nothing else useful to report in the -g -gcodeview cases, but with
that patch applied assembler errors result, as mentioned above. The command
lines and corresponding errors can be found in the attachment above.
Preprocessed source is attached above, let me know if anything else is needed.