diff options
-rw-r--r-- | tests/elftls_dl_test.cpp | 17 | ||||
-rw-r--r-- | tests/elftls_test.cpp | 10 |
2 files changed, 16 insertions, 11 deletions
diff --git a/tests/elftls_dl_test.cpp b/tests/elftls_dl_test.cpp index e908fb930..36bdc3b92 100644 --- a/tests/elftls_dl_test.cpp +++ b/tests/elftls_dl_test.cpp @@ -32,6 +32,7 @@ #include <thread> #include "gtest_globals.h" +#include "private/__get_tls.h" #include "utils.h" #if defined(__BIONIC__) @@ -114,11 +115,25 @@ TEST(elftls_dl, bump_local_vars) { }).join(); } +extern "C" int* missing_weak_tls_addr(); + +// The Bionic linker resolves a TPREL relocation to an unresolved weak TLS +// symbol to 0, which is added to the thread pointer. N.B.: A TPREL relocation +// in a static executable is resolved by the static linker instead, and static +// linker behavior varies (especially with bfd and gold). See +// https://bugs.llvm.org/show_bug.cgi?id=40570. +TEST(elftls_dl, tprel_missing_weak) { + ASSERT_EQ(static_cast<void*>(__get_tls()), missing_weak_tls_addr()); + std::thread([] { + ASSERT_EQ(static_cast<void*>(__get_tls()), missing_weak_tls_addr()); + }).join(); +} + // The behavior of accessing an unresolved weak TLS symbol using a dynamic TLS // relocation depends on which kind of implementation the target uses. With // TLSDESC, the result is NULL. With __tls_get_addr, the result is the // generation count (or maybe undefined behavior)? This test only tests TLSDESC. -TEST(elftls_dl, missing_weak) { +TEST(elftls_dl, tlsdesc_missing_weak) { #if defined(__aarch64__) void* lib = dlopen("libtest_elftls_dynamic.so", RTLD_LOCAL | RTLD_NOW); ASSERT_NE(nullptr, lib); diff --git a/tests/elftls_test.cpp b/tests/elftls_test.cpp index 2d83d7080..7c072b62f 100644 --- a/tests/elftls_test.cpp +++ b/tests/elftls_test.cpp @@ -30,8 +30,6 @@ #include <thread> -#include "private/__get_tls.h" - // Specify the LE access model explicitly. This file is compiled into the // bionic-unit-tests executable, but the compiler sees an -fpic object file // output into a static library, so it defaults to dynamic TLS accesses. @@ -64,17 +62,9 @@ TEST(elftls, shared_ie) { }).join(); } -extern "C" int* missing_weak_tls_addr(); extern "C" int bump_static_tls_var_1(); extern "C" int bump_static_tls_var_2(); -TEST(elftls, tprel_missing_weak) { - ASSERT_EQ(static_cast<void*>(__get_tls()), missing_weak_tls_addr()); - std::thread([] { - ASSERT_EQ(static_cast<void*>(__get_tls()), missing_weak_tls_addr()); - }).join(); -} - TEST(elftls, tprel_addend) { ASSERT_EQ(4, bump_static_tls_var_1()); ASSERT_EQ(8, bump_static_tls_var_2()); |