diff --git a/libc/libc.map.txt b/libc/libc.map.txt index 5695dc6c4..4a4e60777 100644 --- a/libc/libc.map.txt +++ b/libc/libc.map.txt @@ -1518,34 +1518,34 @@ LIBC_R { # introduced=R tss_set; # Unwinder implementation - __aeabi_unwind_cpp_pr0; # apex llndk arm - __aeabi_unwind_cpp_pr1; # apex llndk arm - __aeabi_unwind_cpp_pr2; # apex llndk arm - __deregister_frame; # apex llndk arm64 x86 x86_64 - __gnu_unwind_frame; # apex llndk arm - __register_frame; # apex llndk arm64 x86 x86_64 - _Unwind_Backtrace; # apex llndk - _Unwind_Complete; # apex llndk arm - _Unwind_DeleteException; # apex llndk - _Unwind_Find_FDE; # apex llndk - _Unwind_FindEnclosingFunction; # apex llndk - _Unwind_ForcedUnwind; # apex llndk arm64 x86 x86_64 - _Unwind_GetCFA; # apex llndk - _Unwind_GetDataRelBase; # apex llndk - _Unwind_GetGR; # apex llndk - _Unwind_GetIP; # apex llndk - _Unwind_GetIPInfo; # apex llndk - _Unwind_GetLanguageSpecificData; # apex llndk - _Unwind_GetRegionStart; # apex llndk - _Unwind_GetTextRelBase; # apex llndk - _Unwind_RaiseException; # apex llndk - _Unwind_Resume; # apex llndk - _Unwind_Resume_or_Rethrow; # apex llndk - _Unwind_SetGR; # apex llndk - _Unwind_SetIP; # apex llndk - _Unwind_VRS_Get; # apex llndk arm - _Unwind_VRS_Pop; # apex llndk arm - _Unwind_VRS_Set; # apex llndk arm + __aeabi_unwind_cpp_pr0; # arm + __aeabi_unwind_cpp_pr1; # arm + __aeabi_unwind_cpp_pr2; # arm + __deregister_frame; # arm64 x86 x86_64 + __gnu_unwind_frame; # arm + __register_frame; # arm64 x86 x86_64 + _Unwind_Backtrace; + _Unwind_Complete; # arm + _Unwind_DeleteException; + _Unwind_Find_FDE; + _Unwind_FindEnclosingFunction; + _Unwind_ForcedUnwind; # arm64 x86 x86_64 + _Unwind_GetCFA; + _Unwind_GetDataRelBase; + _Unwind_GetGR; + _Unwind_GetIP; + _Unwind_GetIPInfo; + _Unwind_GetLanguageSpecificData; + _Unwind_GetRegionStart; + _Unwind_GetTextRelBase; + _Unwind_RaiseException; + _Unwind_Resume; + _Unwind_Resume_or_Rethrow; + _Unwind_SetGR; + _Unwind_SetIP; + _Unwind_VRS_Get; # arm + _Unwind_VRS_Pop; # arm + _Unwind_VRS_Set; # arm } LIBC_Q; LIBC_S { # introduced=S diff --git a/libc/malloc_debug/PointerData.cpp b/libc/malloc_debug/PointerData.cpp index 5ab2232f2..e3a35a687 100644 --- a/libc/malloc_debug/PointerData.cpp +++ b/libc/malloc_debug/PointerData.cpp @@ -26,6 +26,7 @@ * SUCH DAMAGE. */ +#include #include #include #include @@ -54,8 +55,6 @@ #include "malloc_debug.h" #include "UnwindBacktrace.h" -extern "C" char* __cxa_demangle(const char*, char*, size_t*, int*); - std::atomic_uint8_t PointerData::backtrace_enabled_; std::atomic_bool PointerData::backtrace_dump_; @@ -617,8 +616,8 @@ void PointerData::DumpLiveToFile(int fd) { if (frame.function_name.empty()) { dprintf(fd, " \"\" 0}"); } else { - char* demangled_name = __cxa_demangle(frame.function_name.c_str(), nullptr, nullptr, - nullptr); + char* demangled_name = + abi::__cxa_demangle(frame.function_name.c_str(), nullptr, nullptr, nullptr); const char* name; if (demangled_name != nullptr) { name = demangled_name; diff --git a/libc/malloc_debug/UnwindBacktrace.cpp b/libc/malloc_debug/UnwindBacktrace.cpp index c892a39da..8a6ff7b7f 100644 --- a/libc/malloc_debug/UnwindBacktrace.cpp +++ b/libc/malloc_debug/UnwindBacktrace.cpp @@ -26,6 +26,7 @@ * SUCH DAMAGE. */ +#include #include #include #include @@ -48,8 +49,6 @@ #define PAD_PTR "08" PRIx64 #endif -extern "C" char* __cxa_demangle(const char*, char*, size_t*, int*); - bool Unwind(std::vector* frames, std::vector* frame_info, size_t max_frames) { [[clang::no_destroy]] static unwindstack::AndroidLocalUnwinder unwinder( @@ -89,7 +88,8 @@ void UnwindLog(const std::vector& frame_info) { if (!info->function_name.empty()) { line += " ("; - char* demangled_name = __cxa_demangle(info->function_name.c_str(), nullptr, nullptr, nullptr); + char* demangled_name = + abi::__cxa_demangle(info->function_name.c_str(), nullptr, nullptr, nullptr); if (demangled_name != nullptr) { line += demangled_name; free(demangled_name); diff --git a/libc/malloc_debug/backtrace.cpp b/libc/malloc_debug/backtrace.cpp index 0649571ef..ecb3a80a0 100644 --- a/libc/malloc_debug/backtrace.cpp +++ b/libc/malloc_debug/backtrace.cpp @@ -26,6 +26,7 @@ * SUCH DAMAGE. */ +#include #include #include #include @@ -48,8 +49,6 @@ typedef struct _Unwind_Context __unwind_context; -extern "C" char* __cxa_demangle(const char*, char*, size_t*, int*); - static MapData g_map_data; static const MapEntry* g_current_code_map = nullptr; @@ -145,7 +144,7 @@ std::string backtrace_string(const uintptr_t* frames, size_t frame_count) { char buf[1024]; if (symbol != nullptr) { - char* demangled_name = __cxa_demangle(symbol, nullptr, nullptr, nullptr); + char* demangled_name = abi::__cxa_demangle(symbol, nullptr, nullptr, nullptr); const char* name; if (demangled_name != nullptr) { name = demangled_name; diff --git a/tests/__cxa_atexit_test.cpp b/tests/__cxa_atexit_test.cpp index 6a122d1cb..9f73261d6 100644 --- a/tests/__cxa_atexit_test.cpp +++ b/tests/__cxa_atexit_test.cpp @@ -26,19 +26,30 @@ * SUCH DAMAGE. */ -#include #include +extern "C" { +int __cxa_atexit(void (*func)(void*), void* arg, void* dso); + +// TODO(b/175635923). __cxa_finalize's return type should actually be "void", +// but it is declared "int" here instead to be compatible with the declaration +// in an old version of cxxabi.h, which is included indirectly. The declarations +// of __cxa_atexit and __cxa_finalize are removed from newer versions of +// cxxabi.h, so once libc++ is updated, this return type should be changed to +// "void". +int __cxa_finalize(void* dso); +} + TEST(__cxa_atexit, simple) { int counter = 0; - __cxxabiv1::__cxa_atexit([](void* arg) { ++*static_cast(arg); }, &counter, &counter); + __cxa_atexit([](void* arg) { ++*static_cast(arg); }, &counter, &counter); - __cxxabiv1::__cxa_finalize(&counter); + __cxa_finalize(&counter); ASSERT_EQ(counter, 1); // The handler won't be called twice. - __cxxabiv1::__cxa_finalize(&counter); + __cxa_finalize(&counter); ASSERT_EQ(counter, 1); } @@ -54,16 +65,16 @@ TEST(__cxa_atexit, order) { }; for (int i = 0; i < 500; ++i) { - __cxxabiv1::__cxa_atexit(append_to_actual, new int{i}, &handles[i % 2]); + __cxa_atexit(append_to_actual, new int{i}, &handles[i % 2]); } - __cxxabiv1::__cxa_finalize(&handles[0]); + __cxa_finalize(&handles[0]); for (int i = 500; i < 750; ++i) { - __cxxabiv1::__cxa_atexit(append_to_actual, new int{i}, &handles[1]); + __cxa_atexit(append_to_actual, new int{i}, &handles[1]); } - __cxxabiv1::__cxa_finalize(&handles[1]); + __cxa_finalize(&handles[1]); std::vector expected; for (int i = 498; i >= 0; i -= 2) expected.push_back(i); diff --git a/tests/__cxa_demangle_test.cpp b/tests/__cxa_demangle_test.cpp index 4628a61c0..d400619ad 100644 --- a/tests/__cxa_demangle_test.cpp +++ b/tests/__cxa_demangle_test.cpp @@ -29,11 +29,9 @@ #include #include -extern "C" char* __cxa_demangle(const char*, char*, size_t*, int*); - TEST(__cxa_demangle, cxa_demangle_fuzz_152588929) { #if defined(__aarch64__) - char* p = __cxa_demangle("1\006ILeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE", 0, 0, 0); + char* p = abi::__cxa_demangle("1\006ILeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE", 0, 0, 0); ASSERT_STREQ("\x6<-0x1.cecececececececececececececep+11983", p); free(p); #endif @@ -41,7 +39,7 @@ TEST(__cxa_demangle, cxa_demangle_fuzz_152588929) { TEST(__cxa_demangle, DISABLED_cxa_demangle_fuzz_167977068) { #if defined(__aarch64__) - char* p = __cxa_demangle("DTLeeeeeeeeeeeeeeeeeeeeeeeeeEEEEeeEEEE", 0, 0, 0); + char* p = abi::__cxa_demangle("DTLeeeeeeeeeeeeeeeeeeeeeeeeeEEEEeeEEEE", 0, 0, 0); ASSERT_EQ(nullptr, p) << p; free(p); #endif