| Issue |
60965
|
| Summary |
Failure to emit vtable members for std::shared_ptr control block
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
ecatmur
|
Since clang 5 (at least, that's the first version with C++17 support) until current trunk, the following program fails to link:
```c++
#include <functional>
#include <memory>
#include <utility>
template<class> void x() { std::shared_ptr<int>(new int); }
template<class> void y() { x<void>(); }
std::function<void()> a = []()
{
auto f = [](auto) -> void { y<int>(); };
auto g = [f](auto k) { return f(k); };
std::invoke(g, 0);
};
int main() {}
```
With libstdc++ the missing symbols are:
```
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eae5a1.o:(.data.rel.ro._ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE]+0x10): undefined reference to `std::_Sp_counted_ptr<int*, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eae5a1.o:(.data.rel.ro._ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE]+0x18): undefined reference to `std::_Sp_counted_ptr<int*, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eae5a1.o:(.data.rel.ro._ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE]+0x20): undefined reference to `std::_Sp_counted_ptr<int*, (__gnu_cxx::_Lock_policy)2>::_M_dispose()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eae5a1.o:(.data.rel.ro._ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE]+0x28): undefined reference to `std::_Sp_counted_ptr<int*, (__gnu_cxx::_Lock_policy)2>::_M_destroy()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eae5a1.o:(.data.rel.ro._ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE]+0x30): undefined reference to `std::_Sp_counted_ptr<int*, (__gnu_cxx::_Lock_policy)2>::_M_get_deleter(std::type_info const&)'
```
With libc++ they are:
```
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-44ea4b.o:(.data.rel.ro._ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE]+0x10): undefined reference to `std::__1::__shared_ptr_pointer<int*, std::__1::shared_ptr<int>::__shared_ptr_default_delete<int, int>, std::__1::allocator<int> >::~__shared_ptr_pointer()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-44ea4b.o:(.data.rel.ro._ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE]+0x18): undefined reference to `std::__1::__shared_ptr_pointer<int*, std::__1::shared_ptr<int>::__shared_ptr_default_delete<int, int>, std::__1::allocator<int> >::~__shared_ptr_pointer()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-44ea4b.o:(.data.rel.ro._ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE]+0x20): undefined reference to `std::__1::__shared_ptr_pointer<int*, std::__1::shared_ptr<int>::__shared_ptr_default_delete<int, int>, std::__1::allocator<int> >::__on_zero_shared()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-44ea4b.o:(.data.rel.ro._ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE]+0x28): undefined reference to `std::__1::__shared_ptr_pointer<int*, std::__1::shared_ptr<int>::__shared_ptr_default_delete<int, int>, std::__1::allocator<int> >::__get_deleter(std::type_info const&) const'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-44ea4b.o:(.data.rel.ro._ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE]+0x30): undefined reference to `std::__1::__shared_ptr_pointer<int*, std::__1::shared_ptr<int>::__shared_ptr_default_delete<int, int>, std::__1::allocator<int> >::__on_zero_shared_weak()'
```
Replacing std::shared_ptr with boost::shared_ptr:
```
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x10): undefined reference to `boost::detail::sp_counted_impl_p<int>::~sp_counted_impl_p()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x18): undefined reference to `boost::detail::sp_counted_impl_p<int>::~sp_counted_impl_p()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x20): undefined reference to `boost::detail::sp_counted_impl_p<int>::dispose()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x30): undefined reference to `boost::detail::sp_counted_impl_p<int>::get_deleter(std::type_info const&)'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x38): undefined reference to `boost::detail::sp_counted_impl_p<int>::get_local_deleter(std::type_info const&)'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x40): undefined reference to `boost::detail::sp_counted_impl_p<int>::get_untyped_deleter()'
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs