// 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.
// This variable will be zero-initialized (.tbss)
__attribute__((tls_model("local-exec"))) static __thread int tlsvar_le_zero;
// This variable will have an initializer (.tdata)
__attribute__((tls_model("local-exec"))) static __thread int tlsvar_le_init = 10;
// Access libtest_elftls_shared_var's TLS variable using an IE access.
__attribute__((tls_model("initial-exec"))) extern"C" __thread int elftls_shared_var;
TEST(elftls, basic_le) { // Check the variables on the main thread.
ASSERT_EQ(11, ++tlsvar_le_init);
ASSERT_EQ(1, ++tlsvar_le_zero);
// Check variables on a new thread.
std::thread([] {
ASSERT_EQ(11, ++tlsvar_le_init);
ASSERT_EQ(1, ++tlsvar_le_zero);
}).join();
}
// Because this C++ source file is built with -fpic, the compiler will access // this variable using a GD model. Typically, the static linker will relax the // GD to LE, but the arm32 linker doesn't do TLS relaxations, so we can test // calling __tls_get_addr in a static executable. The static linker knows that // the main executable's TlsIndex::module_id is 1 and writes that into the GOT.
__thread int tlsvar_general = 30;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.