https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128338

            Bug ID: 128338
           Summary: [modules] Duplicate symbols of libstdc++ internals
                    when exporting a templated function
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jan.buenker at online dot de
  Target Milestone: ---

Created attachment 66056
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66056&action=edit
Zip containing the 3 .ii files

I've encountered an issue with a module exporting a templated function. Linking
fails with duplicate internal libstdc++ symbols, namely:

internal.o:internal.cpp:(.rdata$_ZZNSt8__format28__write_escaped_unicode_partIcNS_10_Sink_iterIcEEEET0_S3_RSt17basic_string_viewIT_St11char_traitsIS5_EERbNS_10_Term_charEE13__replace_rep[_ZZNSt8__format28__write_escaped_unicode_partIcNS_10_Sink_iterIcEEEET0_S3_RSt17basic_string_viewIT_St11char_traitsIS5_EERbNS_10_Term_charEE13__replace_rep]+0x0):
multiple definition of `std::__format::__write_escaped_unicode_part<char,
std::__format::_Sink_iter<char> >(std::__format::_Sink_iter<char>,
std::basic_string_view<char, std::char_traits<char> >&, bool&,
std::__format::_Term_char)::__replace_rep'; main.o:main.cpp:(.rdata+0x1390):
first defined here
collect2.exe: error: ld returned 1 exit status


I would expect the program to link successfully.

Exposing the templated function in a regular header instead of a module fixes
it, so this issue seems module specific. Note that the issue is not specific to
this concrete symbol, I'm just using `<format>` in the reproducer. I've
previously seen the same issue with internal symbols in other std headers like
`<variant>`.

Potentially related:
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114229 (fixed with GCC 14, so
not a dupe)
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99000 (fixed with GCC 17, which
I can't test yet - might this fix my issue?)

I'm attaching three *.ii files that must be compiled and linked to produce the
issue:
g++.exe -c -o foolib.o -std=c++23 -fmodules foolib.ii
g++.exe -c -o internal.o -std=c++23 -fmodules internal.ii
g++.exe -c -o main.o -std=c++23 -fmodules main.ii
g++.exe main.o internal.o foolib.o

Note: the duplicated symbols do not occur if we run this command before those
above:
g++.exe -std=c++23 -fmodules --compile-std-module -c

Even without changing `#include <format>` to `import std;`, just the std module
being present seems to change something.

Output of `gcc -v`:

Using built-in specs.
COLLECT_GCC=C:\dev\Tools\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/dev/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/16.2.1/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc/configure --prefix=/mingw64 --with-sysroot=/mingw64
--with-build-sysroot=C:/MSYS64/mingw64 --with-local-prefix=/local
--with-native-system-header-dir=/include --libexecdir=/mingw64/lib
--enable-bootstrap --enable-checking=release --with-arch=x86-64-v2
--with-tune=rocketlake --enable-mingw-wildcard
--enable-languages=c,c++,fortran,lto,objc,obj-c++,jit --enable-shared
--enable-static --enable-libatomic --enable-threads=mcf --enable-tls
--enable-graphite --enable-fully-dynamic-string
--enable-libstdcxx-backtrace=yes --enable-libstdcxx-filesystem-ts
--enable-libstdcxx-time --disable-libstdcxx-pch --enable-libgomp
--disable-libssp --disable-multilib --disable-rpath --disable-win32-registry
--disable-nls --disable-werror --disable-symvers --with-libiconv
--with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64
--with-isl=/mingw64 --with-pkgversion='GCC with the MCF thread model, built by
LH_Mouse' --with-bugurl=https://github.com/lhmouse/MINGW-packages/issues
--with-gnu-as --with-gnu-ld --with-libstdcxx-zoneinfo=yes --enable-__cxa_atexit
--disable-libstdcxx-debug --enable-lto --enable-plugin
--with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: mcf
Supported LTO compression algorithms: zlib zstd
gcc version 16.2.1 20261008 (GCC with the MCF thread model, built by LH_Mouse)

Reply via email to