Index: include/clang/Driver/CLCompatOptions.td =================================================================== --- include/clang/Driver/CLCompatOptions.td +++ include/clang/Driver/CLCompatOptions.td @@ -77,6 +77,8 @@ def _SLASH_GR_ : CLFlag<"GR-">, HelpText<"Disable emission of RTTI data">; def _SLASH_GF_ : CLFlag<"GF-">, HelpText<"Disable string pooling">, Alias; +def _SLASH_GS : CLFlag<"GS">, HelpText<"Enable buffer security check">; +def _SLASH_GS_ : CLFlag<"GS-">, HelpText<"Disable buffer security check">; def _SLASH_Gs : CLJoined<"Gs">, HelpText<"Set stack probe size">, Alias; def _SLASH_Gy : CLFlag<"Gy">, HelpText<"Put each function in its own section">, @@ -287,7 +289,6 @@ def _SLASH_FC : CLIgnoredFlag<"FC">; def _SLASH_FS : CLIgnoredFlag<"FS">, HelpText<"Force synchronous PDB writes">; def _SLASH_GF : CLIgnoredFlag<"GF">; -def _SLASH_GS_ : CLIgnoredFlag<"GS-">; def _SLASH_kernel_ : CLIgnoredFlag<"kernel-">; def _SLASH_nologo : CLIgnoredFlag<"nologo">; def _SLASH_Ob1 : CLIgnoredFlag<"Ob1">; @@ -329,7 +330,6 @@ def _SLASH_GL_ : CLFlag<"GL-">; def _SLASH_Gm : CLFlag<"Gm">; def _SLASH_Gm_ : CLFlag<"Gm-">; -def _SLASH_GS : CLFlag<"GS">; def _SLASH_GT : CLFlag<"GT">; def _SLASH_Guard : CLJoined<"guard:">; def _SLASH_GZ : CLFlag<"GZ">; Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -6146,6 +6146,14 @@ /*default=*/false)) CmdArgs.push_back("-fno-rtti-data"); + // This controls whether or not we emit stack-protector instrumentation. + // In MSVC, Buffer Security Check (/GS) is on by default. + if (Args.hasFlag(options::OPT__SLASH_GS, options::OPT__SLASH_GS_, + /*default=*/true)) { + CmdArgs.push_back("-stack-protector"); + CmdArgs.push_back(Args.MakeArgString(Twine(LangOptions::SSPStrong))); + } + // Emit CodeView if -Z7 is present. *EmitCodeView = Args.hasArg(options::OPT__SLASH_Z7); if (*EmitCodeView) @@ -9976,6 +9984,12 @@ if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR, /*default=*/false)) CmdArgs.push_back("/GR-"); + + if (Args.hasFlag(options::OPT__SLASH_GS, options::OPT__SLASH_GS_, + /*default=*/true)) { + CmdArgs.push_back("/GR"); + } + if (Arg *A = Args.getLastArg(options::OPT_ffunction_sections, options::OPT_fno_function_sections)) CmdArgs.push_back(A->getOption().getID() == options::OPT_ffunction_sections