Repository navigation
test(libs): compile allocation-counting tests with C++23 - #12999
Conversation
Under MSYS2 UCRT64 GCC 16.2.0 on Windows, guest_json_copy_failure aborts (0xc0000409, operation leaked allocations) due to basic_string extern template member deallocations routing to libstdc++-6.dll's operator delete. Compile guest_json_copy_failure_tests with C++23 (cxx_std_23) so GCC 16 inlines basic_string members into the test executable.
…ith C++23 Under MSYS2 UCRT64 GCC 16.2.0 on Windows, guest_libressl_object_allocation fails 108 of 740 checks due to cross-module allocator counting mismatches with libstdc++-6.dll. Compile guest_libressl_object_allocation_tests with C++23 (cxx_std_23) so string member operations route through the test's replacement operators. Fixes boykopovar#12969
2284598 to
58f3665
Compare
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
rooklz
left a comment
There was a problem hiding this comment.
Approving: I checked the mechanism independently and the evidence holds.
Headers. In Homebrew GCC 16.2.0, bits/basic_string.tcc L1040-1041 has # if __cplusplus <= 202002L && _GLIBCXX_EXTERN_TEMPLATE > 0 → extern template class basic_string<char>;. Under C++23 only _M_replace_cold stays extern. That matches the PR description.
Objects. I compiled every TU of both targets with g++-16 -O2 -Icore/libs at -std=gnu++20 and at gnu++23, then ran nm -u | c++filt on each:
| TU | gnu++20 undefined basic_string<char> |
gnu++23 |
|---|---|---|
| libSceJson2/Export.cpp | _M_dispose, _M_replace_cold, append(const char*), reserve, move ctor, runtime_error(const string&) |
_M_replace_cold, runtime_error(const string&) |
| libSceLibreSsl/src/ObjectText.cpp | _M_dispose, _M_replace_cold |
_M_replace_cold |
| tests/JsonCopyFailure.cpp, ObjectTextAllocation.cpp, ObjectTable.cpp, Error.cpp | none | none |
With C++23, every string member that allocates or frees (_M_dispose, reserve, append, move ctor) is instantiated inside the test executable, so it uses the replaced operator new/delete. _M_replace_cold still resolves into libstdc++, but it only moves characters and never allocates. That fits the live=50 vs 49 failure coming from a DLL-side _M_dispose.
Compile. All 6 TUs build with 0 errors under clang++ and g++-16 at both gnu++20 and gnu++23. target_compile_features(... cxx_std_23) stays inside CMake 3.20's known features, and it only affects the two test targets, not the shipped libSceJson2/libSceLibreSsl.
Gates (head 58f3665):
git merge-treeagainst main 951f374 is clean, and so isgit diff --check.check_conventions --base mainpasses.pr_overlap --branchmerged 42/42 and listed 16 shared-file PRs that it couldn't compare. 15 of those already conflict with main. The one real clash is #10378 (kyon-eth, libSceJson2 allocator): it also touches theguest_json_copy_failure_testsblock and addstarget_link_libraries(... libkernel libc)right where this PR adds its line. It's a one-line context conflict and whichever lands second needs a trivial rebase.
Non-blocking:
- The fix relies on a libstdc++ detail: the C++23 instantiation rule could change, and
_M_replace_coldis still imported. An alternative that doesn't depend on it would be static libstdc++ for these two MinGW tests (-static-libstdc++, whichconfigure_host_test_executablealready uses elsewhere). I haven't checked that it works together with the guestlibclink, so this is only a suggestion. - I verified this on macOS with g++-16 object symbols. I could not reproduce the Windows PE runtime myself; that part rests on your MSYS2 3/3 runs.
AI-assisted: yes
|
Same result with an older GCC 16, on a second host: Windows 11 Pro 10.0.22631, i9-9900K, MSYS2 UCRT64 GCC 16.1.0 (Rev5), Release,
So 16.1 is affected the same way as 16.2, and this change fixes it there too. AI-assisted: yes (Claude Code) |
|
A run on GCC 16.1, since #12969 reports 16.2: the same failure, and this change fixes it. Windows 11 Pro 10.0.22631, Intel i9-9900K, MSYS2 UCRT64 g++ 16.1.0 (Rev5), Ninja, Release,
AI-assisted: yes (Claude Code) |
|
Checked the two |
What
Built with MSYS2 UCRT64 GCC 16.2.0 on Windows,
guest_json_copy_failureaborts (0xc0000409,operation leaked allocations, live=50, expected 49) andguest_libressl_object_allocationfails 108 of 740 checks (failed conversion releases scratch allocations).Both test fixtures replace global
operator newandoperator deleteto track live allocations. Under GCC 16 with-std=gnu++20,bits/basic_string.tcccontainsextern template class basic_string<char>for__cplusplus <= 202002L, causingbasic_string<char>members such as_M_disposeto be imported fromlibstdc++-6.dll. On Windows PE, deletions executed inside the DLL invoke the DLL's internaloperator delete, bypassing the test executable's replacement and producing allocation-counting mismatches.This sets
cxx_std_23compile features onguest_json_copy_failure_testsandguest_libressl_object_allocation_tests. Under C++23, GCC 16 drops the extern template declaration and inlines the string members directly into the test executable, ensuring bothnewanddeleteroute through the test's replacement operators.Tested
guest_json_copy_failure: 549 allocation failures, no leaks (passes 3/3 runs).guest_libressl_object_allocation: 0 failures, final_live 0 (passes 3/3 runs).python tools/check_conventions.py --base origin/mainreports 0 findings.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)