<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/97244>97244</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] module should not emit module initializer if it is not used in the module
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
trcrsired
</td>
</tr>
</table>
<pre>
```cpp
//mymodule.cppm
module;
export module mymodule;
```
```cpp
//main.cc
import mymodule;
int main(){}
```
```
clang++ --precompile mymodule.cppm -std=c++26 -Ofast -o mymodule.gcm
clang++ -o main main.cc -std=c++26 -Ofast -fmodule-file=mymodule.gcm -fuse
-ld=lld
warning: the form '-fmodule-file=<BMI-path>' is deprecated for standard C++ named modules;consider to use
'-fmodule-file=<module-name>=<BMI-path>' instead [-Weager-load-cxx-named-modules]
1 warning generated.
ld.lld: error: undefined symbol: initializer for module mymodule
>>> referenced by C:/Users/unlvs/AppData/Local/Temp/main-c847e4.o:(_GLOBAL__sub_I_main.cc)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```
The asm it generates will "jmp _ZGIW8mymodule". However, GCC does not emit that after my complaint before. If the module has global variables, it should emit no symbol.
```
.text
.def @feat.00;
.scl 3;
.type 0;
.endef
.globl @feat.00
.set @feat.00, 0
.file "main.cc"
.def main;
.scl 2;
.type 32;
.endef
.globl main # -- Begin function main
.p2align 4, 0x90
main: # @main
.seh_proc main
# %bb.0:
pushq %rbp
.seh_pushreg %rbp
subq $32, %rsp
.seh_stackalloc 32
leaq 32(%rsp), %rbp
.seh_setframe %rbp, 32
.seh_endprologue
callq __main
xorl %eax, %eax
addq $32, %rsp
popq %rbp
retq
.seh_endproc
# -- End function
.def _GLOBAL__sub_I_main.cc;
.scl 3;
.type 32;
.endef
.p2align 4, 0x90 # -- Begin function _GLOBAL__sub_I_main.cc
_GLOBAL__sub_I_main.cc: # @_GLOBAL__sub_I_main.cc
# %bb.0:
jmp _ZGIW8mymodule # TAILCALL
# -- End function
.section .ctors,"dw"
.p2align 3, 0x0
.quad _GLOBAL__sub_I_main.cc
.section .drectve,"yni"
.addrsig
.addrsig_sym _GLOBAL__sub_I_main.cc
```
```
g++ -c mymodule.cppm -Ofast -std=c++26 -fmodules-ts
g++ -o main main.cc mymodule.o -Ofast -std=c++26 -fmodules-ts
```
```
g++ -c mymodule.cppm -Ofast -std=c++26 -fmodules-ts
g++ -S main.cc mymodule.o -Ofast -std=c++26 -fmodules-ts
g++: warning: mymodule.o: linker input file unused because linking not done
.file "main.cc"
.text
.section .text.startup,"x"
.p2align 4
.globl main
.def main; .scl 2; .type 32; .endef
.seh_proc main
main:
.LFB0:
subq $40, %rsp
.seh_stackalloc 40
.seh_endprologue
call __main
xorl %eax, %eax
addq $40, %rsp
ret
.seh_endproc
.def __main; .scl 2; .type 32; .endef
.ident "GCC: (GNU) 15.0.0 20240629 (experimental)"
```
Also, I do think gcc just reuses -c option and .o file which is a better choice plus clang should be compatible with GCC
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8V0tv67oR_jX0ZiBBpvzSwovYuU4DpL2LnosLdGNQ5EjiORSpQ1KJ019fUJJt-ZHctAdoYMQWH998wxnOfGLOyVIjrsl8Q-aPE9b6yti1t9w6aVFMciPe12SR9B_eNCR5JMkDoTtCd_V7bUSrMOZNU_cT_QBJN8O67j8eGmM99HNw3HVedIS_ery2xqSOOe-HZN1D3mD1s9pDWE7oitCMLDdk-fi5rf6RK6ZLQjeEbiCKGovc1I0cce48hch5QdJH3q-kC4h-L5jzEJnzwpLXdzBNRwsGVz4GKnqUqJDBt8cxKkRF67DHjlTYrpToH9-Y1VKXJH0AXyEUxtZA6PIajaTbzd-fo4b5iqS_EboE6UBgcJd5FGEfOM-0YFbAdqCuWY1iCKEj6YYb7aRAC97AiQ90f_dNDgMBJ1i9S0M7j0wAmW-iP5GVaCNlmIj44dDtE9HR_nwI5xQGn6FEjTbQj_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