1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #include "CloudABI.h" |
10 | #include "InputInfo.h" |
11 | #include "CommonArgs.h" |
12 | #include "clang/Driver/Compilation.h" |
13 | #include "clang/Driver/Driver.h" |
14 | #include "clang/Driver/Options.h" |
15 | #include "llvm/ADT/SmallString.h" |
16 | #include "llvm/Option/ArgList.h" |
17 | #include "llvm/Support/Path.h" |
18 | |
19 | using namespace clang::driver; |
20 | using namespace clang::driver::tools; |
21 | using namespace clang::driver::toolchains; |
22 | using namespace clang; |
23 | using namespace llvm::opt; |
24 | |
25 | void cloudabi::Linker::ConstructJob(Compilation &C, const JobAction &JA, |
26 | const InputInfo &Output, |
27 | const InputInfoList &Inputs, |
28 | const ArgList &Args, |
29 | const char *LinkingOutput) const { |
30 | const ToolChain &ToolChain = getToolChain(); |
31 | const Driver &D = ToolChain.getDriver(); |
32 | ArgStringList CmdArgs; |
33 | |
34 | |
35 | Args.ClaimAllArgs(options::OPT_g_Group); |
36 | |
37 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
38 | |
39 | |
40 | Args.ClaimAllArgs(options::OPT_w); |
41 | |
42 | if (!D.SysRoot.empty()) |
43 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
44 | |
45 | |
46 | CmdArgs.push_back("-Bstatic"); |
47 | CmdArgs.push_back("--no-dynamic-linker"); |
48 | |
49 | |
50 | if (ToolChain.isPIEDefault()) { |
51 | CmdArgs.push_back("-pie"); |
52 | CmdArgs.push_back("-zrelro"); |
53 | } |
54 | |
55 | CmdArgs.push_back("--eh-frame-hdr"); |
56 | CmdArgs.push_back("--gc-sections"); |
57 | |
58 | if (Output.isFilename()) { |
59 | CmdArgs.push_back("-o"); |
60 | CmdArgs.push_back(Output.getFilename()); |
61 | } else { |
62 | (0) . __assert_fail ("Output.isNothing() && \"Invalid output.\"", "/home/seafit/code_projects/clang_source/clang/lib/Driver/ToolChains/CloudABI.cpp", 62, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Output.isNothing() && "Invalid output."); |
63 | } |
64 | |
65 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { |
66 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o"))); |
67 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o"))); |
68 | } |
69 | |
70 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
71 | ToolChain.AddFilePathLibArgs(Args, CmdArgs); |
72 | Args.AddAllArgs(CmdArgs, |
73 | {options::OPT_T_Group, options::OPT_e, options::OPT_s, |
74 | options::OPT_t, options::OPT_Z_Flag, options::OPT_r}); |
75 | |
76 | if (D.isUsingLTO()) { |
77 | (0) . __assert_fail ("!Inputs.empty() && \"Must have at least one input.\"", "/home/seafit/code_projects/clang_source/clang/lib/Driver/ToolChains/CloudABI.cpp", 77, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!Inputs.empty() && "Must have at least one input."); |
78 | AddGoldPlugin(ToolChain, Args, CmdArgs, Output, Inputs[0], |
79 | D.getLTOMode() == LTOK_Thin); |
80 | } |
81 | |
82 | AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); |
83 | |
84 | if (ToolChain.ShouldLinkCXXStdlib(Args)) |
85 | ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
86 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { |
87 | CmdArgs.push_back("-lc"); |
88 | CmdArgs.push_back("-lcompiler_rt"); |
89 | } |
90 | |
91 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) |
92 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); |
93 | |
94 | const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); |
95 | C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); |
96 | } |
97 | |
98 | |
99 | |
100 | CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, |
101 | const ArgList &Args) |
102 | : Generic_ELF(D, Triple, Args) { |
103 | SmallString<128> P(getDriver().Dir); |
104 | llvm::sys::path::append(P, "..", getTriple().str(), "lib"); |
105 | getFilePaths().push_back(P.str()); |
106 | } |
107 | |
108 | void CloudABI::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
109 | llvm::opt::ArgStringList &CC1Args) const { |
110 | SmallString<128> P(getDriver().Dir); |
111 | llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); |
112 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
113 | } |
114 | |
115 | void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, |
116 | ArgStringList &CmdArgs) const { |
117 | CmdArgs.push_back("-lc++"); |
118 | CmdArgs.push_back("-lc++abi"); |
119 | CmdArgs.push_back("-lunwind"); |
120 | } |
121 | |
122 | Tool *CloudABI::buildLinker() const { |
123 | return new tools::cloudabi::Linker(*this); |
124 | } |
125 | |
126 | bool CloudABI::isPIEDefault() const { |
127 | |
128 | |
129 | |
130 | switch (getTriple().getArch()) { |
131 | case llvm::Triple::aarch64: |
132 | case llvm::Triple::x86_64: |
133 | return true; |
134 | default: |
135 | return false; |
136 | } |
137 | } |
138 | |
139 | SanitizerMask CloudABI::getSupportedSanitizers() const { |
140 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
141 | Res |= SanitizerKind::SafeStack; |
142 | return Res; |
143 | } |
144 | |
145 | SanitizerMask CloudABI::getDefaultSanitizers() const { |
146 | return SanitizerKind::SafeStack; |
147 | } |
148 | |