[PATCH] D43108: Support for the mno-stack-arg-probe flag
nruslan created this revision. nruslan added a reviewer: clang. Herald added a subscriber: cfe-commits. Adds support for this flag. There is also another piece for llvm (separate review). More info: https://bugs.llvm.org/show_bug.cgi?id=36221 Repository: rC Clang https://reviews.llvm.org/D43108 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/TargetInfo.cpp lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -914,6 +914,8 @@ Opts.StackProbeSize = StackProbeSize; } + Opts.NoStackArgProbe = Args.hasArg(OPT_mno_stack_arg_probe); + if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) { StringRef Name = A->getValue(); unsigned Method = llvm::StringSwitch(Name) Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -4034,6 +4034,9 @@ CmdArgs.push_back("-mstack-probe-size=0"); } + if (Args.hasArg(options::OPT_mno_stack_arg_probe)) +CmdArgs.push_back("-mno-stack-arg-probe"); + if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it, options::OPT_mno_restrict_it)) { if (A->getOption().matches(options::OPT_mrestrict_it)) { Index: lib/CodeGen/TargetInfo.cpp === --- lib/CodeGen/TargetInfo.cpp +++ lib/CodeGen/TargetInfo.cpp @@ -2355,16 +2355,17 @@ } }; -static void addStackProbeSizeTargetAttribute(const Decl *D, - llvm::GlobalValue *GV, - CodeGen::CodeGenModule &CGM) { +static void addStackProbeParamsTargetAttribute(const Decl *D, + llvm::GlobalValue *GV, + CodeGen::CodeGenModule &CGM) { if (D && isa(D)) { -if (CGM.getCodeGenOpts().StackProbeSize != 4096) { - llvm::Function *Fn = cast(GV); +llvm::Function *Fn = cast(GV); +if (CGM.getCodeGenOpts().StackProbeSize != 4096) Fn->addFnAttr("stack-probe-size", llvm::utostr(CGM.getCodeGenOpts().StackProbeSize)); -} +if (CGM.getCodeGenOpts().NoStackArgProbe) + Fn->addFnAttr("no-stack-arg-probe"); } } @@ -2374,7 +2375,7 @@ X86_32TargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition); if (!IsForDefinition) return; - addStackProbeSizeTargetAttribute(D, GV, CGM); + addStackProbeParamsTargetAttribute(D, GV, CGM); } class WinX86_64TargetCodeGenInfo : public TargetCodeGenInfo { @@ -2436,7 +2437,7 @@ } } - addStackProbeSizeTargetAttribute(D, GV, CGM); + addStackProbeParamsTargetAttribute(D, GV, CGM); } } @@ -5622,7 +5623,7 @@ ARMTargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition); if (!IsForDefinition) return; - addStackProbeSizeTargetAttribute(D, GV, CGM); + addStackProbeParamsTargetAttribute(D, GV, CGM); } } Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -223,6 +223,7 @@ ///< alignment, if not 0. VALUE_CODEGENOPT(StackProbeSize, 32, 4096) ///< Overrides default stack ///< probe size, even if 0. +CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information ///< in debug info. Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1822,6 +1822,8 @@ HelpText<"Set the stack alignment">; def mstack_probe_size : Joined<["-"], "mstack-probe-size=">, Group, Flags<[CC1Option]>, HelpText<"Set the stack probe size">; +def mno_stack_arg_probe : Flag<["-"], "mno-stack-arg-probe">, Group, Flags<[CC1Option]>, + HelpText<"Disable stack probes">; def mthread_model : Separate<["-"], "mthread-model">, Group, Flags<[CC1Option]>, HelpText<"The thread model to use, e.g. posix, single (posix by default)">, Values<"posix,single">; def meabi : Separate<["-"], "meabi">, Group, Flags<[CC1Option]>, Index: docs/ClangCommandLineReference.rst === --- docs/ClangCommandLineReference.rst +++ docs/ClangCommandLineReference.rst @@ -2180,6 +2180,10 @@ Set the stack probe size +.. option:: -mno-stack-arg-probe + +Disable
[PATCH] D43108: Support for the mno-stack-arg-probe flag
nruslan added a comment. @craig.topper, @MatzeB, @hans: Can someone take a look at this change? Repository: rC Clang https://reviews.llvm.org/D43108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D43108: Support for the mno-stack-arg-probe flag
nruslan added a comment. @hans: One real-world example is when it is used to compile UEFI code using PE/COFF targets natively. Obviously, UEFI uses ABI which is basically almost the same as MS ABI, except that chkstk is not used. It mostly works (I actually was able to get it running) except the cases when the code contains variable-sized arrays allocated on stacks. Unfortunately, stack-probe-size will only help with fixed sized array but will not help to solve the problem described in the bug description since stack usage is unknown at compile time. MinGW does not have this problem because it provides this flag. @MatzeB : there is a test on LLVM side (related review). Do you think the test is needed for clang side? If so, please let me know, what kind of test it is supposed to be. Repository: rC Clang https://reviews.llvm.org/D43108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D43108: Support for the mno-stack-arg-probe flag
nruslan updated this revision to Diff 134377. nruslan marked 3 inline comments as done. nruslan added a comment. Added mstack-arg-probe, tests, and changes related to other comments of the reviewers https://reviews.llvm.org/D43108 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/TargetInfo.cpp lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/stack-arg-probe.c test/Driver/stack-arg-probe.c Index: test/Driver/stack-arg-probe.c === --- /dev/null +++ test/Driver/stack-arg-probe.c @@ -0,0 +1,7 @@ +// RUN: %clang -### %s 2>&1 | FileCheck %s -check-prefix=STACKPROBE +// RUN: %clang -### -mno-stack-arg-probe -mstack-arg-probe %s 2>&1 | FileCheck %s -check-prefix=STACKPROBE +// RUN: %clang -### -mstack-arg-probe -mno-stack-arg-probe %s 2>&1 | FileCheck %s -check-prefix=NO-STACKPROBE +// REQUIRES: clang-driver + +// NO-STACKPROBE: -mno-stack-arg-probe +// STACKPROBE-NOT: -mno-stack-arg-probe Index: test/CodeGen/stack-arg-probe.c === --- /dev/null +++ test/CodeGen/stack-arg-probe.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -triple=i686-windows-msvc -emit-llvm -o - -mno-stack-arg-probe | FileCheck %s -check-prefix=NO-STACKPROBE +// RUN: %clang_cc1 %s -triple=i686-windows-msvc -emit-llvm -o - | FileCheck %s -check-prefix=STACKPROBE + +// NO-STACKPROBE: attributes #{{[0-9]+}} = {{{.*}} "no-stack-arg-probe" +// STACKPROBE-NOT: attributes #{{[0-9]+}} = {{{.*}} "no-stack-arg-probe" + +void test1() { +} Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -914,6 +914,8 @@ Opts.StackProbeSize = StackProbeSize; } + Opts.NoStackArgProbe = Args.hasArg(OPT_mno_stack_arg_probe); + if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) { StringRef Name = A->getValue(); unsigned Method = llvm::StringSwitch(Name) Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -4034,6 +4034,10 @@ CmdArgs.push_back("-mstack-probe-size=0"); } + if (!Args.hasFlag(options::OPT_mstack_arg_probe, +options::OPT_mno_stack_arg_probe, true)) +CmdArgs.push_back(Args.MakeArgString("-mno-stack-arg-probe")); + if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it, options::OPT_mno_restrict_it)) { if (A->getOption().matches(options::OPT_mrestrict_it)) { Index: lib/CodeGen/TargetInfo.cpp === --- lib/CodeGen/TargetInfo.cpp +++ lib/CodeGen/TargetInfo.cpp @@ -2355,16 +2355,15 @@ } }; -static void addStackProbeSizeTargetAttribute(const Decl *D, - llvm::GlobalValue *GV, - CodeGen::CodeGenModule &CGM) { - if (D && isa(D)) { -if (CGM.getCodeGenOpts().StackProbeSize != 4096) { - llvm::Function *Fn = cast(GV); +static void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV, + CodeGen::CodeGenModule &CGM) { + if (llvm::Function *Fn = dyn_cast_or_null(GV)) { +if (CGM.getCodeGenOpts().StackProbeSize != 4096) Fn->addFnAttr("stack-probe-size", llvm::utostr(CGM.getCodeGenOpts().StackProbeSize)); -} +if (CGM.getCodeGenOpts().NoStackArgProbe) + Fn->addFnAttr("no-stack-arg-probe"); } } @@ -2374,7 +2373,7 @@ X86_32TargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition); if (!IsForDefinition) return; - addStackProbeSizeTargetAttribute(D, GV, CGM); + addStackProbeTargetAttributes(D, GV, CGM); } class WinX86_64TargetCodeGenInfo : public TargetCodeGenInfo { @@ -2436,7 +2435,7 @@ } } - addStackProbeSizeTargetAttribute(D, GV, CGM); + addStackProbeTargetAttributes(D, GV, CGM); } } @@ -5622,7 +5621,7 @@ ARMTargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition); if (!IsForDefinition) return; - addStackProbeSizeTargetAttribute(D, GV, CGM); + addStackProbeTargetAttributes(D, GV, CGM); } } Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -223,6 +223,7 @@ ///< alignment, if not 0. VALUE_CODEGENOPT(StackProbeSize, 32, 4096) ///< Overrides default stack ///< probe size, even if 0. +CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used CODEGENOP
[PATCH] D43108: Support for the mno-stack-arg-probe flag
nruslan added inline comments. Comment at: lib/Driver/ToolChains/Clang.cpp:4038 + if (Args.hasArg(options::OPT_mno_stack_arg_probe)) +CmdArgs.push_back("-mno-stack-arg-probe"); + hans wrote: > I think you can just do > > ``` > Args.AddLastArg(CmdArgs, options::OPT_mno_stack_arg_probe) > ``` > > which avoids the if-statement and having to spell out the flag. I added mstack_arg_probe also, and this check now contains two options. I am not sure how AddLastArg behaves in this case (especially because only one attribute needs to be defined: mno-stack-arg-probe, and a positive case is the default). I found some other examples similar to this one, and they used hasArg with two options. https://reviews.llvm.org/D43108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D43108: Support for the mno-stack-arg-probe flag
nruslan added a comment. @hans: I responded to the comments and also updated diff for clang with new changes. https://reviews.llvm.org/D43108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D43108: Support for the mno-stack-arg-probe flag
nruslan added a comment. @hans, @craig.topper, @MatzeB: Can someone commit https://reviews.llvm.org/D43108 (this) and https://reviews.llvm.org/D43107 on my behalf? I do not think, I have commit access. https://reviews.llvm.org/D43108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D43108: Support for the mno-stack-arg-probe flag
nruslan added a comment. @aemerson : I am not 100% sure, but I think you are talking about different flag. This commit is for supporting a flag to disable stack probes (identical flag can be found in MinGW), it basically only applies to PE/COFF (Windows) targets. It can be useful to compile UEFI code. By default, Windows will use check probes of 4K in x86. A related stack-probe-size allows to vary the size of stack probes. This one completely disables them. By default, stack probes are enabled (i.e., -mstack-arg-probe is the default behavior) and have the size of 4K in x86. Repository: rC Clang https://reviews.llvm.org/D43108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D43108: Support for the mno-stack-arg-probe flag
nruslan added a comment. @aemerson : yes, it is just part of MS ABI Repository: rC Clang https://reviews.llvm.org/D43108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53102: Support for the mno-tls-direct-seg-refs flag
nruslan created this revision. nruslan added reviewers: hans, craig.topper. Herald added a subscriber: cfe-commits. Allows to disable direct TLS segment access (%fs or %gs). GCC supports a similar flag, it can be useful in some circumstances, e.g. when a thread context block needs to be updated directly from user space. More info and specific use cases: https://bugs.llvm.org/show_bug.cgi?id=16145 There is another revision for LLVM as well. Repository: rC Clang https://reviews.llvm.org/D53102 Files: docs/ClangCommandLineReference.rst include/clang/Driver/CC1Options.td include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CGCall.cpp lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/indirect-tls-seg-refs.c test/Driver/indirect-tls-seg-refs.c Index: test/Driver/indirect-tls-seg-refs.c === --- /dev/null +++ test/Driver/indirect-tls-seg-refs.c @@ -0,0 +1,7 @@ +// RUN: %clang -### %s 2>&1 | FileCheck %s -check-prefix=TLSDIRECT +// RUN: %clang -### -mno-tls-direct-seg-refs -mtls-direct-seg-refs %s 2>&1 | FileCheck %s -check-prefix=TLSDIRECT +// RUN: %clang -### -mtls-direct-seg-refs -mno-tls-direct-seg-refs %s 2>&1 | FileCheck %s -check-prefix=NO-TLSDIRECT +// REQUIRES: clang-driver + +// NO-TLSDIRECT: -indirect-tls-seg-refs +// TLSDIRECT-NOT: -indirect-tls-seg-refs Index: test/CodeGen/indirect-tls-seg-refs.c === --- /dev/null +++ test/CodeGen/indirect-tls-seg-refs.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -indirect-tls-seg-refs | FileCheck %s -check-prefix=NO-TLSDIRECT +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s -check-prefix=TLSDIRECT + +// NO-TLSDIRECT: attributes #{{[0-9]+}} = {{{.*}} "indirect-tls-seg-refs" +// TLSDIRECT-NOT: attributes #{{[0-9]+}} = {{{.*}} "indirect-tls-seg-refs" + +void test1() { +} Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -614,6 +614,7 @@ Opts.DisableLifetimeMarkers = Args.hasArg(OPT_disable_lifetimemarkers); Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone); Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); + Opts.IndirectTlsSegRefs = Args.hasArg(OPT_indirect_tls_seg_refs); Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); Opts.UseRegisterSizedBitfieldAccess = Args.hasArg( OPT_fuse_register_sized_bitfield_access); Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -1739,6 +1739,10 @@ Args.hasArg(options::OPT_fapple_kext)) CmdArgs.push_back("-disable-red-zone"); + if (!Args.hasFlag(options::OPT_mtls_direct_seg_refs, + options::OPT_mno_tls_direct_seg_refs, true)) +CmdArgs.push_back("-indirect-tls-seg-refs"); + // Default to avoid implicit floating-point for kernel/kext code, but allow // that to be overridden with -mno-soft-float. bool NoImplicitFloat = (Args.hasArg(options::OPT_mkernel) || Index: lib/CodeGen/CGCall.cpp === --- lib/CodeGen/CGCall.cpp +++ lib/CodeGen/CGCall.cpp @@ -1709,6 +1709,8 @@ if (CodeGenOpts.DisableRedZone) FuncAttrs.addAttribute(llvm::Attribute::NoRedZone); + if (CodeGenOpts.IndirectTlsSegRefs) +FuncAttrs.addAttribute("indirect-tls-seg-refs"); if (CodeGenOpts.NoImplicitFloat) FuncAttrs.addAttribute(llvm::Attribute::NoImplicitFloat); Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -62,6 +62,8 @@ CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new ///< pass manager. CODEGENOPT(DisableRedZone, 1, 0) ///< Set when -mno-red-zone is enabled. +CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs + ///< is specified. CODEGENOPT(DisableTailCalls , 1, 0) ///< Do not emit tail calls. CODEGENOPT(NoEscapingBlockTailCalls, 1, 0) ///< Do not emit tail calls from ///< escaping blocks. Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -2006,6 +2006,8 @@ def mno_pascal_strings : Flag<["-"], "mno-pascal-strings">, Alias; def mno_red_zone : Flag<["-"], "mno-red-zone">, Group; +def mno_tls_direct_seg_refs : Flag<["-"], "mno-tls-direct-seg-refs">, Group, + HelpText<"Disable direct TLS access through segment registers">;
[PATCH] D53102: Support for the mno-tls-direct-seg-refs flag
nruslan added inline comments. Comment at: docs/ClangCommandLineReference.rst:2241 + +Enable or disable direct TLS access through segment registers + hans wrote: > This file is automatically generated based on the options .td files, so no > need to update it here. ok Comment at: include/clang/Driver/CC1Options.td:195 HelpText<"Do not emit code that uses the red zone.">; +def indirect_tls_seg_refs : Flag<["-"], "indirect-tls-seg-refs">, + HelpText<"Do not emit code that uses direct TLS segment access.">; hans wrote: > Could mno_tls_direct_seg_refs be used as a cc1 flag instead? done Comment at: include/clang/Driver/Options.td:2167 +def mtls_direct_seg_refs : Flag<["-"], "mtls-direct-seg-refs">, Group, + HelpText<"Enable direct TLS access through segment registers">; def mregparm_EQ : Joined<["-"], "mregparm=">, Group; hans wrote: > Maybe add (default) to the help text to indicate this is the default? done https://reviews.llvm.org/D53102 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53102: Support for the mno-tls-direct-seg-refs flag
nruslan updated this revision to Diff 169224. nruslan marked 3 inline comments as done. nruslan added a comment. @hans , @craig.topper : Updated the patch with all requested changes https://reviews.llvm.org/D53102 Files: include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.def lib/CodeGen/CGCall.cpp lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/indirect-tls-seg-refs.c test/Driver/indirect-tls-seg-refs.c Index: test/Driver/indirect-tls-seg-refs.c === --- /dev/null +++ test/Driver/indirect-tls-seg-refs.c @@ -0,0 +1,7 @@ +// RUN: %clang -### %s 2>&1 | FileCheck %s -check-prefix=TLSDIRECT +// RUN: %clang -### -mno-tls-direct-seg-refs -mtls-direct-seg-refs %s 2>&1 | FileCheck %s -check-prefix=TLSDIRECT +// RUN: %clang -### -mtls-direct-seg-refs -mno-tls-direct-seg-refs %s 2>&1 | FileCheck %s -check-prefix=NO-TLSDIRECT +// REQUIRES: clang-driver + +// NO-TLSDIRECT: -mno-tls-direct-seg-refs +// TLSDIRECT-NOT: -mno-tls-direct-seg-refs Index: test/CodeGen/indirect-tls-seg-refs.c === --- /dev/null +++ test/CodeGen/indirect-tls-seg-refs.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -mno-tls-direct-seg-refs | FileCheck %s -check-prefix=NO-TLSDIRECT +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s -check-prefix=TLSDIRECT + +// NO-TLSDIRECT: attributes #{{[0-9]+}} = {{{.*}} "indirect-tls-seg-refs" +// TLSDIRECT-NOT: attributes #{{[0-9]+}} = {{{.*}} "indirect-tls-seg-refs" + +void test1() { +} Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -614,6 +614,7 @@ Opts.DisableLifetimeMarkers = Args.hasArg(OPT_disable_lifetimemarkers); Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone); Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); + Opts.IndirectTlsSegRefs = Args.hasArg(OPT_mno_tls_direct_seg_refs); Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); Opts.UseRegisterSizedBitfieldAccess = Args.hasArg( OPT_fuse_register_sized_bitfield_access); Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -1739,6 +1739,10 @@ Args.hasArg(options::OPT_fapple_kext)) CmdArgs.push_back("-disable-red-zone"); + if (!Args.hasFlag(options::OPT_mtls_direct_seg_refs, + options::OPT_mno_tls_direct_seg_refs, true)) +CmdArgs.push_back("-mno-tls-direct-seg-refs"); + // Default to avoid implicit floating-point for kernel/kext code, but allow // that to be overridden with -mno-soft-float. bool NoImplicitFloat = (Args.hasArg(options::OPT_mkernel) || Index: lib/CodeGen/CGCall.cpp === --- lib/CodeGen/CGCall.cpp +++ lib/CodeGen/CGCall.cpp @@ -1709,6 +1709,8 @@ if (CodeGenOpts.DisableRedZone) FuncAttrs.addAttribute(llvm::Attribute::NoRedZone); + if (CodeGenOpts.IndirectTlsSegRefs) +FuncAttrs.addAttribute("indirect-tls-seg-refs"); if (CodeGenOpts.NoImplicitFloat) FuncAttrs.addAttribute(llvm::Attribute::NoImplicitFloat); Index: include/clang/Frontend/CodeGenOptions.def === --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -62,6 +62,8 @@ CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new ///< pass manager. CODEGENOPT(DisableRedZone, 1, 0) ///< Set when -mno-red-zone is enabled. +CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs + ///< is specified. CODEGENOPT(DisableTailCalls , 1, 0) ///< Do not emit tail calls. CODEGENOPT(NoEscapingBlockTailCalls, 1, 0) ///< Do not emit tail calls from ///< escaping blocks. Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -2006,6 +2006,8 @@ def mno_pascal_strings : Flag<["-"], "mno-pascal-strings">, Alias; def mno_red_zone : Flag<["-"], "mno-red-zone">, Group; +def mno_tls_direct_seg_refs : Flag<["-"], "mno-tls-direct-seg-refs">, Group, Flags<[CC1Option]>, + HelpText<"Disable direct TLS access through segment registers">; def mno_relax_all : Flag<["-"], "mno-relax-all">, Group; def mno_rtd: Flag<["-"], "mno-rtd">, Group; def mno_soft_float : Flag<["-"], "mno-soft-float">, Group; @@ -2161,6 +2163,8 @@ def moslib_EQ : Joined<["-"], "moslib=">, Group; def mpascal_strings : Flag<["-"], "mpascal-strings">, Alias; def mred_zone : Flag<["-"], "mr
[PATCH] D53102: Support for the mno-tls-direct-seg-refs flag
nruslan added a comment. @hans, @craig.topper : If everything is fine, can someone check in the clang and llvm patches on my behalf? I do not have commit access. https://reviews.llvm.org/D53102 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53102: Support for the mno-tls-direct-seg-refs flag
nruslan added a comment. In https://reviews.llvm.org/D53102#1268272, @kristina wrote: > If the author doesn't mind I can just apply the style fix after patching and > then rebuild and run all the relevant tests (or would you prefer to do > that?). Seems easier than a new revision for an indentation change on one > line. @kristina : Thank you! Sure, that is fine. Go ahead. https://reviews.llvm.org/D53102 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53102: Support for the mno-tls-direct-seg-refs flag
nruslan added a comment. In https://reviews.llvm.org/D53102#1268364, @kristina wrote: > By the way, out of curiosity is this for anything specific (alternative libc > or some user-mode-scheduling implementation)? Not nitpicking, just curious > since it's an interesting topic in general and it's frustrating that the > architecture is so limited in terms of registers that can be used for > TLS/related data unlike newer ARM/ARM64 architectures. > > Also FWIW `%gs` is generally free to use under x86_64 Linux which is where I > usually place my thread control blocks which doesn't interfere with libc > which uses `%fs`. (Just started build/test job, waiting on that for now) @kristina : Yes, there are some recent use cases mentioned in the bug report (see the link above). Also, I know that it was used for x86 (32-bit only) Xen guests where it would be recommended to compile an OS with this flag. I also used it in my fork of the NPTL pthread library in VirtuOS to support M:N threading model: http://sigops.org/sosp/sosp13/papers/p116-nikolaev.pdf https://reviews.llvm.org/D53102 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53102: Support for the mno-tls-direct-seg-refs flag
nruslan added a comment. @kristina : Thank you very much for taking care of the patchsets! Repository: rC Clang https://reviews.llvm.org/D53102 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits