Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -6579,6 +6579,11 @@ Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name); Args.AddLastArg(CmdArgs, options::OPT_dylinker); Args.AddLastArg(CmdArgs, options::OPT_Mach); + + if (D.IsUsingLTO(Args)) + if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, + options::OPT_fno_zero_initialized_in_bss)) + CmdArgs.push_back("-mllvm -nozero-initialized-in-bss"); } void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, Index: test/Driver/no-zero-initialized-in-bss.c =================================================================== --- /dev/null +++ test/Driver/no-zero-initialized-in-bss.c @@ -0,0 +1,11 @@ +// RUN: %clang -### -c -fno-zero-initialized-in-bss %s 2>&1 | FileCheck -check-prefix CHECK-NO-ZERO %s +// RUN: %clang -### -c -fzero-initialized-in-bss %s 2>&1 | FileCheck -check-prefix CHECK-ZERO %s +// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix CHECK-ZERO %s +// RUN: %clang -### -flto -fzero-initialized-in-bss -fno-zero-initialized-in-bss -target x86_64-apple-darwin %s 2>&1 | FileCheck -check-prefix CHECK-NO-ZERO-LTO-DARWIN %s +// RUN: %clang -### -flto -fno-zero-initialized-in-bss -fzero-initialized-in-bss -target x86_64-apple-darwin %s 2>&1 | FileCheck -check-prefix CHECK-ZERO-LTO-DARWIN %s +// RUN: %clang -### -flto -target x86_64-apple-darwin %s 2>&1 | FileCheck -check-prefix CHECK-ZERO-LTO-DARWIN %s + +// CHECK-NO-ZERO: -mno-zero-initialized-in-bss +// CHECK-ZERO-NOT: -mno-zero-initialized-in-bss +// CHECK-NO-ZERO-LTO-DARWIN: -mllvm -nozero-initialized-in-bss +// CHECK-ZERO-LTO-DARWIN-NOT: -mllvm -nozero-initialized-in-bss