Bug 103400 - src/c++98/*_allocator.cc symbols not exported
Summary: src/c++98/*_allocator.cc symbols not exported
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: link-failure
Depends on:
Blocks:
 
Reported: 2021-11-23 23:36 UTC by Jonathan Wakely
Modified: 2021-12-02 17:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2021-11-23 23:36:44 UTC
When GCC is configured with --enable-libstdcxx-allocator=pool we get this test failure:

FAIL: 27_io/manipulators/standard/wchar_t/2.cc (test for excess errors)
Excess errors:
/usr/bin/ld: Dwarf Error: Can't find .debug_ranges section.
2.cc:(.text._ZNSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEED2Ev[_ZNSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEED5Ev]+0x44): undefined reference to `__gnu_cxx::__pool_alloc<wchar_t>::deallocate(wchar_t*, unsigned long)'
2.cc:(.text._ZNSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEED0Ev[_ZNSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEED5Ev]+0x44): undefined reference to `__gnu_cxx::__pool_alloc<wchar_t>::deallocate(wchar_t*, unsigned long)'
2.cc:(.text._Z6test01v+0x464): undefined reference to `__gnu_cxx::__pool_alloc<wchar_t>::deallocate(wchar_t*, unsigned long)'
2.cc:(.text._Z6test01v+0x4c4): undefined reference to `__gnu_cxx::__pool_alloc<wchar_t>::deallocate(wchar_t*, unsigned long)'
2.cc:(.text._Z6test01v+0x51c): undefined reference to `__gnu_cxx::__pool_alloc<wchar_t>::deallocate(wchar_t*, unsigned long)'
collect2: error: ld returned 1 exit status

The specialization is explicitly instantiated in src/c++98/pool_allocator.cc:

  // Instantiations.
  template class __pool_alloc<char>;
  template class __pool_alloc<wchar_t>;

But the symbols have never been exported, so dynamic link fails (static linking works though).

Similarly, when built with --enable-libstdcxx-allocator=mt lots of tests fail, because the __gnu_cxx::__common_pool<__gnu_cxx::__pool, true>::_S_get_pool()::_S_pool static variable and its guard variable are not exported. That means the linker cannot combine the definition in libstdc++.so with the one in user code, and we get two copies of it. This means allocations and deallocations might happen in different pools, and so segfault.

And --enable-libstdcxx-allocator=bitmap is completely broken, see PR 103381.

it's not clear whether it's worth salvaging these extensions, or if we should just deprecate and them remove them.
Comment 1 Jonathan Wakely 2021-11-23 23:41:54 UTC
(In reply to Jonathan Wakely from comment #0)
> Similarly, when built with --enable-libstdcxx-allocator=mt lots of tests
> fail, because the __gnu_cxx::__common_pool<__gnu_cxx::__pool,
> true>::_S_get_pool()::_S_pool static variable and its guard variable are not
> exported. That means the linker cannot combine the definition in
> libstdc++.so with the one in user code, and we get two copies of it. This
> means allocations and deallocations might happen in different pools, and so
> segfault.

nm /tmp/alloc/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so | fgrep _S_pool
00000000002205e8 b _ZGVZN9__gnu_cxx13__common_poolINS_6__poolELb1EE11_S_get_poolEvE7_S_pool
0000000000220600 b _ZZN9__gnu_cxx13__common_poolINS_6__poolELb1EE11_S_get_poolEvE7_S_pool

They should have type 'u'. It can be fixed by:

--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -2400,6 +2400,8 @@ GLIBCXX_3.4.29 {
 GLIBCXX_3.4.30 {
 
     _ZSt21__glibcxx_assert_fail*;
+    _ZGVZN9__gnu_cxx13__common_poolINS_6__poolELb1EE11_S_get_poolEvE7_S_pool;
+    _ZZN9__gnu_cxx13__common_poolINS_6__poolELb1EE11_S_get_poolEvE7_S_pool;
 
 } GLIBCXX_3.4.29;
Comment 2 Jonathan Wakely 2021-11-24 00:03:31 UTC
(In reply to Jonathan Wakely from comment #0)
> And --enable-libstdcxx-allocator=bitmap is completely broken, see PR 103381.

Repeating PR 103381 comment 4:

Every test fails with:

/usr/bin/ld: .../libstdc++-v3/src/.libs/libstdc++.so: undefined reference to `__gnu_cxx::bitmap_allocator<unsigned int>::_S_last_request'
/usr/bin/ld: .../libstdc++-v3/src/.libs/libstdc++.so: undefined reference to `__gnu_cxx::bitmap_allocator<std::_Sp_counted_ptr_inplace<std::mutex, std::allocator<std::mutex>, (__gnu_cxx::_Lock_policy)2> >::_S_mut'
/usr/bin/ld: .../libstdc++-v3/src/.libs/libstdc++.so: undefined reference to `__gnu_cxx::bitmap_allocator<std::_Sp_counted_ptr_inplace<std::__future_base::_State_baseV2, std::allocator<std::__future_base::_State_baseV2>, (__gnu_cxx::_Lock_policy)2> >::_S_mut'
/usr/bin/ld: .../libstdc++-v3/src/.libs/libstdc++.so: undefined reference to `__gnu_cxx::bitmap_allocator<std::_Sp_counted_ptr_inplace<std::mutex, std::allocator<std::mutex>, (__gnu_cxx::_Lock_policy)2> >::_S_mem_blocks'
/usr/bin/ld: .../libstdc++-v3/src/.libs/libstdc++.so: undefined reference to `__gnu_cxx::bitmap_allocator<std::_Sp_counted_ptr_inplace<std::__future_base::_State_baseV2, std::allocator<std::__future_base::_State_baseV2>, (__gnu_cxx::_Lock_policy)2> >::_S_last_request'
/usr/bin/ld: .../libstdc++-v3/src/.libs/libstdc++.so: undefined reference to `__gnu_cxx::bitmap_allocator<unsigned int>::_S_mut'
/usr/bin/ld: .../libstdc++-v3/src/.libs/libstdc++.so: undefined reference to `__gnu_cxx::bitmap_allocator<unsigned int>::_S_mem_blocks'
/usr/bin/ld: .../libstdc++-v3/src/.libs/libstdc++.so: undefined reference to `__gnu_cxx::bitmap_allocator<std::_Sp_counted_ptr_inplace<std::mutex, std::allocator<std::mutex>, (__gnu_cxx::_Lock_policy)2> >::_S_last_request'
/usr/bin/ld: .../libstdc++-v3/src/.libs/libstdc++.so: undefined reference to `__gnu_cxx::bitmap_allocator<std::_Sp_counted_ptr_inplace<std::__future_base::_State_baseV2, std::allocator<std::__future_base::_State_baseV2>, (__gnu_cxx::_Lock_policy)2> >::_S_mem_blocks'
Comment 3 GCC Commits 2021-12-02 16:53:48 UTC
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:e2e98f524fdb80c16e3395f20fee930fbcad5562

commit r12-5754-ge2e98f524fdb80c16e3395f20fee930fbcad5562
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Dec 1 16:30:30 2021 +0000

    libstdc++: Remove broken std::allocator base classes [PR103340]
    
    The bitmap_allocator, __mt_alloc and __pool_alloc extensions are no
    longer suitable for use as the base class of std::allocator, because
    they have not been updated to meet the C++20 requirements.  There is a
    patch attached to PR 103340 which addresses that, but more work would be
    needed to solve the linking errors that occur when the library is
    configured to use them.
    
    Using --enable-libstdcxx-allocator=bitmap wouldn't even bootstrap for
    the past few years, and I can't find any gcc-testresults reports using
    any of these allocators. This patch removes the configure option to use
    these as the std::allocator base class. The allocators are still in the
    tree and can be used directly, you just can't configure the library to
    use one of them as the base class of std::allocator.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/103340
            PR libstdc++/103400
            PR libstdc++/103381
            * acinclude.m4 (GLIBCXX_ENABLE_ALLOCATOR): Remove mt, bitmap
            and pool options.
            * configure: Regenerate.
            * config/allocator/bitmap_allocator_base.h: Removed.
            * config/allocator/mt_allocator_base.h: Removed.
            * config/allocator/pool_allocator_base.h: Removed.
            * doc/xml/manual/allocator.xml: Update.
            * doc/xml/manual/configure.xml: Update.
            * doc/xml/manual/evolution.xml: Document removal.
            * doc/xml/manual/mt_allocator.xml: Editorial tweaks.
            * doc/html/manual/*: Regenerate.
Comment 4 Jonathan Wakely 2021-12-02 17:18:19 UTC
Fixed by removing these allocators as possible implementations of std::allocator.