diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c..8a337dac9f4f5 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -621,6 +621,9 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, } // Try to find the unwind info using `dl_find_object` dl_find_object findResult; +#if __has_feature(memory_sanitizer) + __builtin_memset(&findResult, 0, sizeof(dl_find_object)); +#endif if (dlFindObject && dlFindObject((void *)targetAddr, &findResult) == 0) { if (findResult.dlfo_eh_frame == nullptr) { // Found an entry for `targetAddr`, but there is no unwind info. diff --git a/libunwind/src/UnwindLevel1-gcc-ext.c b/libunwind/src/UnwindLevel1-gcc-ext.c index 32c872ffade1f..c906ce263965c 100644 --- a/libunwind/src/UnwindLevel1-gcc-ext.c +++ b/libunwind/src/UnwindLevel1-gcc-ext.c @@ -133,6 +133,10 @@ _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) { unw_cursor_t cursor; unw_context_t uc; +#if __has_feature(memory_sanitizer) + __builtin_memset(&cursor, 0, sizeof(cursor)); + __builtin_memset(&uc, 0, sizeof(uc)); +#endif __unw_getcontext(&uc); __unw_init_local(&cursor, &uc); diff --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c index 7e785f4d31e71..e63f22906f5d6 100644 --- a/libunwind/src/UnwindLevel1.c +++ b/libunwind/src/UnwindLevel1.c @@ -507,6 +507,10 @@ _Unwind_ForcedUnwind(_Unwind_Exception *exception_object, (void *)exception_object, (void *)(uintptr_t)stop); unw_context_t uc; unw_cursor_t cursor; +#if __has_feature(memory_sanitizer) + __builtin_memset(&uc, 0, sizeof(uc)); + __builtin_memset(&cursor, 0, sizeof(cursor)); +#endif __unw_getcontext(&uc); // Mark that this is a forced unwind, so _Unwind_Resume() can do diff --git a/libunwind/test/forceunwind.pass.cpp b/libunwind/test/forceunwind.pass.cpp index 344034e1ea5f5..e8333eb74a979 100644 --- a/libunwind/test/forceunwind.pass.cpp +++ b/libunwind/test/forceunwind.pass.cpp @@ -9,9 +9,6 @@ // REQUIRES: linux -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - // Basic test for _Unwind_ForcedUnwind. // See libcxxabi/test/forced_unwind* tests too. diff --git a/libunwind/test/libunwind_01.pass.cpp b/libunwind/test/libunwind_01.pass.cpp index 838df6b589720..d5fd7fbbf05f7 100644 --- a/libunwind/test/libunwind_01.pass.cpp +++ b/libunwind/test/libunwind_01.pass.cpp @@ -10,19 +10,16 @@ // TODO: Investigate this failure on x86_64 macOS back deployment // XFAIL: stdlib=system && target=x86_64-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0|12.0}} -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - #include #include #include #include void backtrace(int lower_bound) { - unw_context_t context; + unw_context_t context = {0}; unw_getcontext(&context); - unw_cursor_t cursor; + unw_cursor_t cursor = {0}; unw_init_local(&cursor, &context); char buffer[1024]; @@ -67,10 +64,10 @@ __attribute__((noinline)) void test3(int i, int j, int k) { } void test_no_info() { - unw_context_t context; + unw_context_t context = {0}; unw_getcontext(&context); - unw_cursor_t cursor; + unw_cursor_t cursor = {0}; unw_init_local(&cursor, &context); unw_proc_info_t info; @@ -87,10 +84,10 @@ void test_no_info() { } void test_reg_names() { - unw_context_t context; + unw_context_t context = {0}; unw_getcontext(&context); - unw_cursor_t cursor; + unw_cursor_t cursor = {0}; unw_init_local(&cursor, &context); int max_reg_num = -100; @@ -113,7 +110,7 @@ void test_reg_names() { #if defined(__x86_64__) void test_reg_get_set() { - unw_context_t context; + unw_context_t context = {0}; unw_getcontext(&context); unw_cursor_t cursor; @@ -134,10 +131,10 @@ void test_reg_get_set() { } void test_fpreg_get_set() { - unw_context_t context; + unw_context_t context = {0}; unw_getcontext(&context); - unw_cursor_t cursor; + unw_cursor_t cursor = {0}; unw_init_local(&cursor, &context); // get/set is not implemented for x86_64 fpregs. diff --git a/libunwind/test/libunwind_02.pass.cpp b/libunwind/test/libunwind_02.pass.cpp index 9fd8e5d7159c9..5f2d2b43bddc1 100644 --- a/libunwind/test/libunwind_02.pass.cpp +++ b/libunwind/test/libunwind_02.pass.cpp @@ -7,9 +7,6 @@ // //===----------------------------------------------------------------------===// -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - // This test fails on older llvm, when built with picolibc. // XFAIL: clang-16 && LIBCXX-PICOLIBC-FIXME diff --git a/libunwind/test/signal_frame.pass.cpp b/libunwind/test/signal_frame.pass.cpp index 004029cfe1e90..2882b3fbf264b 100644 --- a/libunwind/test/signal_frame.pass.cpp +++ b/libunwind/test/signal_frame.pass.cpp @@ -12,9 +12,6 @@ // TODO: Investigate this failure on Apple // XFAIL: target={{.+}}-apple-{{.+}} -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - // UNSUPPORTED: libunwind-arm-ehabi // The AIX assembler does not support CFI directives, which @@ -32,8 +29,8 @@ void test() { asm(".cfi_signal_frame"); - unw_cursor_t cursor; - unw_context_t uc; + unw_cursor_t cursor = {0}; + unw_context_t uc = {0}; unw_getcontext(&uc); unw_init_local(&cursor, &uc); assert(unw_step(&cursor) > 0); diff --git a/libunwind/test/signal_unwind.pass.cpp b/libunwind/test/signal_unwind.pass.cpp index 1c1566415a4d4..8ba0c8b2859ac 100644 --- a/libunwind/test/signal_unwind.pass.cpp +++ b/libunwind/test/signal_unwind.pass.cpp @@ -10,9 +10,6 @@ // Ensure that the unwinder can cope with the signal handler. // REQUIRES: target={{(aarch64|riscv64|s390x|x86_64)-.+linux.*}} -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - // Note: this test fails on musl because: // // (a) musl disables emission of unwind information for its build, and diff --git a/libunwind/test/unw_resume.pass.cpp b/libunwind/test/unw_resume.pass.cpp index 2b7470b5cad0e..45f34ac69ca09 100644 --- a/libunwind/test/unw_resume.pass.cpp +++ b/libunwind/test/unw_resume.pass.cpp @@ -10,14 +10,11 @@ // Ensure that unw_resume() resumes execution at the stack frame identified by // cursor. -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - #include __attribute__((noinline)) void test_unw_resume() { - unw_context_t context; - unw_cursor_t cursor; + unw_context_t context = {0}; + unw_cursor_t cursor = {0}; unw_getcontext(&context); unw_init_local(&cursor, &context); diff --git a/libunwind/test/unwind_leaffunction.pass.cpp b/libunwind/test/unwind_leaffunction.pass.cpp index 98de7dc43260c..4259406cc493d 100644 --- a/libunwind/test/unwind_leaffunction.pass.cpp +++ b/libunwind/test/unwind_leaffunction.pass.cpp @@ -10,9 +10,6 @@ // Ensure that leaf function can be unwund. // REQUIRES: target={{(aarch64|riscv64|s390x|x86_64)-.+linux.*}} -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - // Note: this test fails on musl because: // // (a) musl disables emission of unwind information for its build, and