Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bare metal 'ELF' toolchain that runs as and ld directly

  • Loading branch information...
commit ddbd2d49c5cfc2ec56da676a74a9cdc6d6611806 1 parent 6797c47
Sébastien Bourdeauducq authored May 29, 2012
2  include/clang/Driver/HostInfo.h
@@ -65,6 +65,8 @@ class HostInfo {
65 65
 
66 66
 const HostInfo *createAuroraUXHostInfo(const Driver &D,
67 67
                                        const llvm::Triple& Triple);
  68
+const HostInfo *createBareMetalHostInfo(const Driver &D,
  69
+                                      const llvm::Triple& Triple);
68 70
 const HostInfo *createDarwinHostInfo(const Driver &D,
69 71
                                      const llvm::Triple& Triple);
70 72
 const HostInfo *createOpenBSDHostInfo(const Driver &D,
3  lib/Driver/Driver.cpp
@@ -1574,6 +1574,9 @@ const HostInfo *Driver::GetHostInfo(const char *TripleStr) const {
1574 1574
   llvm::PrettyStackTraceString CrashInfo("Constructing host");
1575 1575
   llvm::Triple Triple(llvm::Triple::normalize(TripleStr).c_str());
1576 1576
 
  1577
+  if (Triple.getEnvironment() == llvm::Triple::ELF)
  1578
+    return createBareMetalHostInfo(*this, Triple);
  1579
+  
1577 1580
   // TCE is an osless target
1578 1581
   if (Triple.getArchName() == "tce")
1579 1582
     return createTCEHostInfo(*this, Triple);
54  lib/Driver/HostInfo.cpp
@@ -34,6 +34,54 @@ HostInfo::~HostInfo() {
34 34
 
35 35
 namespace {
36 36
 
  37
+// Bare metal Host Info
  38
+
  39
+/// BareMetalHostInfo -  Bare metal host information implementation.
  40
+class BareMetalHostInfo : public HostInfo {
  41
+  /// Cache of tool chains we have created.
  42
+  mutable llvm::StringMap<ToolChain*> ToolChains;
  43
+
  44
+public:
  45
+  BareMetalHostInfo(const Driver &D, const llvm::Triple& Triple)
  46
+    : HostInfo(D, Triple) {}
  47
+  ~BareMetalHostInfo();
  48
+
  49
+  virtual bool useDriverDriver() const;
  50
+
  51
+  virtual ToolChain *CreateToolChain(const ArgList &Args,
  52
+                                     const char *ArchName) const;
  53
+};
  54
+
  55
+BareMetalHostInfo::~BareMetalHostInfo() {
  56
+  for (llvm::StringMap<ToolChain*>::iterator
  57
+         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it){
  58
+    delete it->second;
  59
+  }
  60
+}
  61
+
  62
+bool BareMetalHostInfo::useDriverDriver() const {
  63
+  return false;
  64
+}
  65
+
  66
+ToolChain *BareMetalHostInfo::CreateToolChain(const ArgList &Args,
  67
+                                            const char *ArchName) const {
  68
+  assert(!ArchName &&
  69
+         "Unexpected arch name on platform without driver driver support.");
  70
+
  71
+  std::string Arch = getArchName();
  72
+  ArchName = Arch.c_str();
  73
+
  74
+  ToolChain *&TC = ToolChains[ArchName];
  75
+  if (!TC) {
  76
+    llvm::Triple TCTriple(getTriple());
  77
+    TCTriple.setArchName(ArchName);
  78
+
  79
+    TC = new toolchains::BareMetal(*this, TCTriple);
  80
+  }
  81
+
  82
+  return TC;
  83
+}
  84
+
37 85
 // Darwin Host Info
38 86
 
39 87
 /// DarwinHostInfo - Darwin host information implementation.
@@ -670,6 +718,12 @@ clang::driver::createAuroraUXHostInfo(const Driver &D,
670 718
 }
671 719
 
672 720
 const HostInfo *
  721
+clang::driver::createBareMetalHostInfo(const Driver &D,
  722
+                                     const llvm::Triple& Triple) {
  723
+  return new BareMetalHostInfo(D, Triple);
  724
+}
  725
+
  726
+const HostInfo *
673 727
 clang::driver::createDarwinHostInfo(const Driver &D,
674 728
                                     const llvm::Triple& Triple){
675 729
   return new DarwinHostInfo(D, Triple);
30  lib/Driver/ToolChains.cpp
@@ -1406,6 +1406,36 @@ const char *Generic_GCC::GetDefaultRelocationModel() const {
1406 1406
 const char *Generic_GCC::GetForcedPicModel() const {
1407 1407
   return 0;
1408 1408
 }
  1409
+
  1410
+/// BareMetal - Bare metal tool chain which can call as(1) and ld(1) directly.
  1411
+
  1412
+BareMetal::BareMetal(const HostInfo &Host, const llvm::Triple& Triple)
  1413
+  : Generic_ELF(Host, Triple) {
  1414
+}
  1415
+
  1416
+Tool &BareMetal::SelectTool(const Compilation &C, const JobAction &JA,
  1417
+                        const ActionList &Inputs) const {
  1418
+  Action::ActionClass Key;
  1419
+  if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
  1420
+    Key = Action::AnalyzeJobClass;
  1421
+  else
  1422
+    Key = JA.getKind();
  1423
+
  1424
+  Tool *&T = Tools[Key];
  1425
+  if (!T) {
  1426
+    switch (Key) {
  1427
+    case Action::AssembleJobClass:
  1428
+      T = new tools::baremetal::Assemble(*this); break;
  1429
+    case Action::LinkJobClass:
  1430
+      T = new tools::baremetal::Link(*this); break;
  1431
+    default:
  1432
+      T = &Generic_GCC::SelectTool(C, JA, Inputs);
  1433
+    }
  1434
+  }
  1435
+
  1436
+  return *T;
  1437
+}
  1438
+
1409 1439
 /// Hexagon Toolchain
1410 1440
 
1411 1441
 Hexagon_TC::Hexagon_TC(const HostInfo &Host, const llvm::Triple& Triple)
8  lib/Driver/ToolChains.h
@@ -442,6 +442,14 @@ class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
442 442
                            const ActionList &Inputs) const;
443 443
 };
444 444
 
  445
+class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF {
  446
+public:
  447
+  BareMetal(const HostInfo &Host, const llvm::Triple& Triple);
  448
+
  449
+  virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
  450
+                           const ActionList &Inputs) const;
  451
+};
  452
+
445 453
 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
446 454
 public:
447 455
   OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
52  lib/Driver/Tools.cpp
@@ -2659,6 +2659,58 @@ void gcc::Link::RenderExtraToolArgs(const JobAction &JA,
2659 2659
   // The types are (hopefully) good enough.
2660 2660
 }
2661 2661
 
  2662
+/// Bare metal Tools
  2663
+
  2664
+void baremetal::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
  2665
+                                   const InputInfo &Output,
  2666
+                                   const InputInfoList &Inputs,
  2667
+                                   const ArgList &Args,
  2668
+                                   const char *LinkingOutput) const {
  2669
+  ArgStringList CmdArgs;
  2670
+
  2671
+  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
  2672
+                       options::OPT_Xassembler);
  2673
+
  2674
+  CmdArgs.push_back("-o");
  2675
+  CmdArgs.push_back(Output.getFilename());
  2676
+
  2677
+  for (InputInfoList::const_iterator
  2678
+         it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
  2679
+    const InputInfo &II = *it;
  2680
+    CmdArgs.push_back(II.getFilename());
  2681
+  }
  2682
+
  2683
+  const char *Exec =
  2684
+    Args.MakeArgString(getToolChain().GetProgramPath("as"));
  2685
+  C.addCommand(new Command(JA, *this, Exec, CmdArgs));
  2686
+}
  2687
+
  2688
+void baremetal::Link::ConstructJob(Compilation &C, const JobAction &JA,
  2689
+                               const InputInfo &Output,
  2690
+                               const InputInfoList &Inputs,
  2691
+                               const ArgList &Args,
  2692
+                               const char *LinkingOutput) const {
  2693
+  ArgStringList CmdArgs;
  2694
+
  2695
+  if (Output.isFilename()) {
  2696
+    CmdArgs.push_back("-o");
  2697
+    CmdArgs.push_back(Output.getFilename());
  2698
+  } else {
  2699
+    assert(Output.isNothing() && "Invalid output.");
  2700
+  }
  2701
+
  2702
+  Args.AddAllArgs(CmdArgs, options::OPT_L);
  2703
+  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
  2704
+  Args.AddAllArgs(CmdArgs, options::OPT_e);
  2705
+
  2706
+  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
  2707
+
  2708
+  addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
  2709
+
  2710
+  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("ld"));
  2711
+  C.addCommand(new Command(JA, *this, Exec, CmdArgs));
  2712
+}
  2713
+
2662 2714
 // Hexagon tools start.
2663 2715
 void hexagon::Assemble::RenderExtraToolArgs(const JobAction &JA,
2664 2716
                                         ArgStringList &CmdArgs) const {
30  lib/Driver/Tools.h
@@ -153,6 +153,36 @@ namespace gcc {
153 153
   };
154 154
 } // end namespace gcc
155 155
 
  156
+  /// baremetal -- Directly call GNU Binutils assembler and linker
  157
+namespace baremetal {
  158
+  class LLVM_LIBRARY_VISIBILITY Assemble : public Tool  {
  159
+  public:
  160
+    Assemble(const ToolChain &TC) : Tool("baremetal::Assemble", "assembler",
  161
+                                         TC) {}
  162
+
  163
+    virtual bool hasIntegratedCPP() const { return false; }
  164
+
  165
+    virtual void ConstructJob(Compilation &C, const JobAction &JA,
  166
+                              const InputInfo &Output,
  167
+                              const InputInfoList &Inputs,
  168
+                              const ArgList &TCArgs,
  169
+                              const char *LinkingOutput) const;
  170
+  };
  171
+  class LLVM_LIBRARY_VISIBILITY Link : public Tool  {
  172
+  public:
  173
+    Link(const ToolChain &TC) : Tool("baremetal::Link", "linker", TC) {}
  174
+
  175
+    virtual bool hasIntegratedCPP() const { return false; }
  176
+
  177
+    virtual void ConstructJob(Compilation &C, const JobAction &JA,
  178
+                              const InputInfo &Output,
  179
+                              const InputInfoList &Inputs,
  180
+                              const ArgList &TCArgs,
  181
+                              const char *LinkingOutput) const;
  182
+  };
  183
+} // end namespace baremetal
  184
+
  185
+
156 186
 namespace hexagon {
157 187
   // For Hexagon, we do not need to instantiate tools for PreProcess, PreCompile and Compile.
158 188
   // We simply use "clang -cc1" for those actions.

0 notes on commit ddbd2d4

Please sign in to comment.
Something went wrong with that request. Please try again.