Index: lib/Driver/ToolChains/Gnu.cpp =================================================================== --- lib/Driver/ToolChains/Gnu.cpp +++ lib/Driver/ToolChains/Gnu.cpp @@ -390,10 +390,22 @@ CmdArgs.push_back("--fix-cortex-a53-843419"); } - // Android does not allow shared text relocations. Emit a warning if the - // user's code contains any. - if (isAndroid) - CmdArgs.push_back("--warn-shared-textrel"); + if (isAndroid) { + // Android does not allow shared text relocations. Emit a warning if the + // user's code contains any. + CmdArgs.push_back("--warn-shared-textrel"); + + // FIXME In lld, --android-tls is a temporary option that makes its TLS + // layout compatible with Android Bionic on ARM/AArch64. Delete once the + // reservation of extra TLS slots is done in a proper layer (e.g. + // crtbegin_{dynamic,static}.o). + if (Triple.isARM() || Triple.isAArch64()) { + const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); + if (llvm::sys::path::filename(Exec).equals_lower("ld.lld") || + llvm::sys::path::stem(Exec).equals_lower("ld.lld")) + CmdArgs.push_back("--android-tls"); + } + } for (const auto &Opt : ToolChain.ExtraOpts) CmdArgs.push_back(Opt.c_str()); Index: test/Driver/android-aarch64-link.cpp =================================================================== --- test/Driver/android-aarch64-link.cpp +++ test/Driver/android-aarch64-link.cpp @@ -16,7 +16,13 @@ // RUN: -### -v %s 2> %t // RUN: FileCheck -check-prefix=MAX-PAGE-SIZE < %t %s // +// RUN: %clang -target aarch64-linux-android -### %s 2>&1 | \ +// RUN: FileCheck --implicit-check-not=--android-tls /dev/null +// RUN: %clang -target aarch64-linux-android -fuse-ld=lld -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=TLS %s +// // GENERIC-ARM: --fix-cortex-a53-843419 // CORTEX-A53: --fix-cortex-a53-843419 // CORTEX-A57-NOT: --fix-cortex-a53-843419 // MAX-PAGE-SIZE: max-page-size=4096 +// TLS: --android-tls Index: test/Driver/android-arm-link.cpp =================================================================== --- /dev/null +++ test/Driver/android-arm-link.cpp @@ -0,0 +1,6 @@ +// RUN: %clang -target arm-linux-androideabi -### %s 2>&1 | \ +// RUN: FileCheck --implicit-check-not=--android-tls /dev/null +// RUN: %clang -target arm-linux-androideabi -fuse-ld=lld -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=TLS %s + +// TLS: --android-tls