From f4910132078b4b8852fc46657f3150ed472f4654 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 16 Apr 2013 18:21:19 +0000 Subject: [PATCH] [Modules] Convert module specific -fno-modules-autolink into -fno-autolink. - There is no reason to have a modules specific flag for disabling autolinking. Instead, convert the existing flag into -fno-autolink (which should cover other autolinking code generation paths like #pragmas if and when we support them). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179612 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/Modules.rst | 4 ++-- include/clang/Driver/Options.td | 9 ++++---- include/clang/Frontend/CodeGenOptions.def | 3 +-- lib/CodeGen/CodeGenModule.cpp | 2 +- lib/Driver/Tools.cpp | 25 ++++++++++++++--------- lib/Frontend/CompilerInvocation.cpp | 2 +- test/Driver/autolink_integrated_as.c | 6 ++++++ test/Driver/modules.m | 6 ------ test/Driver/modules_integrated_as.c | 6 ------ test/Modules/autolink.m | 6 +++++- 10 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 test/Driver/autolink_integrated_as.c delete mode 100644 test/Driver/modules_integrated_as.c diff --git a/docs/Modules.rst b/docs/Modules.rst index 8a6b8b6d2e..fdf597a5a9 100644 --- a/docs/Modules.rst +++ b/docs/Modules.rst @@ -168,8 +168,8 @@ Command-line parameters ``-fmodules-cache-path=`` Specify the path to the modules cache. If not provided, Clang will select a system-appropriate default. -``-f[no-]modules-autolink`` - Enable of disable automatic linking against the libraries associated with imported modules. +``-fno-autolink`` + Disable automatic linking against the libraries associated with imported modules. ``-fmodules-ignore-macro=macroname`` Instruct modules to ignore the named macro when selecting an appropriate module variant. Use this for macros defined on the command line that don't affect how modules are built, to improve sharing of compiled module files. diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 34a62fc29f..f79a5badc6 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -311,6 +311,11 @@ def fastcp : Flag<["-"], "fastcp">, Group; def fastf : Flag<["-"], "fastf">, Group; def fast : Flag<["-"], "fast">, Group; def fasynchronous_unwind_tables : Flag<["-"], "fasynchronous-unwind-tables">, Group; + +def fautolink : Flag <["-"], "fautolink">, Group; +def fno_autolink : Flag <["-"], "fno-autolink">, Group, Flags<[NoForward, CC1Option]>, + HelpText<"Disable generation of linker directives for automatic library linking">; + def fblocks : Flag<["-"], "fblocks">, Group, Flags<[CC1Option]>, HelpText<"Enable the 'blocks' language feature">; def fbootclasspath_EQ : Joined<["-"], "fbootclasspath=">, Group; @@ -509,10 +514,6 @@ def fmodules_prune_after : Joined<["-"], "fmodules-prune-after=">, Group; def fmodules : Flag <["-"], "fmodules">, Group, Flags<[NoForward,CC1Option]>, HelpText<"Enable the 'modules' language feature">; -def fmodules_autolink : Flag <["-"], "fmodules-autolink">, Group, Flags<[NoForward,CC1Option]>, - HelpText<"Enable autolinking of the libraries for imported modules">; -def fno_modules_autolink : Flag <["-"], "fno-modules-autolink">, Group, - HelpText<"Disable autolinking of the libraries for imported modules">; def fmodules_ignore_macro : Joined<["-"], "fmodules-ignore-macro=">, Group, Flags<[CC1Option]>, HelpText<"Ignore the definition of the given macro when building and loading modules">; def fretain_comments_from_system_headers : Flag<["-"], "fretain-comments-from-system-headers">, Group, Flags<[CC1Option]>; diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 1c0b9fa99e..f6e2472cb9 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -28,6 +28,7 @@ CODEGENOPT(Name, Bits, Default) CODEGENOPT(Name, Bits, Default) #endif +CODEGENOPT(Autolink , 1, 1) ///< -fno-autolink CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm. CODEGENOPT(ObjCAutoRefCountExceptions , 1, 0) ///< Whether ARC should be EH-safe. CODEGENOPT(CoverageExtraChecksum, 1, 0) ///< Whether we need a second checksum for functions in GCNO files. @@ -120,8 +121,6 @@ VALUE_CODEGENOPT(StackAlignment , 32, 0) ///< Overrides default stack CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information ///< in debug info. -CODEGENOPT(ModulesAutolink, 1, 0) ///< Whether to auto-link imported modules - /// The user specified number of registers to be used for integral arguments, /// or 0 if unspecified. VALUE_CODEGENOPT(NumRegisterParameters, 32, 0) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 5893814d7a..7990a491c0 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -189,7 +189,7 @@ void CodeGenModule::Release() { EmitStaticExternCAliases(); EmitLLVMUsed(); - if (CodeGenOpts.ModulesAutolink) { + if (CodeGenOpts.Autolink && Context.getLangOpts().Modules) { EmitModuleLinkOptions(); } diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 2cb9d6f09e..0ecd6f4146 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1453,6 +1453,18 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType, CmdArgs.push_back("-fexceptions"); } +static bool ShouldDisableAutolink(const ArgList &Args, + const ToolChain &TC) { + bool Default = true; + if (TC.getTriple().isOSDarwin()) { + // The native darwin assembler doesn't support the linker_option directives, + // so we disable them if we think the .s file will be passed to it. + Default = TC.useIntegratedAs(); + } + return !Args.hasFlag(options::OPT_fautolink, options::OPT_fno_autolink, + Default); +} + static bool ShouldDisableCFI(const ArgList &Args, const ToolChain &TC) { bool Default = true; @@ -2594,6 +2606,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (ShouldDisableDwarfDirectory(Args, getToolChain())) CmdArgs.push_back("-fno-dwarf-directory-asm"); + if (ShouldDisableAutolink(Args, getToolChain())) + CmdArgs.push_back("-fno-autolink"); + // Add in -fdebug-compilation-dir if necessary. addDebugCompDirArg(Args, CmdArgs); @@ -2889,16 +2904,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_interval); Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_after); - // -fmodules-autolink (on by default when modules is enabled) automatically - // links against libraries for imported modules. This requires the - // integrated assembler. - if (HaveModules && getToolChain().useIntegratedAs() && - Args.hasFlag(options::OPT_fmodules_autolink, - options::OPT_fno_modules_autolink, - true)) { - CmdArgs.push_back("-fmodules-autolink"); - } - // -faccess-control is default. if (Args.hasFlag(options::OPT_fno_access_control, options::OPT_faccess_control, diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index c8ccffa91d..ba3809bba5 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -328,7 +328,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info); Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); - Opts.ModulesAutolink = Args.hasArg(OPT_fmodules_autolink); Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns); Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); @@ -347,6 +346,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) || (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize); + Opts.Autolink = !Args.hasArg(OPT_fno_autolink); Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose); Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions); Opts.CUDAIsDevice = Args.hasArg(OPT_fcuda_is_device); diff --git a/test/Driver/autolink_integrated_as.c b/test/Driver/autolink_integrated_as.c new file mode 100644 index 0000000000..f1e710222a --- /dev/null +++ b/test/Driver/autolink_integrated_as.c @@ -0,0 +1,6 @@ +// RUN: %clang -target x86_64-apple-darwin -fsyntax-only %s -no-integrated-as -### 2>&1 | FileCheck %s + +// Test that the autolinking feature is disabled with *not* using the +// integrated assembler. + +// CHECK: -fno-autolink diff --git a/test/Driver/modules.m b/test/Driver/modules.m index 69c79fca72..b93054dbf8 100644 --- a/test/Driver/modules.m +++ b/test/Driver/modules.m @@ -4,9 +4,3 @@ // RUN: %clang -fmodules -fno-modules -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-MODULES %s // CHECK-HAS-MODULES: -fmodules -// RUN: %clang -target x86_64-apple-darwin10 -fmodules -fno-modules -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-AUTOLINK %s -// CHECK-HAS-AUTOLINK: -fmodules-autolink - -// RUN: %clang -fmodules -fno-modules -fno-modules-autolink -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-AUTOLINK %s -// CHECK-NO-AUTOLINK-NOT: -fmodules-autolink - diff --git a/test/Driver/modules_integrated_as.c b/test/Driver/modules_integrated_as.c deleted file mode 100644 index 0abd18fc5f..0000000000 --- a/test/Driver/modules_integrated_as.c +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: %clang -fsyntax-only modules_integrated_as.c -fmodules -no-integrated-as -### 2>&1 | FileCheck %s - -// Test that the autolinking feature is disabled with *not* using the -// integrated assembler. - -// CHECK-NOT: -fmodules-autolink diff --git a/test/Modules/autolink.m b/test/Modules/autolink.m index 7f75473cbb..4bf9d592a8 100644 --- a/test/Modules/autolink.m +++ b/test/Modules/autolink.m @@ -1,5 +1,6 @@ // RUN: rm -rf %t -// RUN: %clang_cc1 -emit-llvm -o - -fmodules-cache-path=%t -fmodules -fmodules-autolink -F %S/Inputs -I %S/Inputs %s | FileCheck %s +// RUN: %clang_cc1 -emit-llvm -o - -fmodules-cache-path=%t -fmodules -F %S/Inputs -I %S/Inputs %s | FileCheck %s +// RUN: %clang_cc1 -emit-llvm -fno-autolink -o - -fmodules-cache-path=%t -fmodules -F %S/Inputs -I %S/Inputs %s | FileCheck --check-prefix=CHECK-AUTOLINK-DISABLED %s @import autolink.sub2; @@ -38,3 +39,6 @@ int use_no_umbrella() { // CHECK: ![[DEPENDSONMODULE]] = metadata !{metadata !"-framework", metadata !"DependsOnModule"} // CHECK: ![[MODULE]] = metadata !{metadata !"-framework", metadata !"Module"} // CHECK: ![[NOUMBRELLA]] = metadata !{metadata !"-framework", metadata !"NoUmbrella"} + +// CHECK-AUTOLINK-DISABLED: !llvm.module.flags +// CHECK-AUTOLINK-DISABLED-NOT: "Linker Options" -- 2.40.0