Index: include/clang/Driver/ToolChain.h =================================================================== --- include/clang/Driver/ToolChain.h +++ include/clang/Driver/ToolChain.h @@ -600,6 +600,12 @@ virtual SanitizerMask getDefaultSanitizers() const { return SanitizerMask(); } + + /// Returns true when it's possible to split LTO unit to use whole + /// program devirtualization and CFI santiizers. + virtual bool canSplitThinLTOUnit() const { + return !(getTriple().isOSDarwin() || getTriple().isPS4()); + } }; /// Set a ToolChain's effective triple. Reset it when the registration object Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -5395,7 +5395,9 @@ CmdArgs.push_back("-fwhole-program-vtables"); } - bool DefaultsSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO(); + bool DefaultsSplitLTOUnit = + (WholeProgramVTables || Sanitize.needsLTO()) && + (D.getLTOMode() == LTOK_Full || TC.canSplitThinLTOUnit()); bool SplitLTOUnit = Args.hasFlag(options::OPT_fsplit_lto_unit, options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit); Index: test/Driver/split-lto-unit.c =================================================================== --- test/Driver/split-lto-unit.c +++ test/Driver/split-lto-unit.c @@ -3,6 +3,10 @@ // RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -fno-split-lto-unit 2>&1 | FileCheck --check-prefix=NOUNIT %s // RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -fno-split-lto-unit -fwhole-program-vtables 2>&1 | FileCheck --check-prefix=ERROR1 %s // RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -fno-split-lto-unit -fsanitize=cfi 2>&1 | FileCheck --check-prefix=ERROR2 %s +// RUN: %clang -target x86_64-apple-darwin13.3.0 -### %s -fwhole-program-vtables -flto=full 2>&1 | FileCheck --check-prefix=UNIT %s +// RUN: %clang -target x86_64-apple-darwin13.3.0 -### %s -fwhole-program-vtables -flto=thin 2>&1 | FileCheck --check-prefix=NOUNIT %s +// RUN: %clang -target x86_64-scei-ps4 -### %s -fwhole-program-vtables -flto=full 2>&1 | FileCheck --check-prefix=UNIT %s +// RUN: %clang -target x86_64-scei-ps4 -### %s -fwhole-program-vtables -flto=thin 2>&1 | FileCheck --check-prefix=NOUNIT %s // UNIT: "-fsplit-lto-unit" // NOUNIT-NOT: "-fsplit-lto-unit"