Index: cfe/trunk/include/clang/Driver/Options.td =================================================================== --- cfe/trunk/include/clang/Driver/Options.td +++ cfe/trunk/include/clang/Driver/Options.td @@ -815,7 +815,7 @@ HelpText<"Emit all declarations, even if unused">; def femulated_tls : Flag<["-"], "femulated-tls">, Group, Flags<[CC1Option]>, HelpText<"Use emutls functions to access thread_local variables">; -def fno_emulated_tls : Flag<["-"], "fno-emulated-tls">, Group; +def fno_emulated_tls : Flag<["-"], "fno-emulated-tls">, Group, Flags<[CC1Option]>; def fencoding_EQ : Joined<["-"], "fencoding=">, Group; def ferror_limit_EQ : Joined<["-"], "ferror-limit=">, Group, Flags<[CoreOption]>; def fexceptions : Flag<["-"], "fexceptions">, Group, Flags<[CC1Option]>, Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.def =================================================================== --- cfe/trunk/include/clang/Frontend/CodeGenOptions.def +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def @@ -69,7 +69,8 @@ CODEGENOPT(EmitGcovArcs , 1, 0) ///< Emit coverage data files, aka. GCDA. CODEGENOPT(EmitGcovNotes , 1, 0) ///< Emit coverage "notes" files, aka GCNO. CODEGENOPT(EmitOpenCLArgMetadata , 1, 0) ///< Emit OpenCL kernel arg metadata. -CODEGENOPT(EmulatedTLS , 1, 0) ///< Set when -femulated-tls is enabled. +CODEGENOPT(EmulatedTLS , 1, 0) ///< Set by default or -f[no-]emulated-tls. +CODEGENOPT(ExplicitEmulatedTLS , 1, 0) ///< Set if -f[no-]emulated-tls is used. /// \brief Embed Bitcode mode (off/all/bitcode/marker). ENUM_CODEGENOPT(EmbedBitcode, EmbedBitcodeKind, 2, Embed_Off) CODEGENOPT(ForbidGuardVariables , 1, 0) ///< Issue errors if C++ guard variables Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp =================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp @@ -433,6 +433,7 @@ Options.DataSections = CodeGenOpts.DataSections; Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames; Options.EmulatedTLS = CodeGenOpts.EmulatedTLS; + Options.ExplicitEmulatedTLS = CodeGenOpts.ExplicitEmulatedTLS; Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning(); Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection; Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp @@ -3937,13 +3937,9 @@ Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names); - // Emulated TLS is enabled by default on Android and OpenBSD, and can be enabled - // manually with -femulated-tls. - bool EmulatedTLSDefault = Triple.isAndroid() || Triple.isOSOpenBSD() || - Triple.isWindowsCygwinEnvironment(); - if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls, - EmulatedTLSDefault)) - CmdArgs.push_back("-femulated-tls"); + Args.AddLastArg(CmdArgs, options::OPT_femulated_tls, + options::OPT_fno_emulated_tls); + // AltiVec-like language extensions aren't relevant for assembling. if (!isa(JA) || Output.getType() != types::TY_PP_Asm) Args.AddLastArg(CmdArgs, options::OPT_fzvector); Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp =================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -942,8 +942,12 @@ } } - Opts.EmulatedTLS = - Args.hasFlag(OPT_femulated_tls, OPT_fno_emulated_tls, false); + if (Args.getLastArg(OPT_femulated_tls) || + Args.getLastArg(OPT_fno_emulated_tls)) { + Opts.ExplicitEmulatedTLS = true; + Opts.EmulatedTLS = + Args.hasFlag(OPT_femulated_tls, OPT_fno_emulated_tls, false); + } if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) { StringRef Name = A->getValue(); Index: cfe/trunk/test/Driver/emulated-tls.cpp =================================================================== --- cfe/trunk/test/Driver/emulated-tls.cpp +++ cfe/trunk/test/Driver/emulated-tls.cpp @@ -1,7 +1,42 @@ -// Cygwin and OpenBSD use emutls. Clang should pass -femulated-tls to cc1 -// and cc1 should pass EmulatedTLS to LLVM CodeGen. -// FIXME: Add more targets here to use emutls. -// RUN: %clang -### -std=c++11 -target i686-pc-cygwin %s 2>&1 | FileCheck %s -// RUN: %clang -### -std=c++11 -target i686-pc-openbsd %s 2>&1 | FileCheck %s +// Android, Cygwin and OpenBSD use emutls by default. +// Clang should pass -femulated-tls or -fno-emulated-tls to cc1 if they are used, +// and cc1 should set up EmulatedTLS and ExplicitEmulatedTLS to LLVM CodeGen. +// +// RUN: %clang -### -target arm-linux-androideabi %s 2>&1 \ +// RUN: | FileCheck -check-prefix=DEFAULT %s +// RUN: %clang -### -target arm-linux-gnu %s 2>&1 \ +// RUN: | FileCheck -check-prefix=DEFAULT %s +// RUN: %clang -### -target i686-pc-cygwin %s 2>&1 \ +// RUN: | FileCheck -check-prefix=DEFAULT %s +// RUN: %clang -### -target i686-pc-openbsd %s 2>&1 \ +// RUN: | FileCheck -check-prefix=DEFAULT %s -// CHECK: "-cc1" {{.*}}"-femulated-tls" +// RUN: %clang -### -target arm-linux-androideabi -fno-emulated-tls -femulated-tls %s 2>&1 \ +// RUN: | FileCheck -check-prefix=EMU %s +// RUN: %clang -### -target arm-linux-gnu %s -fno-emulated-tls -femulated-tls 2>&1 \ +// RUN: | FileCheck -check-prefix=EMU %s +// RUN: %clang -### -target i686-pc-cygwin %s -fno-emulated-tls -femulated-tls 2>&1 \ +// RUN: | FileCheck -check-prefix=EMU %s +// RUN: %clang -### -target i686-pc-openbsd %s -fno-emulated-tls -femulated-tls 2>&1 \ +// RUN: | FileCheck -check-prefix=EMU %s + +// RUN: %clang -### -target arm-linux-androideabi -femulated-tls -fno-emulated-tls %s 2>&1 \ +// RUN: | FileCheck -check-prefix=NOEMU %s +// RUN: %clang -### -target arm-linux-gnu %s -femulated-tls -fno-emulated-tls 2>&1 \ +// RUN: | FileCheck -check-prefix=NOEMU %s +// RUN: %clang -### -target i686-pc-cygwin %s -femulated-tls -fno-emulated-tls 2>&1 \ +// RUN: | FileCheck -check-prefix=NOEMU %s +// RUN: %clang -### -target i686-pc-openbsd %s -femulated-tls -fno-emulated-tls 2>&1 \ +// RUN: | FileCheck -check-prefix=NOEMU %s + + +// Default without -f[no-]emulated-tls, will be decided by the target triple. +// DEFAULT-NOT: "-cc1" {{.*}}"-femulated-tls" +// DEFAULT-NOT: "-cc1" {{.*}}"-fno-emulated-tls" + +// Explicit and last -f[no-]emulated-tls flag will be passed to cc1. +// EMU: "-cc1" {{.*}}"-femulated-tls" +// EMU-NOT: "-cc1" {{.*}}"-fno-emulated-tls" + +// NOEMU: "-cc1" {{.*}}"-fno-emulated-tls" +// NOEMU-NOT: "-cc1" {{.*}}"-femulated-tls"