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: 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/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: 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: 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/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);