[PATCH] D19996: New clang option -mpiecopyrelocs to indicate support for linker copy relocations when linking as PIE
Sriraman Tallam via cfe-commits
cfe-commits at lists.llvm.org
Thu May 5 14:25:28 PDT 2016
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<llvm::PIELevel::Level>(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<m_Group>;
def mrecip : Flag<["-"], "mrecip">, Group<m_Group>;
def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group<m_Group>, Flags<[CC1Option]>;
+def mpiecopyrelocs : Flag<["-"], "mpiecopyrelocs">, Group<m_Group>;
+def mno_piecopyrelocs : Flag<["-"], "mno-piecopyrelocs">, Group<m_Group>;
def msse2 : Flag<["-"], "msse2">, Group<m_x86_Features_Group>;
def msse3 : Flag<["-"], "msse3">, Group<m_x86_Features_Group>;
def msse4a : Flag<["-"], "msse4a">, Group<m_x86_Features_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">,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19996.56347.patch
Type: text/x-patch
Size: 3585 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160505/0f92856a/attachment-0001.bin>
More information about the cfe-commits
mailing list