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

Rafael EspĂ­ndola via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 31 18:37:06 PDT 2015


Looks like something that should be in the bitcode, no? What happens if one
compile unit has it and another one doesn't?
On Aug 31, 2015 8:50 PM, "Akira Hatanaka via cfe-commits" <
cfe-commits at lists.llvm.org> wrote:

> 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,
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150831/6fa29003/attachment.html>


More information about the cfe-commits mailing list