<p dir="ltr">Looks like something that should be in the bitcode, no? What happens if one compile unit has it and another one doesn't? </p>
<div class="gmail_quote">On Aug 31, 2015 8:50 PM, "Akira Hatanaka via cfe-commits" <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">ahatanak created this revision.<br>
ahatanak added reviewers: echristo, dexonsmith.<br>
ahatanak added a subscriber: cfe-commits.<br>
<br>
Clang driver option -fno-zero-initialized-in-bss is used to prevent global variables that are initialized to zero from being placed in the bss section, but is currently ignored when doing LTO. This patch fixes this bug by passing -no-zero-initialized-in-bss on ld64's command line using -mllvm. If we agree on the approach this patch takes, I plan to make similar changes for gold's plugin.<br>
<br>
<a href="http://reviews.llvm.org/D12511" rel="noreferrer" target="_blank">http://reviews.llvm.org/D12511</a><br>
<br>
Files:<br>
  lib/Driver/Tools.cpp<br>
  test/Driver/no-zero-initialized-in-bss.c<br>
<br>
Index: test/Driver/no-zero-initialized-in-bss.c<br>
===================================================================<br>
--- /dev/null<br>
+++ test/Driver/no-zero-initialized-in-bss.c<br>
@@ -0,0 +1,11 @@<br>
+// RUN: %clang -### -c -fno-zero-initialized-in-bss %s 2>&1 | FileCheck -check-prefix CHECK-NO-ZERO %s<br>
+// RUN: %clang -### -c -fzero-initialized-in-bss %s 2>&1 | FileCheck -check-prefix CHECK-ZERO %s<br>
+// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix CHECK-ZERO %s<br>
+// 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<br>
+// 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<br>
+// RUN: %clang -### -flto -target x86_64-apple-darwin %s 2>&1 | FileCheck -check-prefix CHECK-ZERO-LTO-DARWIN %s<br>
+<br>
+// CHECK-NO-ZERO: -mno-zero-initialized-in-bss<br>
+// CHECK-ZERO-NOT: -mno-zero-initialized-in-bss<br>
+// CHECK-NO-ZERO-LTO-DARWIN: -mllvm -nozero-initialized-in-bss<br>
+// CHECK-ZERO-LTO-DARWIN-NOT: -mllvm -nozero-initialized-in-bss<br>
Index: lib/Driver/Tools.cpp<br>
===================================================================<br>
--- lib/Driver/Tools.cpp<br>
+++ lib/Driver/Tools.cpp<br>
@@ -6579,6 +6579,11 @@<br>
   Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name);<br>
   Args.AddLastArg(CmdArgs, options::OPT_dylinker);<br>
   Args.AddLastArg(CmdArgs, options::OPT_Mach);<br>
+<br>
+  if (D.IsUsingLTO(Args))<br>
+    if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss,<br>
+                      options::OPT_fno_zero_initialized_in_bss))<br>
+      CmdArgs.push_back("-mllvm -nozero-initialized-in-bss");<br>
 }<br>
<br>
 void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,<br>
<br>
<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div>