diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 19a830cac144..ffaa5724ac83 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -908,21 +908,28 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType, static bool ShouldDisableCFI(const ArgList &Args, const ToolChain &TC) { + if (TC.getTriple().getOS() == llvm::Triple::Darwin) { + // The native darwin assembler doesn't support cfi directives, so + // we disable them if with think the .s file will be passed to it. - // FIXME: Duplicated code with ToolChains.cpp - // FIXME: This doesn't belong here, but ideally we will support static soon - // anyway. - bool HasStatic = (Args.hasArg(options::OPT_mkernel) || - Args.hasArg(options::OPT_static) || - Args.hasArg(options::OPT_fapple_kext)); - bool IsIADefault = TC.IsIntegratedAssemblerDefault() && !HasStatic; - bool UseIntegratedAs = Args.hasFlag(options::OPT_integrated_as, - options::OPT_no_integrated_as, - IsIADefault); - bool UseCFI = Args.hasFlag(options::OPT_fdwarf2_cfi_asm, - options::OPT_fno_dwarf2_cfi_asm, - UseIntegratedAs); - return !UseCFI; + // FIXME: Duplicated code with ToolChains.cpp + // FIXME: This doesn't belong here, but ideally we will support static soon + // anyway. + bool HasStatic = (Args.hasArg(options::OPT_mkernel) || + Args.hasArg(options::OPT_static) || + Args.hasArg(options::OPT_fapple_kext)); + bool IsIADefault = TC.IsIntegratedAssemblerDefault() && !HasStatic; + bool UseIntegratedAs = Args.hasFlag(options::OPT_integrated_as, + options::OPT_no_integrated_as, + IsIADefault); + bool UseCFI = Args.hasFlag(options::OPT_fdwarf2_cfi_asm, + options::OPT_fno_dwarf2_cfi_asm, + UseIntegratedAs); + return !UseCFI; + } + + // For now we assume that every other assembler support CFI. + return false; } /// \brief Check whether the given input tree contains any compilation actions. diff --git a/clang/test/Driver/cfi.c b/clang/test/Driver/cfi.c new file mode 100644 index 000000000000..b5c0c03e7a49 --- /dev/null +++ b/clang/test/Driver/cfi.c @@ -0,0 +1,8 @@ +// RUN: %clang -ccc-host-triple i386-apple-darwin10 -static -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-DARWIN %s + +// RUN: %clang -ccc-host-triple i386-pc-linux-gnu -static -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-LINUX %s + +// CHECK-DARWIN: -fno-dwarf2-cfi-asm +// CHECK-LINUX-NOT: -fno-dwarf2-cfi-asm