diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 5c9368ad0ed..4309627daab 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -267,7 +267,11 @@ if (UNIX) set(OS_SRCS ${OS_SRCS} unix/memcache.c) set(OS_SRCS ${OS_SRCS} unix/module_elf.c) set(OS_SRCS ${OS_SRCS} unix/ksynch_linux.c) - set(OS_SRCS ${OS_SRCS} unix/tls_linux_${ARCH_NAME}.c) + if (ARM OR AARCH64) + set(OS_SRCS ${OS_SRCS} unix/tls_linux_aarchxx.c) + else () + set(OS_SRCS ${OS_SRCS} unix/tls_linux_${ARCH_NAME}.c) + endif () set(OS_SRCS ${OS_SRCS} unix/signal_linux.c) set(OS_SRCS ${OS_SRCS} unix/signal_linux_${ARCH_NAME}.c) set(OS_SRCS ${OS_SRCS} unix/native_elf.c) diff --git a/core/unix/tls_linux_aarch64.c b/core/unix/tls_linux_aarch64.c deleted file mode 100644 index fb3d3a7c349..00000000000 --- a/core/unix/tls_linux_aarch64.c +++ /dev/null @@ -1,70 +0,0 @@ -/* ********************************************************** - * Copyright (c) 2016 ARM Limited. All rights reserved. - * **********************************************************/ - -/* - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of ARM Limited nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL ARM LIMITED OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - */ - -/*************************************************************************** - * tls_linux_aarch64.c - thread-local storage for arm64 Linux - */ - -#include /* offsetof */ -#include "../globals.h" -#include "tls.h" - -#ifndef LINUX -# error Linux-only -#endif - -#ifndef AARCH64 -# error AArch64-only -#endif - -#ifndef CLIENT_INTERFACE -# error CLIENT_INTERFACE build only for TLS mangling on AArch64 -#endif - -byte ** -get_dr_tls_base_addr(void) -{ - ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569 */ - return NULL; -} - -void -tls_thread_init(os_local_state_t *os_tls, byte *segment) -{ - ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569 */ -} - -void -tls_thread_free(tls_type_t tls_type, int index) -{ - ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569 */ -} diff --git a/core/unix/tls_linux_arm.c b/core/unix/tls_linux_aarchxx.c similarity index 89% rename from core/unix/tls_linux_arm.c rename to core/unix/tls_linux_aarchxx.c index a45a5b8ac40..7835fcd8c2a 100644 --- a/core/unix/tls_linux_arm.c +++ b/core/unix/tls_linux_aarchxx.c @@ -31,24 +31,26 @@ */ /* - * tls_linux_arm.c - TLS support on ARM + * tls_linux_arm.c - thread-local storage for arm and arm64 Linux */ #include /* offsetof */ #include "../globals.h" #include "tls.h" -#include "include/syscall.h" +#ifndef AARCH64 +# include "include/syscall.h" +#endif #ifndef LINUX # error Linux-only #endif -#ifndef ARM -# error ARM-only +#if !(defined(ARM) || defined(AARCH64)) +# error ARM/AArch64-only #endif #ifndef CLIENT_INTERFACE -# error CLIENT_INTERFACE build only for TLS mangling on ARM +# error CLIENT_INTERFACE build only for TLS mangling on ARM/AArch64 #endif byte ** @@ -67,7 +69,12 @@ tls_thread_init(os_local_state_t *os_tls, byte *segment) LOG(GLOBAL, LOG_THREADS, 2, "tls_thread_init: cur priv lib tls base is "PFX"\n", os_tls->os_seg_info.priv_lib_tls_base); +#ifdef AARCH64 + asm volatile("msr tpidr_el0, %0" : : + "r"(os_tls->os_seg_info.priv_lib_tls_base)); +#else dynamorio_syscall(SYS_set_tls, 1, os_tls->os_seg_info.priv_lib_tls_base); +#endif ASSERT(get_segment_base(TLS_REG_LIB) == os_tls->os_seg_info.priv_lib_tls_base); ASSERT(*get_dr_tls_base_addr() == NULL); *get_dr_tls_base_addr() = segment;