r247981 - Pass the relocation model to LLVM for assembler files.

Joerg Sonnenberger via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 18 04:13:44 PDT 2015


Author: joerg
Date: Fri Sep 18 06:13:43 2015
New Revision: 247981

URL: http://llvm.org/viewvc/llvm-project?rev=247981&view=rev
Log:
Pass the relocation model to LLVM for assembler files.

Modified:
    cfe/trunk/lib/CodeGen/BackendUtil.cpp
    cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=247981&r1=247980&r2=247981&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Fri Sep 18 06:13:43 2015
@@ -463,6 +463,7 @@ TargetMachine *EmitAssemblyHelper::Creat
     FeaturesStr = Features.getString();
   }
 
+  // Keep this synced with the equivalent code in tools/driver/cc1as_main.cpp.
   llvm::Reloc::Model RM = llvm::Reloc::Default;
   if (CodeGenOpts.RelocationModel == "static") {
     RM = llvm::Reloc::Static;

Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=247981&r1=247980&r2=247981&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Fri Sep 18 06:13:43 2015
@@ -126,6 +126,9 @@ struct AssemblerInvocation {
   unsigned NoExecStack : 1;
   unsigned FatalWarnings : 1;
 
+  /// The name of the relocation model to use.
+  std::string RelocationModel;
+
   /// @}
 
 public:
@@ -248,6 +251,7 @@ bool AssemblerInvocation::CreateFromArgs
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
   Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
+  Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");
 
   return Success;
 }
@@ -321,8 +325,19 @@ static bool ExecuteAssembler(AssemblerIn
   std::unique_ptr<MCObjectFileInfo> MOFI(new MCObjectFileInfo());
 
   MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr);
-  // FIXME: Assembler behavior can change with -static.
-  MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), Reloc::Default,
+
+  llvm::Reloc::Model RM = llvm::Reloc::Default;
+  if (Opts.RelocationModel == "static") {
+    RM = llvm::Reloc::Static;
+  } else if (Opts.RelocationModel == "pic") {
+    RM = llvm::Reloc::PIC_;
+  } else {
+    assert(Opts.RelocationModel == "dynamic-no-pic" &&
+           "Invalid PIC model!");
+    RM = llvm::Reloc::DynamicNoPIC;
+  }
+
+  MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), RM,
                              CodeModel::Default, Ctx);
   if (Opts.SaveTemporaryLabels)
     Ctx.setAllowTemporaryLabels(false);




More information about the cfe-commits mailing list