Re: [PATCH] D19996: New clang option -mpiecopyrelocs to indicate support for linker copy relocations when linking as PIE

2016-05-10 Thread Sean Silva via cfe-commits
If this is something that GCC doesn't have, it would be nice if we put
something in our own docs about it (something like docs/UsersManual.rst).

On Thu, May 5, 2016 at 2:34 PM, Sriraman Tallam via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Thu, May 5, 2016 at 2:31 PM, Rafael Espíndola
>  wrote:
> > Is there a gcc option or they just assume they are targeting the
> > linker that was around when gcc was built?
>
> It is done at configure time, the linker is checked for copy
> relocations support.  I recently saw a request to replace this with a
> flag like -mpiecopyrelocs.  I chatted off-line with Reid about this
> and a flag was suggested.
>
> >
> >
> >> +  if (Args.hasFlag(options::OPT_mpiecopyrelocs,
> options::OPT_mno_piecopyrelocs,
> >> +   false)) {
> >> +CmdArgs.push_back("-piecopyrelocs");
> >> +  }
> >
> > you don't need the {}
> >
> >> +def piecopyrelocs : Flag<["-"], "piecopyrelocs">,
> >> +  HelpText<"Linker copy relocations support when linking as PIE">;
> >
> > I think you are missing a verb: Linker copy relocations *are* supported.
> >
> > But how about just "Position independent executables can have copy
> relocations"?
> >
> > Cheers,
> > Rafael
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19996: New clang option -mpiecopyrelocs to indicate support for linker copy relocations when linking as PIE

2016-05-05 Thread Sriraman Tallam via cfe-commits
On Thu, May 5, 2016 at 2:31 PM, Rafael Espíndola
 wrote:
> Is there a gcc option or they just assume they are targeting the
> linker that was around when gcc was built?

It is done at configure time, the linker is checked for copy
relocations support.  I recently saw a request to replace this with a
flag like -mpiecopyrelocs.  I chatted off-line with Reid about this
and a flag was suggested.

>
>
>> +  if (Args.hasFlag(options::OPT_mpiecopyrelocs, 
>> options::OPT_mno_piecopyrelocs,
>> +   false)) {
>> +CmdArgs.push_back("-piecopyrelocs");
>> +  }
>
> you don't need the {}
>
>> +def piecopyrelocs : Flag<["-"], "piecopyrelocs">,
>> +  HelpText<"Linker copy relocations support when linking as PIE">;
>
> I think you are missing a verb: Linker copy relocations *are* supported.
>
> But how about just "Position independent executables can have copy 
> relocations"?
>
> Cheers,
> Rafael
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19996: New clang option -mpiecopyrelocs to indicate support for linker copy relocations when linking as PIE

2016-05-05 Thread Rafael Espíndola via cfe-commits
Is there a gcc option or they just assume they are targeting the
linker that was around when gcc was built?


> +  if (Args.hasFlag(options::OPT_mpiecopyrelocs, 
> options::OPT_mno_piecopyrelocs,
> +   false)) {
> +CmdArgs.push_back("-piecopyrelocs");
> +  }

you don't need the {}

> +def piecopyrelocs : Flag<["-"], "piecopyrelocs">,
> +  HelpText<"Linker copy relocations support when linking as PIE">;

I think you are missing a verb: Linker copy relocations *are* supported.

But how about just "Position independent executables can have copy relocations"?

Cheers,
Rafael
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19996: New clang option -mpiecopyrelocs to indicate support for linker copy relocations when linking as PIE

2016-05-05 Thread Sriraman Tallam via cfe-commits
tmsriram created this revision.
tmsriram added a reviewer: rnk.
tmsriram added subscribers: cfe-commits, davidxl, rafael.

With linker copy relocations, PIE can generate better code for external global 
variable accesses.  This patch adds a new option to clang to specify this.  
Please see  http://reviews.llvm.org/D19995  for the patch to LLVM to optimize 
global accesses when this is available. With this option, the module flag "PIE 
Copy Relocations" is set.

http://reviews.llvm.org/D19996

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -570,6 +570,7 @@
   Opts.SoftFloat = Args.hasArg(OPT_msoft_float);
   Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums);
   Opts.StrictVTablePointers = Args.hasArg(OPT_fstrict_vtable_pointers);
+  Opts.PIECopyRelocs = Args.hasArg(OPT_piecopyrelocs);
   Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
   Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
   Args.hasArg(OPT_cl_fast_relaxed_math);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4161,6 +4161,11 @@
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Args.hasFlag(options::OPT_mpiecopyrelocs, options::OPT_mno_piecopyrelocs,
+   false)) {
+CmdArgs.push_back("-piecopyrelocs");
+  }
+
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -484,6 +484,8 @@
   if (uint32_t PLevel = Context.getLangOpts().PIELevel) {
 assert(PLevel < 3 && "Invalid PIE Level");
 getModule().setPIELevel(static_cast(PLevel));
+if (CodeGenOpts.PIECopyRelocs)
+  getModule().setPIECopyRelocs();
   }
 
   SimplifyPersonality();
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -222,6 +222,8 @@
 /// The default TLS model to use.
 ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel)
 
+CODEGENOPT(PIECopyRelocs, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1544,6 +1544,8 @@
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>;
+def mpiecopyrelocs : Flag<["-"], "mpiecopyrelocs">, Group;
+def mno_piecopyrelocs : Flag<["-"], "mno-piecopyrelocs">, Group;
 def msse2 : Flag<["-"], "msse2">, Group;
 def msse3 : Flag<["-"], "msse3">, Group;
 def msse4a : Flag<["-"], "msse4a">, Group;
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -175,6 +175,8 @@
 def dwarf_ext_refs : Flag<["-"], "dwarf-ext-refs">,
   HelpText<"Generate debug info with external references to clang modules"
" or precompiled headers">;
+def piecopyrelocs : Flag<["-"], "piecopyrelocs">,
+  HelpText<"Linker copy relocations support when linking as PIE">;
 def fforbid_guard_variables : Flag<["-"], "fforbid-guard-variables">,
   HelpText<"Emit an error if a C++ static local initializer would need a guard 
variable">;
 def no_implicit_float : Flag<["-"], "no-implicit-float">,


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -570,6 +570,7 @@
   Opts.SoftFloat = Args.hasArg(OPT_msoft_float);
   Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums);
   Opts.StrictVTablePointers = Args.hasArg(OPT_fstrict_vtable_pointers);
+  Opts.PIECopyRelocs = Args.hasArg(OPT_piecopyrelocs);
   Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
   Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
   Args.hasArg(OPT_cl_fast_relaxed_math);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4161,6 +4161,11 @@
 CmdArgs.push