From 85a2bd7b86535fb2eabeda3eaafb0e91c2b68331 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 21 Dec 2015 22:09:34 +0000 Subject: [PATCH] [clang-cl] Add support for /Brepro The /Brepro flag controls whether or not the compiler should embed timestamps into the object file. Object files which do not embed timestamps are not suitable for incremental linking but are suitable for hermetic build systems and staged self-hosts of clang. A normal clang spelling of this flag has been added, -mincremental-linker-compatible. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256204 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CLCompatOptions.td | 6 ++++++ include/clang/Driver/Options.td | 5 +++++ include/clang/Frontend/CodeGenOptions.def | 3 +++ lib/CodeGen/BackendUtil.cpp | 2 ++ lib/Driver/Tools.cpp | 9 +++++++++ lib/Frontend/CompilerInvocation.cpp | 2 ++ test/Driver/cl-options.c | 9 +++++++++ test/Driver/incremental-linker-compatible.c | 17 +++++++++++++++++ tools/driver/cc1as_main.cpp | 11 ++++++++--- 9 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 test/Driver/incremental-linker-compatible.c diff --git a/include/clang/Driver/CLCompatOptions.td b/include/clang/Driver/CLCompatOptions.td index 2db9cfa853..16a5b72783 100644 --- a/include/clang/Driver/CLCompatOptions.td +++ b/include/clang/Driver/CLCompatOptions.td @@ -52,6 +52,12 @@ class CLRemainingArgs : Option<["/", "-"], name, // (We don't put any of these in cl_compile_Group as the options they alias are // already in the right group.) +def _SLASH_Brepro : CLFlag<"Brepro">, + HelpText<"Emit an object file which can be reproduced over time">, + Alias; +def _SLASH_Brepro_ : CLFlag<"Brepro-">, + HelpText<"Emit an object file which cannot be reproduced over time">, + Alias; def _SLASH_C : CLFlag<"C">, HelpText<"Don't discard comments when preprocessing">, Alias; def _SLASH_c : CLFlag<"c">, HelpText<"Compile only">, Alias; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index bfcc55ffde..5ee9115ec7 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1459,6 +1459,11 @@ def mred_zone : Flag<["-"], "mred-zone">, Group; def mregparm_EQ : Joined<["-"], "mregparm=">, Group; def mrelax_all : Flag<["-"], "mrelax-all">, Group, Flags<[CC1Option,CC1AsOption]>, HelpText<"(integrated-as) Relax all machine instructions">; +def mincremental_linker_compatible : Flag<["-"], "mincremental-linker-compatible">, Group, + Flags<[CC1Option,CC1AsOption]>, + HelpText<"(integrated-as) Emit an object file which can be used with an incremental linker">; +def mno_incremental_linker_compatible : Flag<["-"], "mno-incremental-linker-compatible">, Group, + HelpText<"(integrated-as) Emit an object file which cannot be used with an incremental linker">; def mrtd : Flag<["-"], "mrtd">, Group, Flags<[CC1Option]>, HelpText<"Make StdCall calling convention the default">; def msmall_data_threshold_EQ : Joined <["-"], "msmall-data-threshold=">, Group; diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 2e9205fc84..d9f6ab7f42 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -75,6 +75,9 @@ CODEGENOPT(PrepareForLTO , 1, 0) ///< Set when -flto is enabled on the ///< compile step. CODEGENOPT(EmitFunctionSummary, 1, 0) ///< Set when -flto=thin is enabled on the ///< compile step. +CODEGENOPT(IncrementalLinkerCompatible, 1, 0) ///< Emit an object file which can + ///< be used with an incremental + ///< linker. CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants. CODEGENOPT(MergeFunctions , 1, 0) ///< Set when -fmerge-functions is enabled. CODEGENOPT(MSVolatile , 1, 0) ///< Set when /volatile:ms is enabled. diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 79aff4f496..82297e7ee4 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -571,6 +571,8 @@ TargetMachine *EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) { Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels; Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm; Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack; + Options.MCOptions.MCIncrementalLinkerCompatible = + CodeGenOpts.IncrementalLinkerCompatible; Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings; Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose; Options.MCOptions.ABIName = TargetOpts.ABI; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index fd299ea695..5457028677 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2567,6 +2567,15 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, if (UseRelaxAll(C, Args)) CmdArgs.push_back("-mrelax-all"); + // Only default to -mincremental-linker-compatible if we think we are + // targeting the MSVC linker. + bool DefaultIncrementalLinkerCompatible = + C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(); + if (Args.hasFlag(options::OPT_mincremental_linker_compatible, + options::OPT_mno_incremental_linker_compatible, + DefaultIncrementalLinkerCompatible)) + CmdArgs.push_back("-mincremental-linker-compatible"); + // When passing -I arguments to the assembler we sometimes need to // unconditionally take the next argument. For example, when parsing // '-Wa,-I -Wa,foo' we need to accept the -Wa,foo arg after seeing the diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 7fe0a86753..8481a735aa 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -500,6 +500,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings); Opts.EnableSegmentedStacks = Args.hasArg(OPT_split_stacks); Opts.RelaxAll = Args.hasArg(OPT_mrelax_all); + Opts.IncrementalLinkerCompatible = + Args.hasArg(OPT_mincremental_linker_compatible); Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels); Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm); diff --git a/test/Driver/cl-options.c b/test/Driver/cl-options.c index 4ad1612bba..c23aefea14 100644 --- a/test/Driver/cl-options.c +++ b/test/Driver/cl-options.c @@ -376,6 +376,15 @@ // Z7: "-gcodeview" // Z7: "-debug-info-kind=line-tables-only" +// RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=BreproDefault %s +// BreproDefault: "-mincremental-linker-compatible" + +// RUN: %clang_cl /Brepro- /Brepro /c '-###' -- %s 2>&1 | FileCheck -check-prefix=Brepro %s +// Brepro: "-mincremental-linker-compatible" + +// RUN: %clang_cl /Brepro /Brepro- /c '-###' -- %s 2>&1 | FileCheck -check-prefix=Brepro_ %s +// Brepro_-NOT: "-mincremental-linker-compatible" + // This test was super sneaky: "/Z7" means "line-tables", but "-gdwarf" occurs // later on the command line, so it should win. Interestingly the cc1 arguments // came out right, but had wrong semantics, because an invariant assumed by diff --git a/test/Driver/incremental-linker-compatible.c b/test/Driver/incremental-linker-compatible.c new file mode 100644 index 0000000000..e702a01376 --- /dev/null +++ b/test/Driver/incremental-linker-compatible.c @@ -0,0 +1,17 @@ +// RUN: %clang '-###' %s -c -o tmp.o -target i686-pc-linux-gnu -integrated-as -mincremental-linker-compatible 2>&1 | FileCheck %s --check-prefix=TEST1 +// TEST1: "-cc1" {{.*}} "-mincremental-linker-compatible" + +// RUN: %clang '-###' %s -c -o tmp.o -target i686-pc-linux-gnu -integrated-as -mno-incremental-linker-compatible 2>&1 | FileCheck %s --check-prefix=TEST2 +// TEST2-NOT: "-cc1" {{.*}} "-mincremental-linker-compatible" + +// RUN: %clang '-###' %s -c -o tmp.o -target i686-pc-linux-gnu -integrated-as -mno-incremental-linker-compatible -mincremental-linker-compatible 2>&1 | FileCheck %s --check-prefix=TEST3 +// TEST3: "-cc1" {{.*}} "-mincremental-linker-compatible" + +// RUN: %clang '-###' %s -c -o tmp.o -target i686-pc-linux-gnu -integrated-as -mincremental-linker-compatible -mno-incremental-linker-compatible 2>&1 | FileCheck %s --check-prefix=TEST4 +// TEST4-NOT: "-cc1" {{.*}} "-mincremental-linker-compatible" + +// RUN: %clang '-###' %s -c -o tmp.o -target i686-pc-mingw32 -integrated-as 2>&1 | FileCheck %s --check-prefix=TEST5 +// TEST5-NOT: "-cc1" {{.*}} "-mincremental-linker-compatible" + +// RUN: %clang '-###' %s -c -o tmp.o -target i686-pc-win32 -integrated-as 2>&1 | FileCheck %s --check-prefix=TEST6 +// TEST6: "-cc1" {{.*}} "-mincremental-linker-compatible" diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp index d98ba6ea42..59b7af5217 100644 --- a/tools/driver/cc1as_main.cpp +++ b/tools/driver/cc1as_main.cpp @@ -125,6 +125,7 @@ struct AssemblerInvocation { unsigned RelaxAll : 1; unsigned NoExecStack : 1; unsigned FatalWarnings : 1; + unsigned IncrementalLinkerCompatible : 1; /// The name of the relocation model to use. std::string RelocationModel; @@ -144,6 +145,7 @@ public: RelaxAll = 0; NoExecStack = 0; FatalWarnings = 0; + IncrementalLinkerCompatible = 0; DwarfVersion = 0; } @@ -248,6 +250,8 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings); Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); + Opts.IncrementalLinkerCompatible = + Args.hasArg(OPT_mincremental_linker_compatible); return Success; } @@ -394,9 +398,10 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*MRI, Opts.Triple, Opts.CPU); Triple T(Opts.Triple); - Str.reset(TheTarget->createMCObjectStreamer(T, Ctx, *MAB, *Out, CE, *STI, - Opts.RelaxAll, - /*DWARFMustBeAtTheEnd*/ true)); + Str.reset(TheTarget->createMCObjectStreamer( + T, Ctx, *MAB, *Out, CE, *STI, Opts.RelaxAll, + Opts.IncrementalLinkerCompatible, + /*DWARFMustBeAtTheEnd*/ true)); Str.get()->InitSections(Opts.NoExecStack); } -- 2.50.1