Record TLS modules and layout static TLS memory
Bug: http://b/78026329
Test: bionic unit tests
Change-Id: Ibf1bf5ec864c7830e4cd1cb882842b644e6182ae
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 1f259e1..38f15c3 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -65,8 +65,10 @@
#include "linker_phdr.h"
#include "linker_relocs.h"
#include "linker_reloc_iterators.h"
+#include "linker_tls.h"
#include "linker_utils.h"
+#include "private/bionic_globals.h"
#include "android-base/macros.h"
#include "android-base/strings.h"
#include "android-base/stringprintf.h"
@@ -1652,6 +1654,7 @@
if (!si->is_linked() && !si->prelink_image()) {
return false;
}
+ register_soinfo_tls(si);
}
// Step 4: Construct the global group. Note: DF_1_GLOBAL bit of a library is
@@ -1887,6 +1890,7 @@
si->get_realpath(),
si);
notify_gdb_of_unload(si);
+ unregister_soinfo_tls(si);
get_cfi_shadow()->BeforeUnload(si);
soinfo_free(si);
}
@@ -3073,6 +3077,12 @@
&ARM_exidx, &ARM_exidx_count);
#endif
+ TlsSegment tls_segment;
+ if (__bionic_get_tls_segment(phdr, phnum, load_bias, get_realpath(), &tls_segment)) {
+ tls_ = std::make_unique<soinfo_tls>();
+ tls_->segment = tls_segment;
+ }
+
// Extract useful information from dynamic section.
// Note that: "Except for the DT_NULL element at the end of the array,
// and the relative order of DT_NEEDED elements, entries may appear in any order."