public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98364] New: C++20 module binary bloat
@ 2020-12-17 23:43 unlvsur at live dot com
2020-12-18 13:40 ` [Bug c++/98364] C++20 module global constructor emission nathan at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: unlvsur at live dot com @ 2020-12-17 23:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
Bug ID: 98364
Summary: C++20 module binary bloat
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: unlvsur at live dot com
Target Milestone: ---
the module will generate _ZGIW5helloEv which is dead code. There is no way to
remove them.
naive binary without module:
#include<cstdio>
int main()
{
puts("Hello World\n");
}
Disassembly of section .text:
0000000000401040 <main>:
401040: 48 83 ec 08 sub $0x8,%rsp
401044: bf 04 20 40 00 mov $0x402004,%edi
401049: e8 e2 ff ff ff callq 401030 <puts@plt>
40104e: 31 c0 xor %eax,%eax
401050: 48 83 c4 08 add $0x8,%rsp
401054: c3 retq
401055: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
40105c: 00 00 00
40105f: 90 nop
0000000000401060 <set_fast_math>:
401060: f3 0f 1e fa endbr64
401064: 0f ae 5c 24 fc stmxcsr -0x4(%rsp)
401069: 81 4c 24 fc 40 80 00 orl $0x8040,-0x4(%rsp)
401070: 00
401071: 0f ae 54 24 fc ldmxcsr -0x4(%rsp)
401076: c3 retq
401077: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
40107e: 00 00
module binary:
0000000000401050 <main>:
401050: 48 83 ec 08 sub $0x8,%rsp
401054: bf 04 20 40 00 mov $0x402004,%edi
401059: e8 d2 ff ff ff callq 401030 <puts@plt>
40105e: 31 c0 xor %eax,%eax
401060: 48 83 c4 08 add $0x8,%rsp
401064: c3 retq
401065: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1)
40106c: 00 00 00 00
0000000000401070 <_GLOBAL__sub_I_main>:
401070: e9 0b 00 00 00 jmpq 401080 <_ZGIW5helloEv>
401075: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
40107c: 00 00 00
40107f: 90 nop
0000000000401080 <_ZGIW5helloEv>:
401080: 80 3d b2 2f 00 00 00 cmpb $0x0,0x2fb2(%rip) #
404039 <_ZZ13_ZGIW5helloEvE9__in_chrg>
401087: 75 07 jne 401090 <_ZGIW5helloEv+0x10>
401089: c6 05 a9 2f 00 00 01 movb $0x1,0x2fa9(%rip) #
404039 <_ZZ13_ZGIW5helloEvE9__in_chrg>
401090: c3 retq
401091: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
401098: 00 00 00
40109b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
00000000004010a0 <set_fast_math>:
4010a0: f3 0f 1e fa endbr64
4010a4: 0f ae 5c 24 fc stmxcsr -0x4(%rsp)
4010a9: 81 4c 24 fc 40 80 00 orl $0x8040,-0x4(%rsp)
4010b0: 00
4010b1: 0f ae 54 24 fc ldmxcsr -0x4(%rsp)
4010b6: c3 retq
4010b7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
4010be: 00 00
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/98364] C++20 module global constructor emission
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
@ 2020-12-18 13:40 ` nathan at gcc dot gnu.org
2020-12-21 18:41 ` nathan at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: nathan at gcc dot gnu.org @ 2020-12-18 13:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
Nathan Sidwell <nathan at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |nathan at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2020-12-18
Summary|C++20 module binary bloat |C++20 module global
| |constructor emission
--- Comment #1 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
missed optimization/bad predicate
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/98364] C++20 module global constructor emission
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
2020-12-18 13:40 ` [Bug c++/98364] C++20 module global constructor emission nathan at gcc dot gnu.org
@ 2020-12-21 18:41 ` nathan at gcc dot gnu.org
2020-12-21 18:44 ` unlvsur at live dot com
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: nathan at gcc dot gnu.org @ 2020-12-21 18:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
Nathan Sidwell <nathan at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |WAITING
--- Comment #2 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
Is this windows-specific? please privode preprocessed source and compilation
command.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/98364] C++20 module global constructor emission
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
2020-12-18 13:40 ` [Bug c++/98364] C++20 module global constructor emission nathan at gcc dot gnu.org
2020-12-21 18:41 ` nathan at gcc dot gnu.org
@ 2020-12-21 18:44 ` unlvsur at live dot com
2020-12-21 18:44 ` unlvsur at live dot com
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: unlvsur at live dot com @ 2020-12-21 18:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
--- Comment #3 from cqwrteur <unlvsur at live dot com> ---
Created attachment 49824
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49824&action=edit
just compile them and link together to see assembly.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/98364] C++20 module global constructor emission
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
` (2 preceding siblings ...)
2020-12-21 18:44 ` unlvsur at live dot com
@ 2020-12-21 18:44 ` unlvsur at live dot com
2020-12-21 18:45 ` unlvsur at live dot com
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: unlvsur at live dot com @ 2020-12-21 18:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
--- Comment #4 from cqwrteur <unlvsur at live dot com> ---
(In reply to Nathan Sidwell from comment #2)
> Is this windows-specific? please privode preprocessed source and compilation
> command.
no
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/98364] C++20 module global constructor emission
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
` (3 preceding siblings ...)
2020-12-21 18:44 ` unlvsur at live dot com
@ 2020-12-21 18:45 ` unlvsur at live dot com
2020-12-21 18:51 ` unlvsur at live dot com
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: unlvsur at live dot com @ 2020-12-21 18:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
--- Comment #5 from cqwrteur <unlvsur at live dot com> ---
(In reply to cqwrteur from comment #3)
> Created attachment 49824 [details]
> just compile them and link together to see assembly.
compilation command
g++ -o main main.cc hello.cc -Ofast -std=c++20 -flto -fmodules-ts
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/98364] C++20 module global constructor emission
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
` (4 preceding siblings ...)
2020-12-21 18:45 ` unlvsur at live dot com
@ 2020-12-21 18:51 ` unlvsur at live dot com
2020-12-21 18:53 ` unlvsur at live dot com
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: unlvsur at live dot com @ 2020-12-21 18:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
--- Comment #6 from cqwrteur <unlvsur at live dot com> ---
(In reply to Nathan Sidwell from comment #2)
> Is this windows-specific? please privode preprocessed source and compilation
> command.
You need to just compile the code and then use objdump to view generated
assembly.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/98364] C++20 module global constructor emission
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
` (5 preceding siblings ...)
2020-12-21 18:51 ` unlvsur at live dot com
@ 2020-12-21 18:53 ` unlvsur at live dot com
2022-01-01 5:48 ` [Bug c++/98364] [modules] unnneded global constructors are emitted for a module pinskia at gcc dot gnu.org
2024-03-07 20:09 ` ppalka at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: unlvsur at live dot com @ 2020-12-21 18:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
--- Comment #7 from cqwrteur <unlvsur at live dot com> ---
Created attachment 49825
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49825&action=edit
header only naive version
g++ -o naive naive.cc -Ofast -std=c++20 -s -flto
compile both of them and compare assembly.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/98364] [modules] unnneded global constructors are emitted for a module
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
` (6 preceding siblings ...)
2020-12-21 18:53 ` unlvsur at live dot com
@ 2022-01-01 5:48 ` pinskia at gcc dot gnu.org
2024-03-07 20:09 ` ppalka at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-01 5:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |NEW
Summary|[modules] global |[modules] unnneded global
|constructor emission |constructors are emitted
| |for a module
Severity|normal |enhancement
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed:
;; Function (static initializers for hello.cc) (_ZGIW5helloEv)
;; enabled by -tree-original
{
static bool __in_chrg;
static bool __in_chrg;
if (__in_chrg)
{
return;
}
<<cleanup_point <<< Unknown tree: expr_stmt
(void) (__in_chrg = 1) >>>>>;
}
In main-hello.cc.005t.original.
The code comes from start_objects in cp/decl2.c:
if (module_init > 0)
{
// 'static bool __in_chrg = false;
// if (__inchrg) return;
// __inchrg = true
tree var = build_lang_decl (VAR_DECL, in_charge_identifier,
boolean_type_node);
DECL_CONTEXT (var) = fndecl;
DECL_ARTIFICIAL (var) = true;
TREE_STATIC (var) = true;
pushdecl (var);
cp_finish_decl (var, NULL_TREE, false, NULL_TREE, 0);
tree if_stmt = begin_if_stmt ();
finish_if_stmt_cond (var, if_stmt);
finish_return_stmt (NULL_TREE);
finish_then_clause (if_stmt);
finish_if_stmt (if_stmt);
tree assign = build2 (MODIFY_EXPR, boolean_type_node,
var, boolean_true_node);
TREE_SIDE_EFFECTS (assign) = true;
finish_expr_stmt (assign);
}
if (module_init)
module_add_import_initializers ();
Maybe if there are no initializers, maybe we should not create the global init.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/98364] [modules] unnneded global constructors are emitted for a module
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
` (7 preceding siblings ...)
2022-01-01 5:48 ` [Bug c++/98364] [modules] unnneded global constructors are emitted for a module pinskia at gcc dot gnu.org
@ 2024-03-07 20:09 ` ppalka at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-03-07 20:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
Status|NEW |RESOLVED
Target Milestone|--- |13.0
Resolution|--- |FIXED
--- Comment #9 from Patrick Palka <ppalka at gcc dot gnu.org> ---
This seems fixed since r13-1090-ge8609768fbbc1e.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-03-07 20:09 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 23:43 [Bug c++/98364] New: C++20 module binary bloat unlvsur at live dot com
2020-12-18 13:40 ` [Bug c++/98364] C++20 module global constructor emission nathan at gcc dot gnu.org
2020-12-21 18:41 ` nathan at gcc dot gnu.org
2020-12-21 18:44 ` unlvsur at live dot com
2020-12-21 18:44 ` unlvsur at live dot com
2020-12-21 18:45 ` unlvsur at live dot com
2020-12-21 18:51 ` unlvsur at live dot com
2020-12-21 18:53 ` unlvsur at live dot com
2022-01-01 5:48 ` [Bug c++/98364] [modules] unnneded global constructors are emitted for a module pinskia at gcc dot gnu.org
2024-03-07 20:09 ` ppalka 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).