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

            Bug ID: 112820
           Summary: vtable not emitted correctly from module when
                    compiling with -g
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: michael.kenzel at gmail dot com
  Target Milestone: ---

When compiling a class with virtual member functions declared in a module
interface unit and defined in a module implementation unit with -g, the vtable
seems to not get emitted correctly, resulting in linker errors.

example:

        // io.ixx
        export module io;

        export struct error
        {
                virtual const char* what() const noexcept;
        };

        // io-impl.cpp
        module io;

        const char* error::what() const noexcept
        {
                return "bla";
        }

        // main.cpp
        import io;

        int main()
        {
                error{};
        }

compile with
        g++ -std=c++23 -fmodules-ts -g -c -x c++ io.ixx
        g++ -std=c++23 -fmodules-ts -g -c -x c++ io-impl.cpp
        g++ -std=c++23 -fmodules-ts -g -c -x c++ main.cpp
        g++ main.o io.o io-impl.o

produces
        main.o: in function `error@io::error()':
        main.cpp:3:(.text._ZNW2io5errorC2Ev[_ZNW2io5errorC5Ev]+0x8): undefined
reference to `vtable for error@io'
        main.cpp:3:(.text._ZNW2io5errorC2Ev[_ZNW2io5errorC5Ev]+0xc): undefined
reference to `vtable for error@io'

Removing the -g from the first two commands resolves the problem, so this seems
to be tied to debugging information somehow. While the vtable will only be
emitted into io-impl.o, interestingly, it is apparently necessary to remove -g
from both the io-impo.o and the io.o commands for the vtable to be emitted.

Reply via email to