libc: Fix cxa_thread_atexit{,nothr} test.

After patch 9d26b82, we don't provide recursive call protection anymore.
Therefore, to pass the test, we adjust the testcase by protecting on
caller and the testcase is to make sure the dtors is properly handled.

Reported by:    siva
Reviewed by:    kib
Approved by:    markj (mentor)
Fixes:  9d26b82826 ("libc: Fix dtor order in __cxa_thread_atexit")
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D55893
This commit is contained in:
ShengYi Hung
2026-03-17 22:53:08 +08:00
parent 191f47bcd6
commit c25976f0a9
2 changed files with 16 additions and 5 deletions
@@ -30,7 +30,10 @@
#include <cstdio>
#include <cstdlib>
#define AGAIN_CALL_LIMIT 20
static FILE *output = NULL;
static int again_counter = 0;
struct Foo {
Foo() { ATF_REQUIRE(fprintf(output, "Created\n") > 0); }
@@ -79,14 +82,16 @@ extern "C" int __cxa_thread_atexit(void (*)(void *), void *, void *);
static void
again(void *arg)
{
__cxa_thread_atexit(again, arg, &output);
if (again_counter < AGAIN_CALL_LIMIT) {
again_counter++;
__cxa_thread_atexit(again, arg, &output);
}
}
ATF_TEST_CASE_WITHOUT_HEAD(cxx__thread_inf_dtors);
ATF_TEST_CASE_BODY(cxx__thread_inf_dtors)
{
skip("Skip since we only have main thread");
again(NULL);
}
@@ -30,7 +30,10 @@
#include <cstdlib>
#include <thread>
#define AGAIN_CALL_LIMIT 20
static FILE *output = NULL;
static int again_counter = 0;
struct Foo {
Foo() { ATF_REQUIRE(fprintf(output, "Created\n") > 0); }
@@ -52,8 +55,10 @@ extern "C" int __cxa_thread_atexit(void (*)(void *), void *, void *);
static void
again(void *arg)
{
__cxa_thread_atexit(again, arg, &output);
if (again_counter < AGAIN_CALL_LIMIT) {
++again_counter;
__cxa_thread_atexit(again, arg, &output);
}
}
struct Baz {
@@ -164,6 +169,7 @@ ATF_TEST_CASE_BODY(cxx__thread_inf_dtors)
std::thread t([]() { e.use(); });
t.join();
ATF_REQUIRE_EQ(again_counter, AGAIN_CALL_LIMIT);
}
ATF_INIT_TEST_CASES(tcs)