Fix bionic-unit-tests-static crash
The crash happens because for static executables call to dlopen
results in crash. This change moves dlopen() == nullptr check
from static variable to a functions so that the dlopen crash only
affects tests calling dlopen but not the whole executable.
Also make static tests report crashes to debugerd
Test: run bionic-unit-tests-static (for arm 32 and 64)
Bug: http://b/34129417
Change-Id: I7c4d8caf2a43250234fe24496b1c95eab572769f
diff --git a/tests/gtest_preinit_debuggerd.cpp b/tests/gtest_preinit_debuggerd.cpp
new file mode 100644
index 0000000..aac2e3f
--- /dev/null
+++ b/tests/gtest_preinit_debuggerd.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "debuggerd/client.h"
+
+void __gtest_preinit() {
+ debuggerd_init(nullptr);
+}
+
+__attribute__((section(".preinit_array"), __used__))
+void (*__local_gtest_preinit)(void) = __gtest_preinit;