aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2020-04-13 13:57:27 -0700
committerDan Albert <danalbert@google.com>2020-04-13 14:09:37 -0700
commita576392e505f3a91c6a0119231db08d9140913a2 (patch)
tree802322ab00664eeb61f32ca64c1960772e1f68e3
parent28df01568e9323aa7b33986b0e5647dc5ab8b908 (diff)
downloadndk-a576392e505f3a91c6a0119231db08d9140913a2.tar.gz
Add test and changelog note for #1200.
The fix itself is in libc++abi. Test: This is the test Bug: https://github.com/android/ndk/issues/1200 Change-Id: If1c75e80b051e2a2e9316745e671a4e81ada6fbf
-rw-r--r--docs/changelogs/Changelog-r22.md4
-rw-r--r--tests/device/thread_local_dlclose/CMakeLists.txt11
-rw-r--r--tests/device/thread_local_dlclose/jni/Android.mk13
-rw-r--r--tests/device/thread_local_dlclose/jni/Application.mk2
-rw-r--r--tests/device/thread_local_dlclose/jni/foo.cpp15
-rw-r--r--tests/device/thread_local_dlclose/jni/libtestlib.map.txt6
-rw-r--r--tests/device/thread_local_dlclose/jni/testlib.cpp9
7 files changed, 60 insertions, 0 deletions
diff --git a/docs/changelogs/Changelog-r22.md b/docs/changelogs/Changelog-r22.md
index c43ba5a39..d46f68733 100644
--- a/docs/changelogs/Changelog-r22.md
+++ b/docs/changelogs/Changelog-r22.md
@@ -40,7 +40,11 @@ For Android Studio issues, follow the docs on the [Android Studio site].
r19, file a bug with your build system maintainer. See the [Build System
Maintainers Guide] for information on using the NDK in your own build system.
+* [Issue 1200]: Fixed an issue with using `dlclose` with libraries using
+ `thread_local` with non-trivial destructors and the static libc++.
+
[Build System Maintainers Guide]: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md
+[Issue 1200]: https://github.com/android/ndk/issues/1200
## Known Issues
diff --git a/tests/device/thread_local_dlclose/CMakeLists.txt b/tests/device/thread_local_dlclose/CMakeLists.txt
new file mode 100644
index 000000000..12bba47ff
--- /dev/null
+++ b/tests/device/thread_local_dlclose/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.17.0)
+project(thread_local_dlclose)
+
+add_library(testlib SHARED jni/testlib.cpp)
+
+target_link_options(testlib
+ PRIVATE
+ -Wl,--version-script,${CMAKE_SOURCE_DIR}/jni/libtestlib.map.txt
+)
+
+add_executable(foo jni/foo.cpp)
diff --git a/tests/device/thread_local_dlclose/jni/Android.mk b/tests/device/thread_local_dlclose/jni/Android.mk
new file mode 100644
index 000000000..affe2e9c4
--- /dev/null
+++ b/tests/device/thread_local_dlclose/jni/Android.mk
@@ -0,0 +1,13 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := testlib
+LOCAL_SRC_FILES := testlib.cpp
+# Using a version script to ensure that the static libc++ is not re-exposed.
+LOCAL_LDFLAGS := -Wl,--version-script,$(LOCAL_PATH)/libtestlib.map.txt
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := foo
+LOCAL_SRC_FILES := foo.cpp
+include $(BUILD_EXECUTABLE)
diff --git a/tests/device/thread_local_dlclose/jni/Application.mk b/tests/device/thread_local_dlclose/jni/Application.mk
new file mode 100644
index 000000000..1fc3c3dee
--- /dev/null
+++ b/tests/device/thread_local_dlclose/jni/Application.mk
@@ -0,0 +1,2 @@
+APP_STL := c++_static
+APP_CPPFLAGS := -fexceptions -frtti
diff --git a/tests/device/thread_local_dlclose/jni/foo.cpp b/tests/device/thread_local_dlclose/jni/foo.cpp
new file mode 100644
index 000000000..cdc0e7e7b
--- /dev/null
+++ b/tests/device/thread_local_dlclose/jni/foo.cpp
@@ -0,0 +1,15 @@
+#include <dlfcn.h>
+
+#include <thread>
+
+void myThread() {
+ void* lib = dlopen("./libtestlib.so", RTLD_LAZY);
+ auto func = reinterpret_cast<void (*)()>(dlsym(lib, "func"));
+ func();
+ dlclose(lib);
+}
+
+int main(int, char**) {
+ std::thread t(myThread);
+ t.join();
+}
diff --git a/tests/device/thread_local_dlclose/jni/libtestlib.map.txt b/tests/device/thread_local_dlclose/jni/libtestlib.map.txt
new file mode 100644
index 000000000..775be2167
--- /dev/null
+++ b/tests/device/thread_local_dlclose/jni/libtestlib.map.txt
@@ -0,0 +1,6 @@
+VERSION_1 {
+ global:
+ func;
+ local:
+ *;
+};
diff --git a/tests/device/thread_local_dlclose/jni/testlib.cpp b/tests/device/thread_local_dlclose/jni/testlib.cpp
new file mode 100644
index 000000000..844c80fa9
--- /dev/null
+++ b/tests/device/thread_local_dlclose/jni/testlib.cpp
@@ -0,0 +1,9 @@
+#include <iostream>
+
+extern "C" void func() {
+ try {
+ throw 0;
+ } catch (...) {
+ std::cerr << "Caught" << std::endl;
+ }
+}