public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "michael.kenzel at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/112820] New: vtable not emitted correctly from module when compiling with -g
Date: Sat, 02 Dec 2023 01:38:49 +0000	[thread overview]
Message-ID: <bug-112820-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2023-12-02  1:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-02  1:38 michael.kenzel at gmail dot com [this message]
2023-12-02 12:31 ` [Bug c++/112820] " nathanieloshead at gmail dot com
2023-12-04  7:00 ` rguenth at gcc dot gnu.org
2024-01-23  9:46 ` cvs-commit at gcc dot gnu.org
2024-01-27 10:26 ` nshead at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-112820-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).