diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.h b/clang/lib/Driver/ToolChains/Arch/ARM.h --- a/clang/lib/Driver/ToolChains/Arch/ARM.h +++ b/clang/lib/Driver/ToolChains/Arch/ARM.h @@ -53,6 +53,7 @@ const llvm::opt::ArgList &Args); void setFloatABIInTriple(const Driver &D, const llvm::opt::ArgList &Args, llvm::Triple &triple); +bool isHardTPSupported(const llvm::Triple &Triple); ReadTPMode getReadTPMode(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &Triple); void setArchNameInTriple(const Driver &D, const llvm::opt::ArgList &Args, diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -147,6 +147,16 @@ T.getOS() == llvm::Triple::UnknownOS || isARMMProfile(T); } +// We follow GCC and support when the backend has support for the MRC/MCR +// instructions that are used to set the hard thread pointer ("CP15 C13 +// Thread id"). +bool arm::isHardTPSupported(const llvm::Triple &Triple) { + int Ver = getARMSubArchVersionNumber(Triple); + llvm::ARM::ArchKind AK = llvm::ARM::parseArch(Triple.getArchName()); + return Triple.isARM() || AK == llvm::ARM::ArchKind::ARMV6T2 || + (Ver >= 7 && AK != llvm::ARM::ArchKind::ARMV8MBaseline); +} + // Select mode for reading thread pointer (-mtp=soft/cp15). arm::ReadTPMode arm::getReadTPMode(const Driver &D, const ArgList &Args, const llvm::Triple &Triple) { @@ -156,10 +166,7 @@ .Case("cp15", ReadTPMode::Cp15) .Case("soft", ReadTPMode::Soft) .Default(ReadTPMode::Invalid); - if (ThreadPointer == ReadTPMode::Cp15 && - getARMSubArchVersionNumber(Triple) < 7 && - llvm::ARM::parseArch(Triple.getArchName()) != - llvm::ARM::ArchKind::ARMV6T2) { + if (ThreadPointer == ReadTPMode::Cp15 && !isHardTPSupported(Triple)) { D.Diag(diag::err_target_unsupported_tp_hard) << Triple.getArchName(); return ReadTPMode::Invalid; } @@ -430,7 +437,6 @@ bool KernelOrKext = Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext); arm::FloatABI ABI = arm::getARMFloatABI(D, Triple, Args); - arm::ReadTPMode ThreadPointer = arm::getReadTPMode(D, Args, Triple); llvm::Optional> WaCPU, WaFPU, WaHDiv, WaArch; @@ -482,7 +488,7 @@ } } - if (ThreadPointer == arm::ReadTPMode::Cp15) + if (getReadTPMode(D, Args, Triple) == ReadTPMode::Cp15) Features.push_back("+read-tp-hard"); const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ); diff --git a/clang/test/Driver/clang-translation.c b/clang/test/Driver/clang-translation.c --- a/clang/test/Driver/clang-translation.c +++ b/clang/test/Driver/clang-translation.c @@ -115,16 +115,22 @@ // ARMv7_THREAD_POINTER-HARD: "-target-feature" "+read-tp-hard" // RUN: %clang -target armv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \ -// RUN: FileCheck -check-prefix=ARMv6T2_THREAD_POINTER-HARD %s -// ARMv6T2_THREAD_POINTER-HARD: "-target-feature" "+read-tp-hard" - +// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s +// RUN: %clang -target thumbv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \ +// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s +// RUN: %clang -target armv6k-linux -mtp=cp15 -### -S %s 2>&1 | \ +// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s +// RUN: %clang -target armv6-linux -mtp=cp15 -### -S %s 2>&1 | \ +// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s // RUN: %clang -target armv5t-linux -mtp=cp15 -### -S %s 2>&1 | \ -// RUN: FileCheck -check-prefix=ARMv5_THREAD_POINTER_UNSUPP %s -// ARMv5_THREAD_POINTER_UNSUPP: hardware TLS register is not supported for the armv5 sub-architecture - -// RUN: %clang -target thumbv6-linux -mtp=cp15 -### -S %s 2>&1 | \ -// RUN: FileCheck -check-prefix=ARMv6_THREAD_POINTER_UNSUPP %s -// ARMv6_THREAD_POINTER_UNSUPP: hardware TLS register is not supported for the armv6 sub-architecture +// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s +// ARM_THREAD_POINTER-HARD: "-target-feature" "+read-tp-hard" + +// RUN: %clang -target armv6-linux -mthumb -mtp=cp15 -### -S %s 2>&1 | \ +// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_UNSUPP %s +// RUN: %clang -target thumbv6-linux -mthumb -mtp=cp15 -### -S %s 2>&1 | \ +// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_UNSUPP %s +// THUMBv6_THREAD_POINTER_UNSUPP: hardware TLS register is not supported for the thumbv6 sub-architecture // RUN: %clang -target armv7-linux -mtp=soft -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_SOFT %s