Add a new option to conserve stack space.

There are a few places where large data structures are put on the stack.
This causes failures when trying to dump threads using a smaller stack so
use an option to conserve stack space.

Tested by running these commands:

autoreconf -i
./configure

Verify that config.h has CONSERVE_STACK undefined since this is a host build.

autoreconf -i
android/conf_arm.sh

Verify that config.h has CONSERVE_STACK defined.

Built libunwind with both CONSERVE_STACK define and undefined.

Bug: 8410085
Change-Id: I9ec4dee656475650883176d8801430b7e312153c
diff --git a/acinclude.m4 b/acinclude.m4
index 497f7c2..b536a1f 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -30,3 +30,28 @@
 #
 #  AC_CHECK_LIB(atomic_ops, main)
 ])
+
+# ANDROID support update.
+AC_DEFUN([CHECK_ANDROID],
+[dnl Check whether the system has __ANDROID__ defined.
+if test "x$enable_conserve_stack" != xno; then
+  AC_CACHE_CHECK([for __ANDROID__], ac_cv_android,
+         [cat > conftest.c <<\EOF
+  #if !defined(__ANDROID__)
+    value = fail
+  #endif
+EOF
+  if AC_TRY_COMMAND([${CC-cc} $CFLAGS -c conftest.c >&AS_MESSAGE_LOG_FD]); then
+    ac_cv_android=yes
+  else
+    ac_cv_android=no
+  fi
+  rm -f conftest*])
+  if test "$ac_cv_android" = yes; then
+    AC_DEFINE([CONSERVE_STACK], [],
+              [Allocate large structures rather than place them on the stack.])
+  fi
+else
+  ac_cv_android=no
+fi])
+# End of ANDROID update.