public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112820] New: vtable not emitted correctly from module when compiling with -g
@ 2023-12-02 1:38 michael.kenzel at gmail dot com
2023-12-02 12:31 ` [Bug c++/112820] " nathanieloshead at gmail dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: michael.kenzel at gmail dot com @ 2023-12-02 1:38 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112820] vtable not emitted correctly from module when compiling with -g
2023-12-02 1:38 [Bug c++/112820] New: vtable not emitted correctly from module when compiling with -g michael.kenzel at gmail dot com
@ 2023-12-02 12:31 ` nathanieloshead at gmail dot com
2023-12-04 7:00 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: nathanieloshead at gmail dot com @ 2023-12-02 12:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112820
Nathaniel Shead <nathanieloshead at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nathanieloshead at gmail dot com
--- Comment #1 from Nathaniel Shead <nathanieloshead at gmail dot com> ---
The issue seems to be that the same flag is used for DECL_EXTERN and
TYPE_DECL_SUPPRESS_DEBUG, and the modules reading code is getting confused and
thinking that TYPE_DECLs with the latter flag set means that they are actually
DECL_EXTERN and thus preventing them from being emitted.
The following hunk fixes this issue but it'd probably be better to clean up all
handling of extern within the modules reading so that we don't lose the
"suppress debug" flag entirely.
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 33fcf396875..add3fa4b945 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -5397,7 +5397,7 @@ trees_out::core_bools (tree t)
DECL_NOT_REALLY_EXTERN -> base.not_really_extern
== that was a lie, it is here */
- bool is_external = t->decl_common.decl_flag_1;
+ bool is_external = code != TYPE_DECL && t->decl_common.decl_flag_1;
if (!is_external)
/* decl_flag_1 is DECL_EXTERNAL. Things we emit here, might
well be external from the POV of an importer. */
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112820] vtable not emitted correctly from module when compiling with -g
2023-12-02 1:38 [Bug c++/112820] New: vtable not emitted correctly from module when compiling with -g michael.kenzel at gmail dot com
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
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-12-04 7:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112820
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |documentation,
| |internal-improvement
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
The flags are documented to not apply to the same entities (TYPE_DECL vs. other
_DECL nodes). If that no longer applies then I think we should pick different
flags here (or not use DECL_EXTERNAL on TYPE_DECL in the C++ frontend?).
We might want to strengthen the tree checking on DECL_EXTERNAL as it currently
allows all decl nodes.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112820] vtable not emitted correctly from module when compiling with -g
2023-12-02 1:38 [Bug c++/112820] New: vtable not emitted correctly from module when compiling with -g michael.kenzel at gmail dot com
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
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-23 9:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112820
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:
https://gcc.gnu.org/g:affef534b0335592336c82918f15242576e2ab8f
commit r14-8350-gaffef534b0335592336c82918f15242576e2ab8f
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date: Wed Jan 17 16:50:39 2024 +1100
c++: Fix handling of extern templates in modules [PR112820]
Currently, extern templates are detected by looking for the
DECL_EXTERNAL flag on a TYPE_DECL. However, this is incorrect:
TYPE_DECLs don't actually set this flag, and it happens to work by
coincidence due to TYPE_DECL_SUPPRESS_DEBUG happening to use the same
underlying bit. This however causes issues with other TYPE_DECLs that
also happen to have suppressed debug information.
Instead, this patch reworks the logic so CLASSTYPE_INTERFACE_ONLY is
always emitted into the module BMI and can then be used to check for an
extern template correctly.
Otherwise, for other declarations we always want to redetermine this:
even for declarations from the GMF, we may change our mind on whether to
import or export depending on decisions made later in the TU after
importing so we shouldn't decide this now, or necessarily reuse what the
module we'd imported had decided.
Some of this may need to change in the future to account for
https://github.com/itanium-cxx-abi/cxx-abi/issues/170.
PR c++/112820
PR c++/102607
gcc/cp/ChangeLog:
* module.cc (trees_out::lang_type_bools): Write interface_only
and interface_unknown.
(trees_in::lang_type_bools): Read the above flags.
(trees_in::decl_value): Reset CLASSTYPE_INTERFACE_* except for
extern templates.
(trees_in::read_class_def): Remove buggy extern template
handling.
gcc/testsuite/ChangeLog:
* g++.dg/modules/debug-2_a.C: New test.
* g++.dg/modules/debug-2_b.C: New test.
* g++.dg/modules/debug-2_c.C: New test.
* g++.dg/modules/debug-3_a.C: New test.
* g++.dg/modules/debug-3_b.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112820] vtable not emitted correctly from module when compiling with -g
2023-12-02 1:38 [Bug c++/112820] New: vtable not emitted correctly from module when compiling with -g michael.kenzel at gmail dot com
` (2 preceding siblings ...)
2024-01-23 9:46 ` cvs-commit at gcc dot gnu.org
@ 2024-01-27 10:26 ` nshead at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: nshead at gcc dot gnu.org @ 2024-01-27 10:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112820
Nathaniel Shead <nshead at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Target Milestone|--- |14.0
Resolution|--- |FIXED
Assignee|unassigned at gcc dot gnu.org |nshead at gcc dot gnu.org
--- Comment #4 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
Fixed for GCC 14.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-01-27 10:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-02 1:38 [Bug c++/112820] New: vtable not emitted correctly from module when compiling with -g michael.kenzel at gmail dot com
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
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).