<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57131>57131</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang disagrees with GCC about __attribute__((used)) C1 constructor emission
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++,
clang:codegen
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Keno
</td>
</tr>
</table>
<pre>
```
struct foo {
int x;
foo(const foo&) noexcept;
};
__attribute__((used)) inline foo::foo(const foo &other) noexcept {
this->x = other.x;
}
```
With
```
x86_64-linux-gnu-gcc (GCC) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```
built from source, this compiles to:
```
# x86_64-linux-gnu-gcc -S -o - test.cpp
.file "test.cpp"
.text
.section .text._ZN3fooC2ERKS_,"axG",@progbits,_ZN3fooC5ERKS_,comdat
.align 2
.weak _ZN3fooC2ERKS_
.type _ZN3fooC2ERKS_, @function
_ZN3fooC2ERKS_:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movq %rdi, -8(%rbp)
movq %rsi, -16(%rbp)
movq -16(%rbp), %rax
movl (%rax), %edx
movq -8(%rbp), %rax
movl %edx, (%rax)
nop
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size _ZN3fooC2ERKS_, .-_ZN3fooC2ERKS_
.weak _ZN3fooC1ERKS_
.set _ZN3fooC1ERKS_,_ZN3fooC2ERKS_
.ident "GCC: (GNU) 11.1.0"
.section .note.GNU-stack,"",@progbits
```
Note in particular the definition of `_ZN3fooC1ERKS_`
```
.weak _ZN3fooC1ERKS_
.set _ZN3fooC1ERKS_,_ZN3fooC2ERKS_
```
With clang trunk, we get for the same file:
```
# clang -S -o - test.cpp
.text
.file "test.cpp"
.section .text._ZN3fooC2ERKS_,"axG",@progbits,_ZN3fooC2ERKS_,comdat
.weak _ZN3fooC2ERKS_ # -- Begin function _ZN3fooC2ERKS_
.p2align 4, 0x90
.type _ZN3fooC2ERKS_,@function
_ZN3fooC2ERKS_: # @_ZN3fooC2ERKS_
.cfi_startproc
# %bb.0:
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
movq %rdi, -8(%rbp)
movq %rsi, -16(%rbp)
movq -8(%rbp), %rax
movq -16(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, (%rax)
popq %rbp
.cfi_def_cfa %rsp, 8
retq
.Lfunc_end0:
.size _ZN3fooC2ERKS_, .Lfunc_end0-_ZN3fooC2ERKS_
.cfi_endproc
# -- End function
.ident "clang version 16.0.0 (https://github.com/llvm/llvm-project 7ce321e5b0a431d8fde69ce03d1bd7254a7dc00c)"
.section ".note.GNU-stack","",@progbits
.addrsig
```
with no definition of `_ZN3fooC1ERKS_`.
This pattern of `__attribute__((used))` is used in the wild (including in libstdc++) to provide ABI compatibility for functions that were moved from the implementation into an inline definition. Because of this issue, if such a library is compiled with clang, old applications linked against the previous (non-inline) version will be missing the C1 symbol.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1V1uP2jgU_jXwYiVKHAjwwAPDQHfU7rSamWq1-4Ic2wneBjuNnRnor99jhxAugc5quygSic_F3zk-57OdKLab9uJg_wT3vWCmTVlRg1KlUG90V4-h-iekQdtedDoIP9Dt4TFVUpv6Pe7hCZKKbykvzMGgN7o_vK9WxJhSJJXhqxUYw1NpzsDOmgqZC8mdr2gGz9kECGZQZs3L42ku0CKzFtrrRYst6kX3yBn42xM09ctp_H8Is-4UbMfxKh54gKzaepmsvIxSQDL-MJ9bHGHoh_5eda6KXSmytbFyJ8UBDtGy5Bw9q9S8kZKjpaokI0Yo2cNz9C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