r271162 - Handle -Wa,--mrelax-relocations=[no|yes].
Rafael Espindola via cfe-commits
cfe-commits at lists.llvm.org
Sat May 28 19:01:15 PDT 2016
Author: rafael
Date: Sat May 28 21:01:14 2016
New Revision: 271162
URL: http://llvm.org/viewvc/llvm-project?rev=271162&view=rev
Log:
Handle -Wa,--mrelax-relocations=[no|yes].
Added:
cfe/trunk/test/CodeGen/relax.c
cfe/trunk/test/Driver/relax.c
cfe/trunk/test/Driver/relax.s
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/tools/driver/cc1as_main.cpp
Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=271162&r1=271161&r2=271162&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Sat May 28 21:01:14 2016
@@ -143,6 +143,8 @@ def mno_exec_stack : Flag<["-"], "mnoexe
HelpText<"Mark the file as not needing an executable stack">;
def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
HelpText<"Make assembler warnings fatal">;
+def mrelax_relocations : Flag<["--"], "mrelax-relocations">,
+ HelpText<"Use relaxabel elf relocations">;
def compress_debug_sections : Flag<["-"], "compress-debug-sections">,
HelpText<"Compress DWARF debug sections using zlib">;
def msave_temp_labels : Flag<["-"], "msave-temp-labels">,
Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=271162&r1=271161&r2=271162&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Sat May 28 21:01:14 2016
@@ -30,6 +30,7 @@ CODEGENOPT(Name, Bits, Default)
CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
CODEGENOPT(CompressDebugSections, 1, 0) ///< -Wa,-compress-debug-sections
+CODEGENOPT(RelaxELFRelocations, 1, 0) ///< -Wa,--mrelax-relocations
CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm.
CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) operator new
CODEGENOPT(Autolink , 1, 1) ///< -fno-autolink
Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=271162&r1=271161&r2=271162&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Sat May 28 21:01:14 2016
@@ -593,6 +593,7 @@ TargetMachine *EmitAssemblyHelper::Creat
Options.UseInitArray = CodeGenOpts.UseInitArray;
Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
Options.CompressDebugSections = CodeGenOpts.CompressDebugSections;
+ Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
// Set EABI version.
Options.EABIVersion = llvm::StringSwitch<llvm::EABI>(TargetOpts.EABIVersion)
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=271162&r1=271161&r2=271162&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Sat May 28 21:01:14 2016
@@ -2797,6 +2797,8 @@ static void CollectArgsForIntegratedAsse
// When using an integrated assembler, translate -Wa, and -Xassembler
// options.
bool CompressDebugSections = false;
+
+ bool UseRelaxRelocations = false;
const char *MipsTargetFeature = nullptr;
for (const Arg *A :
Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
@@ -2872,6 +2874,12 @@ static void CollectArgsForIntegratedAsse
} else if (Value == "-nocompress-debug-sections" ||
Value == "--nocompress-debug-sections") {
CompressDebugSections = false;
+ } else if (Value == "-mrelax-relocations=yes" ||
+ Value == "--mrelax-relocations=yes") {
+ UseRelaxRelocations = true;
+ } else if (Value == "-mrelax-relocations=no" ||
+ Value == "--mrelax-relocations=no") {
+ UseRelaxRelocations = false;
} else if (Value.startswith("-I")) {
CmdArgs.push_back(Value.data());
// We need to consume the next argument if the current arg is a plain
@@ -2903,6 +2911,8 @@ static void CollectArgsForIntegratedAsse
else
D.Diag(diag::warn_debug_compression_unavailable);
}
+ if (UseRelaxRelocations)
+ CmdArgs.push_back("--mrelax-relocations");
if (MipsTargetFeature != nullptr) {
CmdArgs.push_back("-target-feature");
CmdArgs.push_back(MipsTargetFeature);
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=271162&r1=271161&r2=271162&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Sat May 28 21:01:14 2016
@@ -683,6 +683,7 @@ static bool ParseCodeGenArgs(CodeGenOpti
Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info);
Opts.CompressDebugSections = Args.hasArg(OPT_compress_debug_sections);
+ Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
for (auto A : Args.filtered(OPT_mlink_bitcode_file, OPT_mlink_cuda_bitcode)) {
unsigned LinkFlags = llvm::Linker::Flags::None;
Added: cfe/trunk/test/CodeGen/relax.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/relax.c?rev=271162&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/relax.c (added)
+++ cfe/trunk/test/CodeGen/relax.c Sat May 28 21:01:14 2016
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-obj --mrelax-relocations %s -mrelocation-model pic -o %t
+// RUN: llvm-readobj -r %t | FileCheck %s
+
+// CHECK: R_X86_64_REX_GOTPCRELX foo
+
+extern int foo;
+int *f(void) {
+ return &foo;
+}
Added: cfe/trunk/test/Driver/relax.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/relax.c?rev=271162&view=auto
==============================================================================
--- cfe/trunk/test/Driver/relax.c (added)
+++ cfe/trunk/test/Driver/relax.c Sat May 28 21:01:14 2016
@@ -0,0 +1,4 @@
+// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=yes %s 2>&1 | FileCheck %s
+
+// CHECK: "-cc1"
+// CHECK: "--mrelax-relocations"
Added: cfe/trunk/test/Driver/relax.s
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/relax.s?rev=271162&view=auto
==============================================================================
--- cfe/trunk/test/Driver/relax.s (added)
+++ cfe/trunk/test/Driver/relax.s Sat May 28 21:01:14 2016
@@ -0,0 +1,12 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=yes %s 2>&1 | FileCheck %s
+
+// CHECK: "-cc1as"
+// CHECK: "--mrelax-relocations"
+
+// RUN: %clang -cc1as -triple x86_64-pc-linux --mrelax-relocations %s -o %t -filetype obj
+// RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s
+
+// REL: R_X86_64_REX_GOTPCRELX foo
+
+ movq foo at GOTPCREL(%rip), %rax
Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=271162&r1=271161&r2=271162&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Sat May 28 21:01:14 2016
@@ -88,6 +88,7 @@ struct AssemblerInvocation {
unsigned SaveTemporaryLabels : 1;
unsigned GenDwarfForAssembly : 1;
unsigned CompressDebugSections : 1;
+ unsigned RelaxELFRelocations : 1;
unsigned DwarfVersion;
std::string DwarfDebugFlags;
std::string DwarfDebugProducer;
@@ -200,6 +201,7 @@ bool AssemblerInvocation::CreateFromArgs
// Any DebugInfoKind implies GenDwarfForAssembly.
Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ);
Opts.CompressDebugSections = Args.hasArg(OPT_compress_debug_sections);
+ Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
Opts.DwarfDebugProducer = Args.getLastArgValue(OPT_dwarf_debug_producer);
@@ -315,6 +317,8 @@ static bool ExecuteAssembler(AssemblerIn
if (Opts.CompressDebugSections)
MAI->setCompressDebugSections(DebugCompressionType::DCT_ZlibGnu);
+ MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations);
+
bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj;
std::unique_ptr<raw_fd_ostream> FDOS = getOutputStream(Opts, Diags, IsBinary);
if (!FDOS)
More information about the cfe-commits
mailing list