Avoid a dlopen abort on an invalid TLS alignment
If the alignment of a TLS segment in a shared object is invalid, return
an error through dlerror() rather than aborting the process.
Bug: http://b/78026329
Test: bionic unit tests
Change-Id: I60e589ddd8ca897f485d55af089f08bd3ff5b1fa
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 38f15c3..4aac39b 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -3078,7 +3078,14 @@
#endif
TlsSegment tls_segment;
- if (__bionic_get_tls_segment(phdr, phnum, load_bias, get_realpath(), &tls_segment)) {
+ if (__bionic_get_tls_segment(phdr, phnum, load_bias, &tls_segment)) {
+ if (!__bionic_check_tls_alignment(&tls_segment.alignment)) {
+ if (!relocating_linker) {
+ DL_ERR("TLS segment alignment in \"%s\" is not a power of 2: %zu",
+ get_realpath(), tls_segment.alignment);
+ }
+ return false;
+ }
tls_ = std::make_unique<soinfo_tls>();
tls_->segment = tls_segment;
}