Skip to content

Commit a94ecd3

Browse files
committed
[Libunwind] Fix msan-related errors
Sometimes msan seems to fail proving that variable is (un)initialized and emits false-positives. Such false positives can lead to stack overflow (libc++ CI error) So add explicit initialization of all variables that msan thinks are used without initialization
1 parent f90ca87 commit a94ecd3

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

libunwind/src/AddressSpace.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,9 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
621621
}
622622
// Try to find the unwind info using `dl_find_object`
623623
dl_find_object findResult;
624+
#if __has_feature(memory_sanitizer)
625+
__builtin_memset(&findResult, 0, sizeof(dl_find_object));
626+
#endif
624627
if (dlFindObject && dlFindObject((void *)targetAddr, &findResult) == 0) {
625628
if (findResult.dlfo_eh_frame == nullptr) {
626629
// Found an entry for `targetAddr`, but there is no unwind info.

libunwind/src/UnwindLevel1-gcc-ext.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ _LIBUNWIND_EXPORT _Unwind_Reason_Code
133133
_Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {
134134
unw_cursor_t cursor;
135135
unw_context_t uc;
136+
#if __has_feature(memory_sanitizer)
137+
__builtin_memset(&cursor, 0, sizeof(cursor));
138+
__builtin_memset(&uc, 0, sizeof(uc));
139+
#endif
136140
__unw_getcontext(&uc);
137141
__unw_init_local(&cursor, &uc);
138142

libunwind/src/UnwindLevel1.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ _Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
507507
(void *)exception_object, (void *)(uintptr_t)stop);
508508
unw_context_t uc;
509509
unw_cursor_t cursor;
510+
#if __has_feature(memory_sanitizer)
511+
__builtin_memset(&uc, 0, sizeof(uc));
512+
__builtin_memset(&cursor, 0, sizeof(cursor));
513+
#endif
510514
__unw_getcontext(&uc);
511515

512516
// Mark that this is a forced unwind, so _Unwind_Resume() can do

libunwind/test/libunwind_01.pass.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
#include <string.h>
1717

1818
void backtrace(int lower_bound) {
19-
unw_context_t context;
19+
unw_context_t context = {0};
2020
unw_getcontext(&context);
2121

22-
unw_cursor_t cursor;
22+
unw_cursor_t cursor = {0};
2323
unw_init_local(&cursor, &context);
2424

2525
char buffer[1024];
@@ -64,10 +64,10 @@ __attribute__((noinline)) void test3(int i, int j, int k) {
6464
}
6565

6666
void test_no_info() {
67-
unw_context_t context;
67+
unw_context_t context = {0};
6868
unw_getcontext(&context);
6969

70-
unw_cursor_t cursor;
70+
unw_cursor_t cursor = {0};
7171
unw_init_local(&cursor, &context);
7272

7373
unw_proc_info_t info;
@@ -84,10 +84,10 @@ void test_no_info() {
8484
}
8585

8686
void test_reg_names() {
87-
unw_context_t context;
87+
unw_context_t context = {0};
8888
unw_getcontext(&context);
8989

90-
unw_cursor_t cursor;
90+
unw_cursor_t cursor = {0};
9191
unw_init_local(&cursor, &context);
9292

9393
int max_reg_num = -100;
@@ -110,7 +110,7 @@ void test_reg_names() {
110110

111111
#if defined(__x86_64__)
112112
void test_reg_get_set() {
113-
unw_context_t context;
113+
unw_context_t context = {0};
114114
unw_getcontext(&context);
115115

116116
unw_cursor_t cursor;
@@ -131,10 +131,10 @@ void test_reg_get_set() {
131131
}
132132

133133
void test_fpreg_get_set() {
134-
unw_context_t context;
134+
unw_context_t context = {0};
135135
unw_getcontext(&context);
136136

137-
unw_cursor_t cursor;
137+
unw_cursor_t cursor = {0};
138138
unw_init_local(&cursor, &context);
139139

140140
// get/set is not implemented for x86_64 fpregs.

libunwind/test/signal_frame.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
void test() {
3131
asm(".cfi_signal_frame");
32-
unw_cursor_t cursor;
33-
unw_context_t uc;
32+
unw_cursor_t cursor = {0};
33+
unw_context_t uc = {0};
3434
unw_getcontext(&uc);
3535
unw_init_local(&cursor, &uc);
3636
assert(unw_step(&cursor) > 0);

libunwind/test/unw_resume.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <libunwind.h>
1414

1515
__attribute__((noinline)) void test_unw_resume() {
16-
unw_context_t context;
17-
unw_cursor_t cursor;
16+
unw_context_t context = {0};
17+
unw_cursor_t cursor = {0};
1818

1919
unw_getcontext(&context);
2020
unw_init_local(&cursor, &context);

0 commit comments

Comments
 (0)