blob: fcdbb48dfb7e5230c2afbb4e0e723ee3c0193ffa [file] [log] [blame] [edit]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <lib/ld/abi.h>
#include <lib/ld/tls.h>
#include "static-tls-get-addr.h"
namespace ld {
namespace {
#if defined(__x86_64__)
inline void* ThreadPointer() {
#ifdef __clang__
return *static_cast<void* [[clang::address_space(257)]]*>(nullptr);
#else
void* tp;
__asm__("mov %%fs:0,%0" : "=r"(tp));
return tp;
#endif
}
#else
inline void* ThreadPointer() { return __builtin_thread_pointer(); }
#endif
} // namespace
void* __tls_get_addr(TlsGetAddrGot& got) {
return StaticTlsGetAddr(got, _ld_abi.static_tls_offsets, ThreadPointer());
}
} // namespace ld