Skip to content

Commit ddbd2d4

Browse files
author
Sebastien Bourdeauducq
committedMay 29, 2012
Bare metal 'ELF' toolchain that runs as and ld directly
1 parent 6797c47 commit ddbd2d4

File tree

7 files changed

+179
-0
lines changed

7 files changed

+179
-0
lines changed
 

‎include/clang/Driver/HostInfo.h

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class HostInfo {
6565

6666
const HostInfo *createAuroraUXHostInfo(const Driver &D,
6767
const llvm::Triple& Triple);
68+
const HostInfo *createBareMetalHostInfo(const Driver &D,
69+
const llvm::Triple& Triple);
6870
const HostInfo *createDarwinHostInfo(const Driver &D,
6971
const llvm::Triple& Triple);
7072
const HostInfo *createOpenBSDHostInfo(const Driver &D,

‎lib/Driver/Driver.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,9 @@ const HostInfo *Driver::GetHostInfo(const char *TripleStr) const {
15741574
llvm::PrettyStackTraceString CrashInfo("Constructing host");
15751575
llvm::Triple Triple(llvm::Triple::normalize(TripleStr).c_str());
15761576

1577+
if (Triple.getEnvironment() == llvm::Triple::ELF)
1578+
return createBareMetalHostInfo(*this, Triple);
1579+
15771580
// TCE is an osless target
15781581
if (Triple.getArchName() == "tce")
15791582
return createTCEHostInfo(*this, Triple);

‎lib/Driver/HostInfo.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,54 @@ HostInfo::~HostInfo() {
3434

3535
namespace {
3636

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+
3785
// Darwin Host Info
3886

3987
/// DarwinHostInfo - Darwin host information implementation.
@@ -669,6 +717,12 @@ clang::driver::createAuroraUXHostInfo(const Driver &D,
669717
return new AuroraUXHostInfo(D, Triple);
670718
}
671719

720+
const HostInfo *
721+
clang::driver::createBareMetalHostInfo(const Driver &D,
722+
const llvm::Triple& Triple) {
723+
return new BareMetalHostInfo(D, Triple);
724+
}
725+
672726
const HostInfo *
673727
clang::driver::createDarwinHostInfo(const Driver &D,
674728
const llvm::Triple& Triple){

‎lib/Driver/ToolChains.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,36 @@ const char *Generic_GCC::GetDefaultRelocationModel() const {
14061406
const char *Generic_GCC::GetForcedPicModel() const {
14071407
return 0;
14081408
}
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+
14091439
/// Hexagon Toolchain
14101440

14111441
Hexagon_TC::Hexagon_TC(const HostInfo &Host, const llvm::Triple& Triple)

‎lib/Driver/ToolChains.h

+8
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,14 @@ class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
442442
const ActionList &Inputs) const;
443443
};
444444

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+
445453
class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
446454
public:
447455
OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);

‎lib/Driver/Tools.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,58 @@ void gcc::Link::RenderExtraToolArgs(const JobAction &JA,
26592659
// The types are (hopefully) good enough.
26602660
}
26612661

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+
26622714
// Hexagon tools start.
26632715
void hexagon::Assemble::RenderExtraToolArgs(const JobAction &JA,
26642716
ArgStringList &CmdArgs) const {

‎lib/Driver/Tools.h

+30
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,36 @@ namespace gcc {
153153
};
154154
} // end namespace gcc
155155

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+
156186
namespace hexagon {
157187
// For Hexagon, we do not need to instantiate tools for PreProcess, PreCompile and Compile.
158188
// We simply use "clang -cc1" for those actions.

0 commit comments

Comments
 (0)
Please sign in to comment.