Skip to content

test(libs): compile allocation-counting tests with C++23 - #12999

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
pushkarreddyy:test/allocation-counting-cxx23
Oct 30, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
pushkarreddyy:test/allocation-counting-cxx23

Conversation

@pushkarreddyy

Copy link
Copy Markdown
Contributor

What

Built with MSYS2 UCRT64 GCC 16.2.0 on Windows, guest_json_copy_failure aborts (0xc0000409, operation leaked allocations, live=50, expected 49) and guest_libressl_object_allocation fails 108 of 740 checks (failed conversion releases scratch allocations).

Both test fixtures replace global operator new and operator delete to track live allocations. Under GCC 16 with -std=gnu++20, bits/basic_string.tcc contains extern template class basic_string<char> for __cplusplus <= 202002L, causing basic_string<char> members such as _M_dispose to be imported from libstdc++-6.dll. On Windows PE, deletions executed inside the DLL invoke the DLL's internal operator delete, bypassing the test executable's replacement and producing allocation-counting mismatches.

This sets cxx_std_23 compile features on guest_json_copy_failure_tests and guest_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 both new and delete route through the test's replacement operators.

Tested

  • Windows 11 Pro, MSYS2 UCRT64 GCC 16.2.0 (Rev6):
    • 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).
  • WinLibs GCC 15.2.0:
    • Both test suites pass cleanly 3/3 runs.
  • python tools/check_conventions.py --base origin/main reports 0 findings.

Checklist

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
@pushkarreddyy
pushkarreddyy force-pushed the test/allocation-counting-cxx23 branch from 2284598 to 58f3665 Compare October 29, 2026 20:19
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 10378 core/libs/prx/libSceJson2/CMakeLists.txt L30

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.

Pull request Shared files not compared
PR 9446 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 9571 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10418 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10448 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10450 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10477 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10478 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10481 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10482 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10483 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10486 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10488 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10508 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10570 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10571 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 10834 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 11128 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 11129 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 11138 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 11143 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 11146 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 11151 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 11175 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 11176 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 11466 core/libs/prx/libSceLibreSsl/CMakeLists.txt

@rooklz rooklz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-tree against main 951f374 is clean, and so is git diff --check.
  • check_conventions --base main passes.
  • pr_overlap --branch merged 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 the guest_json_copy_failure_tests block and adds target_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_cold is still imported. An alternative that doesn't depend on it would be static libstdc++ for these two MinGW tests (-static-libstdc++, which configure_host_test_executable already uses elsewhere). I haven't checked that it works together with the guest libc link, 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

@github-actions github-actions Bot added the fix error Closes an issue (Fixes #N) label Oct 29, 2026
@bunbeans2-arch

Copy link
Copy Markdown
Contributor

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, BUILD_TESTING=ON, Ninja.

  • main 992d3fa: ctest -R '^(guest_json_copy_failure|guest_libressl_object_allocation)$' failed both tests in 5 of 5 runs. guest_json_copy_failure exits 0xc0000409 after parse nested array budget=10: operation leaked allocations (live=50) / expected 49 live allocations, got 50. guest_libressl_object_allocation reports "checks":740,"failures":108 (failed conversion releases scratch allocations).
  • main 992d3fa with this PR's diff (58f3665aa2) applied, same build directory: both tests passed in 5 of 5 runs.

So 16.1 is affected the same way as 16.2, and this change fixes it there too.

AI-assisted: yes (Claude Code)

@bunbeans2-arch

Copy link
Copy Markdown
Contributor

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, BUILD_TESTING=ON. main 992d3fa639, then the same tree with this pull request's two target_compile_features(... PRIVATE cxx_std_23) lines applied (head 58f3665aa2). ctest -R "^(guest_json_copy_failure|guest_libressl_object_allocation)$" -V, 3 runs per side:

  • main: both fail in 3 of 3 runs. guest_json_copy_failure exits 0xc0000409 with expected 49 live allocations, got 50; guest_libressl_object_allocation reports "checks":740,"failures":108.
  • With this pull request: both pass in 3 of 3 runs; guest_libressl_object_allocation reports "failures":0,"final_live":0.

AI-assisted: yes (Claude Code)

@adriadam10 adriadam10 self-assigned this Oct 30, 2026
@adriadam10
adriadam10 merged commit c077c0f into boykopovar:main Oct 30, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the two cxx_std_23 lines against the extern-template mechanism (confirmed independently by @rooklz and on a second Windows host by @bunbeans2-arch: both tests fail on main, pass with this change); scope is limited to the two test executables; Windows job green; merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build fix error Closes an issue (Fixes #N) prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests: guest_json_copy_failure and guest_libressl_object_allocation count a leak with GCC 16's libstdc++ on Windows

4 participants