Skip to content

Commit 5c3de71

Browse files
committed
Document the dclose/thread locals with non-trivial destructors problem.
Bug: android/ndk#360 Test: N/A Change-Id: I964a6c9abd1ae65d74c6aee1c842b2f3d24b5556
1 parent 88c5ddb commit 5c3de71

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

android-changes-for-ndk-developers.md

+19
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,22 @@ adb shell setprop debug.ld.all dlerror,dlopen
376376
```
377377

378378
enables logging of all errors and dlopen calls
379+
380+
## dlclose interacts badly with thread local variables with non-trivial destructors
381+
382+
Android allows `dlclose` to unload a library even if there are still
383+
thread-local variables with non-trivial destructors. This leads to
384+
crashes when a thread exits and attempts to call the destructor, the
385+
code for which has been unloaded (as in [issue 360]).
386+
387+
[issue 360]: https://github.com/android-ndk/ndk/issues/360
388+
389+
Not calling `dlclose` or ensuring that your library has `RTLD_NODELETE`
390+
set (so that calls to `dlclose` don't actually unload the library)
391+
are possible workarounds.
392+
393+
| | Pre-M | M+ |
394+
| ----------------- | -------------------------- | ------- |
395+
| No workaround | Works for static STL | Broken |
396+
| `-Wl,-z,nodelete` | Works for static STL | Works |
397+
| No `dlclose` | Works | Works |

0 commit comments

Comments
 (0)