[PATCH] D12511: [LTO] Pass -no-zero-initialized-in-bss on linker command line

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 31 17:50:23 PDT 2015


ahatanak created this revision.
ahatanak added reviewers: echristo, dexonsmith.
ahatanak added a subscriber: cfe-commits.

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. 

http://reviews.llvm.org/D12511

Files:
  lib/Driver/Tools.cpp
  test/Driver/no-zero-initialized-in-bss.c

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
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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12511.33648.patch
Type: text/x-patch
Size: 1782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150901/09e7eb2d/attachment.bin>


More information about the cfe-commits mailing list