[libunwind] Fix testing with sanitizers enabled

When testing with sanitizers enabled, we need to link against a plethora
of system libraries. Using `-nodefaultlibs` like we used to breaks this,
and we would have to add all these system libraries manually, which is
not portable and error prone. Instead, stop using `-nodefaultlibs` so
that we get the libraries added by default by the compiler.

The only caveat with this approach is that we are now relying on the
fact that `-L <path-to-local-libunwind>` will cause the just built
libunwind to be selected before the system implementation (either of
libunwind or libgcc_s.so), which is somewhat fragile.

This patch also turns the 32 bit multilib build into a soft failure
since we are in the process of removing it anyway, see D114473 for
details. This patch is incompatible with the 32 bit multilib build
because Ubuntu does not provide a proper libstdc++ for 32 bits, and
that is required when running with sanitizers enabled.

Differential Revision: https://reviews.llvm.org/D114385

GitOrigin-RevId: ebfeeec4c4bcc4373e5d5dfaff7ee75959a7c931
diff --git a/test/configs/llvm-libunwind-shared.cfg.in b/test/configs/llvm-libunwind-shared.cfg.in
index 206c2b9..9de82e9 100644
--- a/test/configs/llvm-libunwind-shared.cfg.in
+++ b/test/configs/llvm-libunwind-shared.cfg.in
@@ -47,7 +47,7 @@
     '-nostdinc++ -I {}/include {}'.format('@LIBUNWIND_SOURCE_DIR@', ' '.join(compile_flags))
 ))
 config.substitutions.append(('%{link_flags}',
-    '-nodefaultlibs -L {0} -Wl,-rpath,{0} -lunwind -ldl -lc {1}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
+    '-L {0} -Wl,-rpath,{0} -lunwind -ldl {1}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
 ))
 config.substitutions.append(('%{exec}', ''))
 
diff --git a/test/configs/llvm-libunwind-static.cfg.in b/test/configs/llvm-libunwind-static.cfg.in
index dd292e7..9382ad3 100644
--- a/test/configs/llvm-libunwind-static.cfg.in
+++ b/test/configs/llvm-libunwind-static.cfg.in
@@ -49,7 +49,7 @@
     '-nostdinc++ -I {}/include {}'.format('@LIBUNWIND_SOURCE_DIR@', ' '.join(compile_flags))
 ))
 config.substitutions.append(('%{link_flags}',
-    '-nodefaultlibs {}/libunwind.a -ldl -lc {}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
+    '{}/libunwind.a -ldl {}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
 ))
 config.substitutions.append(('%{exec}', ''))
 
diff --git a/test/forceunwind.pass.cpp b/test/forceunwind.pass.cpp
index 1206632..4666972 100644
--- a/test/forceunwind.pass.cpp
+++ b/test/forceunwind.pass.cpp
@@ -9,9 +9,6 @@
 
 // REQUIRES: linux
 
-// TODO: Investigate these failures
-// XFAIL: asan, tsan, ubsan
-
 // Basic test for _Unwind_ForcedUnwind.
 // See libcxxabi/test/forced_unwind* tests too.
 
diff --git a/test/frameheadercache_test.pass.cpp b/test/frameheadercache_test.pass.cpp
index a50b2b6..9abff5e 100644
--- a/test/frameheadercache_test.pass.cpp
+++ b/test/frameheadercache_test.pass.cpp
@@ -1,6 +1,3 @@
-// TODO: Investigate these failures
-// XFAIL: asan, tsan, ubsan
-
 // The other libunwind tests don't test internal interfaces, so the include path
 // is a little wonky.
 #include "../src/config.h"
diff --git a/test/libunwind_01.pass.cpp b/test/libunwind_01.pass.cpp
index 6c1e1bb..e573745 100644
--- a/test/libunwind_01.pass.cpp
+++ b/test/libunwind_01.pass.cpp
@@ -1,6 +1,3 @@
-// TODO: Investigate these failures
-// XFAIL: asan, tsan, ubsan
-
 // TODO: Investigate these failures on x86_64 macOS back deployment
 // UNSUPPORTED: target=x86_64-apple-darwin{{.+}}
 
