From b71f2fcd46790dd63dd2688c208139ea26f027d4 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Mon, 17 Apr 2023 19:21:15 -0400 Subject: [PATCH] [Android] Use ELF TLS for Android API level 29+ Use ELF TLS by default instead of emulated TLS for Android build targets when the API level is >= 29. Android Q features full TLS support. See release notes (https://developer.android.com/preview/features#elf-tls) and implementation details (https://android.googlesource.com/platform/bionic/+/master/docs/elf-tls.md#Workaround_Use-Variant-2-on-arm32_arm64). Reviewed By: rprichard, danalbert Differential Revision: https://reviews.llvm.org/D147849 --- llvm/include/llvm/TargetParser/Triple.h | 6 ++++-- llvm/test/CodeGen/AArch64/emutls_generic.ll | 2 ++ llvm/test/CodeGen/X86/emutls-pic.ll | 1 + llvm/test/CodeGen/X86/emutls-pie.ll | 2 ++ llvm/test/CodeGen/X86/emutls_generic.ll | 2 ++ llvm/test/CodeGen/X86/fast-isel-emutls.ll | 2 ++ 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h index 1437861..ea16cc8 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -979,9 +979,11 @@ public: } /// Tests whether the target uses emulated TLS as default. + /// + /// Note: Android API level 29 (10) introduced ELF TLS. bool hasDefaultEmulatedTLS() const { - return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment() || - isOHOSFamily(); + return (isAndroid() && isAndroidVersionLT(29)) || isOSOpenBSD() || + isWindowsCygwinEnvironment() || isOHOSFamily(); } /// Tests whether the target uses -data-sections as default. diff --git a/llvm/test/CodeGen/AArch64/emutls_generic.ll b/llvm/test/CodeGen/AArch64/emutls_generic.ll index 00d7565..d4c1c06 100644 --- a/llvm/test/CodeGen/AArch64/emutls_generic.ll +++ b/llvm/test/CodeGen/AArch64/emutls_generic.ll @@ -18,6 +18,8 @@ ; aarch64-windows-gnu needs explicit -emulated-tls ; RUN: llc < %s -mtriple=aarch64-apple-darwin -O3 \ ; RUN: | FileCheck -check-prefix=NoEMU %s +; RUN: llc < %s -mtriple=aarch64-linux-android29 -O3 \ +; RUN: | FileCheck -check-prefix=NoEMU %s ; NoEMU-NOT: __emutls diff --git a/llvm/test/CodeGen/X86/emutls-pic.ll b/llvm/test/CodeGen/X86/emutls-pic.ll index f09c1cf..fc57d99 100644 --- a/llvm/test/CodeGen/X86/emutls-pic.ll +++ b/llvm/test/CodeGen/X86/emutls-pic.ll @@ -5,6 +5,7 @@ ; RUN: llc < %s -mtriple=i386-linux-gnu -relocation-model=pic | FileCheck -check-prefix=NoEMU %s ; RUN: llc < %s -mtriple=x86_64-linux-gnu -relocation-model=pic | FileCheck -check-prefix=NoEMU %s +; RUN: llc < %s -mtriple=x86_64-linux-android29 -relocation-model=pic | FileCheck -check-prefix=NoEMU %s ; RUN: llc < %s -mtriple=i386-linux-android -relocation-model=pic | FileCheck -check-prefix=X86 %s ; RUN: llc < %s -mtriple=x86_64-linux-android -relocation-model=pic | FileCheck -check-prefix=X64 %s ; RUN: llc < %s -mtriple=i386-linux-ohos -relocation-model=pic | FileCheck -check-prefix=X86 %s diff --git a/llvm/test/CodeGen/X86/emutls-pie.ll b/llvm/test/CodeGen/X86/emutls-pie.ll index 8563eb3..048c7fb 100644 --- a/llvm/test/CodeGen/X86/emutls-pie.ll +++ b/llvm/test/CodeGen/X86/emutls-pie.ll @@ -11,6 +11,8 @@ ; RUN: | FileCheck -check-prefix=NoEMU %s ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic \ ; RUN: | FileCheck -check-prefix=NoEMU %s +; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-android29 -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=NoEMU %s ; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-android -relocation-model=pic \ ; RUN: | FileCheck -check-prefix=X86 %s ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-android -relocation-model=pic \ diff --git a/llvm/test/CodeGen/X86/emutls_generic.ll b/llvm/test/CodeGen/X86/emutls_generic.ll index 3c3463c..997dd70 100644 --- a/llvm/test/CodeGen/X86/emutls_generic.ll +++ b/llvm/test/CodeGen/X86/emutls_generic.ll @@ -15,6 +15,8 @@ ; RUN: | FileCheck -check-prefix=X86_64 %s ; RUN: llc < %s -mtriple=i386-linux-gnu -relocation-model=pic \ ; RUN: | FileCheck -check-prefix=NoEMU %s +; RUN: llc < %s -mtriple=i686-linux-android29 -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=NoEMU %s ; NoEMU-NOT: __emutls diff --git a/llvm/test/CodeGen/X86/fast-isel-emutls.ll b/llvm/test/CodeGen/X86/fast-isel-emutls.ll index f0ca530..4ce00f5 100644 --- a/llvm/test/CodeGen/X86/fast-isel-emutls.ll +++ b/llvm/test/CodeGen/X86/fast-isel-emutls.ll @@ -1,6 +1,8 @@ ; RUN: llc < %s -emulated-tls -relocation-model=pic -mtriple=i686-unknown-linux-gnu -fast-isel | FileCheck %s ; RUN: llc < %s -relocation-model=pic -mtriple=i686-unknown-linux-gnu -fast-isel \ ; RUN: | FileCheck -check-prefix=NoEMU %s +; RUN: llc < %s -relocation-model=pic -mtriple=i686-linux-android29 -fast-isel \ +; RUN: | FileCheck -check-prefix=NoEMU %s ; PR3654 ; NoEMU-NOT: __emutls -- 2.7.4