Repository navigation
Leave room for a mutex-policy control block in CONNECTION_BLOCK_BYTES - #263
Merged
Merged
Conversation
Raspbian's ARMv6 libstdc++ uses the mutex lock policy for shared_ptr, so std::allocate_shared()'s control block embeds a pthread_mutex_t and needs 48 bytes beyond the connection, over the 32 reserved. The static_assert in ConnectionBlockAllocator::allocate() then fails and the library no longer builds there. Reserve sizeof(std::mutex) more, which has the size of that mutex. test_connection_block.cpp builds the connection under the default policy and, on libstdc++, under the mutex one, so a libstdc++ host reproduces the ARMv6 layout.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since #254,
ConnectionBlockAllocator::allocate()fails its compile-time check on Raspbian's ARMv6 toolchain:CONNECTION_BLOCK_BYTES<Conn>reservedsizeof(Conn) + 32for the object and the control blockstd::allocate_shared()puts it in. Raspbian's libstdc++ uses the mutex lock policy forshared_ptr, even though the compiler reports lock-free atomics, so the control block embeds apthread_mutex_tand needs 48 bytes beyondConn. sendspin-cpp-cli's linux-armv6 job (Raspberry Pi Zero and Pi 1) can't move its pin past 3a3722a until this builds.__GCC_ATOMIC_INT_LOCK_FREEstd::__default_lock_policy_S_mutex_S_atomicsizeof(std::_Sp_counted_base<>)Change
CONNECTION_BLOCK_BYTES<Conn>is nowsizeof(Conn) + 32 + sizeof(std::mutex). libstdc++'s policy mutex wraps the samepthread_mutex_tthatstd::mutexdoes, so this covers it without naming libstdc++ internals in the library:std::mutexis newlib's 4-bytepthread_mutex_thandle, so each connection block grows by about 4 bytes. Nothing else changes: no static RAM, flash, stack or allocation count. The 32 bytes already fit there.A flat 64 would be simpler, but leaves no headroom for a 64-bit mutex-policy libstdc++. Sizing from the exact control block type would need libstdc++ internals.
Tests
New
test_connection_block.cppplaces the hostSendspinClientConnectionin a reserved block, the wayconnect_to()does:HoldsConnectionUnderDefaultPolicy: the control case. The object lands inside the block, and dropping the last reference frees it (LSan checks the free in the sanitizer build).HoldsConnectionUnderMutexPolicy(libstdc++ only): builds throughstd::__allocate_shared<Conn, _S_mutex>, so CI's ubuntu jobs build the ARMv6 layout. With the old+ 32it fails to compile (1688 <= 1656); with the fix it passes. A 32-bit armhf job would not have caught this, because armhf uses the atomic policy.Full suite on Linux (g++ 13, ASan/UBSan): 760/760 pass. The new file also compiles with clang-cl.