Previously, this flag to CC1 was never exposed at the clang driver
layer, and if you happened to enable it (by being on Android or GCC 4.7
platform), you couldn't *disable* it, because there was no 'no' variant.
The whole thing was confusingly implemented.
Now, the target-specific flag processing gets the driver arg list, and
we use standard hasFlag with a default based on the GCC version and/or
Android platform. The user can still pass the 'no-' variant to forcibly
disable the flag, or pass the positive variant to clang itself to enable
the flag.
The test has also been substantially cleaned up and extended to cover
these use cases.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168473
91177308-0d34-0410-b5e6-
96231b3b80d8
HelpText<"The relocation model to use">;
def munwind_tables : Flag<["-"], "munwind-tables">,
HelpText<"Generate unwinding tables for all functions">;
-def fuse_init_array : Flag<["-"], "fuse-init-array">,
- HelpText<"Use .init_array instead of .ctors">;
def mconstructor_aliases : Flag<["-"], "mconstructor-aliases">,
HelpText<"Emit complete constructors and destructors as aliases when possible">;
def mlink_bitcode_file : Separate<["-"], "mlink-bitcode-file">,
Flags<[CC1Option]>, HelpText<"Do not emit code to make initialization of local statics thread safe">;
def fno_use_cxa_atexit : Flag<["-"], "fno-use-cxa-atexit">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Don't use __cxa_atexit for calling destructors">;
+def fno_use_init_array : Flag<["-"], "fno-use-init-array">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Don't use .init_array instead of .ctors">;
def fno_unit_at_a_time : Flag<["-"], "fno-unit-at-a-time">, Group<f_Group>;
def fno_unwind_tables : Flag<["-"], "fno-unwind-tables">, Group<f_Group>;
def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, Group<f_Group>;
def funsigned_char : Flag<["-"], "funsigned-char">, Group<f_Group>;
def funwind_tables : Flag<["-"], "funwind-tables">, Group<f_Group>;
def fuse_cxa_atexit : Flag<["-"], "fuse-cxa-atexit">, Group<f_Group>;
+def fuse_init_array : Flag<["-"], "fuse-init-array">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Use .init_array instead of .ctors">;
def fverbose_asm : Flag<["-"], "fverbose-asm">, Group<f_Group>;
def fvisibility_EQ : Joined<["-"], "fvisibility=">, Group<f_Group>;
def fvisibility_inlines_hidden : Flag<["-"], "fvisibility-inlines-hidden">, Group<f_Group>,
virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const;
- // addClangTargetOptions - Add options that need to be passed to cc1 for
- // this target.
- virtual void addClangTargetOptions(ArgStringList &CC1Args) const;
+ /// \brief Add options that need to be passed to cc1 for this target.
+ virtual void addClangTargetOptions(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const;
// GetRuntimeLibType - Determine the runtime library type to use with the
// given compilation arguments.
// Each toolchain should provide the appropriate include flags.
}
-void ToolChain::addClangTargetOptions(ArgStringList &CC1Args) const {
+void ToolChain::addClangTargetOptions(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
}
ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
return *T;
}
-void Linux::addClangTargetOptions(ArgStringList &CC1Args) const {
+void Linux::addClangTargetOptions(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion();
- if (V >= Generic_GCC::GCCVersion::Parse("4.7.0") ||
- getTriple().getEnvironment() == llvm::Triple::Android)
+ bool UseInitArrayDefault
+ = V >= Generic_GCC::GCCVersion::Parse("4.7.0") ||
+ getTriple().getEnvironment() == llvm::Triple::Android;
+ if (DriverArgs.hasFlag(options::OPT_fuse_init_array,
+ options::OPT_fno_use_init_array,
+ UseInitArrayDefault))
CC1Args.push_back("-fuse-init-array");
}
virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const;
- virtual void addClangTargetOptions(ArgStringList &CC1Args) const;
+ virtual void addClangTargetOptions(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const;
virtual void AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const;
AsynchronousUnwindTables))
CmdArgs.push_back("-munwind-tables");
- getToolChain().addClangTargetOptions(CmdArgs);
+ getToolChain().addClangTargetOptions(Args, CmdArgs);
if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
CmdArgs.push_back("-mlimit-float-precision");
+// Test whether or not the driver instructs the backend to use .init_array
+// sections for global constructors.
+//
+// CHECK-INIT-ARRAY: -fuse-init-array
+// CHECK-NO-INIT-ARRAY-NOT: -fuse-init-array
+//
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target i386-unknown-linux \
// RUN: --sysroot=%S/Inputs/fake_install_tree \
-// RUN: | FileCheck --check-prefix=CHECK-GCC-4-7 %s
-
-// CHECK-GCC-4-7: -fuse-init-array
-
+// RUN: | FileCheck --check-prefix=CHECK-INIT-ARRAY %s
+//
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -fno-use-init-array \
+// RUN: -target i386-unknown-linux \
+// RUN: --sysroot=%S/Inputs/fake_install_tree \
+// RUN: | FileCheck --check-prefix=CHECK-NO-INIT-ARRAY %s
+//
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -fno-use-init-array -fuse-init-array \
+// RUN: -target i386-unknown-linux \
+// RUN: --sysroot=%S/Inputs/fake_install_tree \
+// RUN: | FileCheck --check-prefix=CHECK-INIT-ARRAY %s
+//
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: | FileCheck --check-prefix=CHECK-NO-INIT-ARRAY %s
+//
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -fuse-init-array \
// RUN: -target i386-unknown-linux \
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
-// RUN: | FileCheck --check-prefix=CHECK-GCC-4-6 %s
-
-// CHECK-GCC-4-6-NOT: -fuse-init-array
-
+// RUN: | FileCheck --check-prefix=CHECK-INIT-ARRAY %s
+//
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target arm-unknown-linux-androideabi \
// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
-// RUN: | FileCheck --check-prefix=CHECK-ANDROID %s
-
+// RUN: | FileCheck --check-prefix=CHECK-INIT-ARRAY %s
+//
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target mipsel-unknown-linux-android \
// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
-// RUN: | FileCheck --check-prefix=CHECK-ANDROID %s
-
+// RUN: | FileCheck --check-prefix=CHECK-INIT-ARRAY %s
+//
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target i386-unknown-linux-android \
// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
-// RUN: | FileCheck --check-prefix=CHECK-ANDROID %s
-
-// CHECK-ANDROID: -fuse-init-array
+// RUN: | FileCheck --check-prefix=CHECK-INIT-ARRAY %s