diff --git a/test/libunwind_02.pass.cpp b/test/libunwind_02.pass.cpp
index 6eea7a3..b188fad 100644
--- a/test/libunwind_02.pass.cpp
+++ b/test/libunwind_02.pass.cpp
@@ -1,6 +1,3 @@
-// TODO: Investigate these failures
-// XFAIL: asan, tsan, ubsan
-
 #include <assert.h>
 #include <stdlib.h>
 #include <unwind.h>
diff --git a/test/remember_state_leak.pass.sh.s b/test/remember_state_leak.pass.sh.s
index b98a91d..df1512d 100644
--- a/test/remember_state_leak.pass.sh.s
+++ b/test/remember_state_leak.pass.sh.s
@@ -2,9 +2,6 @@
 # RUN: %{build}
 # RUN: %{run}
 
-// TODO: Investigate these failures
-// XFAIL: asan, tsan, ubsan
-
 // TODO: Investigate this failure
 // XFAIL: 32bits-on-64bits
 
diff --git a/test/signal_frame.pass.cpp b/test/signal_frame.pass.cpp
index 513eef5..85a883b 100644
--- a/test/signal_frame.pass.cpp
+++ b/test/signal_frame.pass.cpp
@@ -9,9 +9,6 @@
 
 // Ensure that functions marked as signal frames are reported as such.
 
-// TODO: Investigate these failures
-// XFAIL: asan, tsan, ubsan
-
 // TODO: Investigate this failure on macOS
 // XFAIL: target={{.+}}-apple-darwin{{.+}}
 
diff --git a/test/signal_unwind.pass.cpp b/test/signal_unwind.pass.cpp
index 12d9589..c16adeb 100644
--- a/test/signal_unwind.pass.cpp
+++ b/test/signal_unwind.pass.cpp
@@ -10,9 +10,6 @@
 // Ensure that the unwinder can cope with the signal handler.
 // REQUIRES: linux && (target={{aarch64-.+}} || target={{x86_64-.+}})
 
-// TODO: Investigate these failures
-// XFAIL: asan, tsan, ubsan
-
 #include <assert.h>
 #include <dlfcn.h>
 #include <signal.h>
diff --git a/test/unw_getcontext.pass.cpp b/test/unw_getcontext.pass.cpp
index a02c8e5..a1f2bae 100644
--- a/test/unw_getcontext.pass.cpp
+++ b/test/unw_getcontext.pass.cpp
@@ -1,6 +1,3 @@
-// TODO: Investigate these failures
-// XFAIL: asan, tsan, ubsan
-
 #include <assert.h>
 #include <libunwind.h>
 
diff --git a/test/unwind_leaffunction.pass.cpp b/test/unwind_leaffunction.pass.cpp
index 4037455..2a6d831 100644
--- a/test/unwind_leaffunction.pass.cpp
+++ b/test/unwind_leaffunction.pass.cpp
@@ -10,9 +10,6 @@
 // Ensure that leaf function can be unwund.
 // REQUIRES: linux && (target={{aarch64-.+}} || target={{x86_64-.+}})
 
-// TODO: Investigate these failures
-// XFAIL: asan, tsan, ubsan
-
 #include <assert.h>
 #include <dlfcn.h>
 #include <signal.h>
@@ -41,14 +38,12 @@
   _Exit(-1);
 }
 
-int* faultyPointer = NULL;
-
 __attribute__((noinline)) void crashing_leaf_func(void) {
-  *faultyPointer = 0;
+  raise(SIGSEGV);
 }
 
 int main(int, char**) {
   signal(SIGSEGV, signal_handler);
   crashing_leaf_func();
   return -2;
-}
\ No newline at end of file
+}