From ddce362ad47085ba3f723b14b40f2cd0ae3cd50c Mon Sep 17 00:00:00 2001 From: Sriraman Tallam Date: Wed, 19 Oct 2016 20:24:06 +0000 Subject: [PATCH] New clang option -mpie-copy-relocations to use copy relocations for PIE builds. Differential Revision: https://reviews.llvm.org/D19996 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284638 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 4 ++++ include/clang/Frontend/CodeGenOptions.def | 3 +++ lib/CodeGen/BackendUtil.cpp | 2 ++ lib/Driver/Tools.cpp | 6 ++++++ lib/Frontend/CompilerInvocation.cpp | 2 ++ 5 files changed, 17 insertions(+) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 56dfc6de26..02ddda7677 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1691,6 +1691,10 @@ def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group, def mimplicit_float : Flag<["-"], "mimplicit-float">, Group; def mrecip : Flag<["-"], "mrecip">, Group; def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, Flags<[CC1Option]>; +def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">, Group, + Flags<[CC1Option]>, + HelpText<"Use copy relocations support for PIE builds">; +def mno_pie_copy_relocations : Flag<["-"], "mno-pie-copy-relocations">, Group; def mx87 : Flag<["-"], "mx87">, Group; def m80387 : Flag<["-"], "m80387">, Alias; def msse2 : Flag<["-"], "msse2">, Group; diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 81307ac7b6..e33ec9e32c 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -252,6 +252,9 @@ VALUE_CODEGENOPT(EmitCheckPathComponentsToStrip, 32, 0) /// Whether to report the hotness of the code region for optimization remarks. CODEGENOPT(DiagnosticsWithHotness, 1, 0) +/// Whether copy relocations support is available when building as PIE. +CODEGENOPT(PIECopyRelocations, 1, 0) + #undef CODEGENOPT #undef ENUM_CODEGENOPT #undef VALUE_CODEGENOPT diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 346aa0beb1..367cace096 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -595,6 +595,8 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) { Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack; Options.MCOptions.MCIncrementalLinkerCompatible = CodeGenOpts.IncrementalLinkerCompatible; + Options.MCOptions.MCPIECopyRelocations = + CodeGenOpts.PIECopyRelocations; Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings; Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose; Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 33fa9ebad7..e6bfae68ee 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -4499,6 +4499,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-mms-bitfields"); } + if (Args.hasFlag(options::OPT_mpie_copy_relocations, + options::OPT_mno_pie_copy_relocations, + false)) { + CmdArgs.push_back("-mpie-copy-relocations"); + } + // This is a coarse approximation of what llvm-gcc actually does, both // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more // complicated ways. diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 39588e8af8..03d400b9ca 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -586,6 +586,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.RelaxAll = Args.hasArg(OPT_mrelax_all); Opts.IncrementalLinkerCompatible = Args.hasArg(OPT_mincremental_linker_compatible); + Opts.PIECopyRelocations = + Args.hasArg(OPT_mpie_copy_relocations); Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels); Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm); -- 2.40.0