https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120508
Bug ID: 120508 Summary: Undefined symbols and relocation truncated to fit IMAGE_REL_AMD64_ADDR32NB with large translation unit making heavy use of templates with -O0 Product: gcc Version: 15.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: krizdjali at gmail dot com Target Milestone: --- Created attachment 61561 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61561&action=edit Compressed preprocessed repro When compiling the attached preprocessed C++ file with the GCC build provided by MSYS2's UCRT64 environment with g++ -g -O0, an object file is produced that will cause linker errors. Inspecting the symbols with nm -Cg shows many templated functions as U, whereas: * when using -O1 or -Og they're not listed at all (at least for the ones I've checked). * when using GCC on Ubuntu, they're listed as W. * when using Clang, they're listed as T. * when using MSVC, they're listed as T. * when commenting out the last 54 add<vsg::Whatever>() calls in ObjectFactory::ObjectFactory, they're listed as T. Attempting to consume the object file when linking emits many (around two thousand) undefined symbol errors, and ten relocation truncated to fit: IMAGE_REL_AMD64_ADDR32NB against ... messages (as well as a message saying additional relocation overflows omitted from the output). The attached file is large, but doing anything to make it smaller makes the errors go away. The size appears to be a necessary condition to trigger the problem. I compressed the file to fit the 1000 KB size limit the bug report form warns about. This might be a binutils bug rather than a GCC bug, but I don't know how to prove that one way or the other. The full version information is: $ g++ -v Using built-in specs. COLLECT_GCC=C:\tools\msys64\ucrt64\bin\g++.exe COLLECT_LTO_WRAPPER=C:/tools/msys64/ucrt64/bin/../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++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-backtrace=yes --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --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='Rev5, 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: posix Supported LTO compression algorithms: zlib zstd gcc version 15.1.0 (Rev5, Built by MSYS2 project)