clang: lib/Driver/ToolChains/Solaris.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

13#include "clang/Config/config.h"

20#include "llvm/ADT/StringSwitch.h"

21#include "llvm/Option/ArgList.h"

22#include "llvm/Support/FileSystem.h"

23#include "llvm/Support/Path.h"

24

28using namespace clang;

30

34 const ArgList &Args,

35 const char *LinkingOutput) const {

36

38}

39

41

42 const Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ);

43 StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;

44 return UseLinker == "bfd" || UseLinker == "gld";

45}

46

48 if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||

49 Args.hasArg(options::OPT_r))

50 return false;

51

52 return Args.hasFlag(options::OPT_pie, options::OPT_no_pie,

54}

55

56

59 if (const Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {

60 StringRef UseLinker = A->getValue();

61 if (!UseLinker.empty()) {

62 if (llvm::sys::path::is_absolute(UseLinker) &&

63 llvm::sys::fs::can_execute(UseLinker))

64 return std::string(UseLinker);

65

66

67 if (UseLinker == "bfd" || UseLinker == "gld")

68

69 return "/usr/gnu/bin/ld";

70

71

72 if (UseLinker != "ld")

74 << A->getAsString(Args);

75 }

76 }

77

78

80}

81

85 const ArgList &Args,

86 const char *LinkingOutput) const {

87 const auto &ToolChain = static_cast<const Solaris &>(getToolChain());

92 ArgStringList CmdArgs;

93

94

95 if (!LinkerIsGnuLd)

96 CmdArgs.push_back("-C");

97

98 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_shared,

99 options::OPT_r)) {

100 CmdArgs.push_back("-e");

101 CmdArgs.push_back("_start");

102 }

103

104 if (IsPIE) {

105 if (LinkerIsGnuLd) {

106 CmdArgs.push_back("-pie");

107 } else {

108 CmdArgs.push_back("-z");

109 CmdArgs.push_back("type=pie");

110 }

111 }

112

113 if (Args.hasArg(options::OPT_static)) {

114 CmdArgs.push_back("-Bstatic");

115 CmdArgs.push_back("-dn");

116 } else {

117 if (!Args.hasArg(options::OPT_r) && Args.hasArg(options::OPT_shared))

118 CmdArgs.push_back("-shared");

119

120

121

122 Args.ClaimAllArgs(options::OPT_pthread);

123 Args.ClaimAllArgs(options::OPT_pthreads);

124 }

125

126 if (LinkerIsGnuLd) {

127

128 switch (Arch) {

129 case llvm::Triple::x86:

130 CmdArgs.push_back("-m");

131 CmdArgs.push_back("elf_i386_sol2");

132 break;

133 case llvm::Triple::x86_64:

134 CmdArgs.push_back("-m");

135 CmdArgs.push_back("elf_x86_64_sol2");

136 break;

137 case llvm::Triple::sparc:

138 CmdArgs.push_back("-m");

139 CmdArgs.push_back("elf32_sparc_sol2");

140 break;

141 case llvm::Triple::sparcv9:

142 CmdArgs.push_back("-m");

143 CmdArgs.push_back("elf64_sparc_sol2");

144 break;

145 default:

146 break;

147 }

148

149 if (Args.hasArg(options::OPT_rdynamic))

150 CmdArgs.push_back("-export-dynamic");

151

152 CmdArgs.push_back("--eh-frame-hdr");

153 } else {

154

155 Args.ClaimAllArgs(options::OPT_rdynamic);

156 }

157

158 assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");

160 CmdArgs.push_back("-o");

162 }

163

164 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,

165 options::OPT_r)) {

166 if (!Args.hasArg(options::OPT_shared))

168

170

171 const Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi);

172 bool HaveAnsi = false;

174 if (Std) {

175 HaveAnsi = Std->getOption().matches(options::OPT_ansi);

176 if (!HaveAnsi)

178 }

179

180 const char *values_X = "values-Xa.o";

181

182 if (HaveAnsi || (LangStd && !LangStd->isGNUMode()))

183 values_X = "values-Xc.o";

185

186 const char *values_xpg = "values-xpg6.o";

187

189 values_xpg = "values-xpg4.o";

191

192 const char *crtbegin = nullptr;

193 if (Args.hasArg(options::OPT_shared) || IsPIE)

194 crtbegin = "crtbeginS.o";

195 else

196 crtbegin = "crtbegin.o";

198

200 }

201

203

204 Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group});

205

208

209 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,

210 options::OPT_r)) {

211

212 bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&

213 !Args.hasArg(options::OPT_static);

215

216 if (D.CCCIsCXX()) {

219 CmdArgs.push_back("-lm");

220 }

221

222 Args.ClaimAllArgs(options::OPT_stdlib_EQ);

223

224

225

226 if (D.IsFlangMode() &&

227 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {

230 CmdArgs.push_back("-lm");

231 }

232 if (Args.hasArg(options::OPT_fstack_protector) ||

233 Args.hasArg(options::OPT_fstack_protector_strong) ||

234 Args.hasArg(options::OPT_fstack_protector_all)) {

235

236 CmdArgs.push_back("-lssp_nonshared");

237 CmdArgs.push_back("-lssp");

238 }

239

240

241 if (Arch == llvm::Triple::sparc) {

243 CmdArgs.push_back("-latomic");

245 }

247 CmdArgs.push_back("-lgcc_s");

249 CmdArgs.push_back("-lc");

250 if (!Args.hasArg(options::OPT_shared)) {

251 CmdArgs.push_back("-lgcc");

252 }

254 if (NeedsSanitizerDeps) {

256

257

258

259

260 if (Arch == llvm::Triple::x86_64 &&

263 !LinkerIsGnuLd) {

264 CmdArgs.push_back("-z");

265 CmdArgs.push_back("relax=transtls");

266 }

267 }

268

270 CmdArgs.push_back("-z");

271 CmdArgs.push_back("now");

272 }

273 }

274

275 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,

276 options::OPT_r)) {

277 const char *crtend = nullptr;

278 if (Args.hasArg(options::OPT_shared) || IsPIE)

279 crtend = "crtendS.o";

280 else

281 crtend = "crtend.o";

284 }

285

287

288 const char *Exec = Args.MakeArgString(getLinkerPath(Args));

290 Exec, CmdArgs, Inputs, Output));

291}

292

294 switch (Triple.getArch()) {

295 case llvm::Triple::x86:

296 case llvm::Triple::sparc:

297 default:

298 break;

299 case llvm::Triple::x86_64:

300 return "/amd64";

301 case llvm::Triple::sparcv9:

302 return "/sparcv9";

303 }

304 return "";

305}

306

307

308

310 const ArgList &Args)

312

314

318

319

323 Paths);

325 }

326

327

328

329 if (StringRef(D.Dir).starts_with(D.SysRoot))

331

333}

334

336 const bool IsSparc = getTriple().getArch() == llvm::Triple::sparc;

337 const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;

339

340 if (IsSparc || IsX86) {

341 Res |= SanitizerKind::Address;

342 Res |= SanitizerKind::PointerCompare;

343 Res |= SanitizerKind::PointerSubtract;

344 }

345 Res |= SanitizerKind::SafeStack;

346 Res |= SanitizerKind::Vptr;

347 return Res;

348}

349

351

352 return llvm::StringSwitch<const char *>(CLANG_DEFAULT_LINKER)

353 .Cases("bfd", "gld", "/usr/gnu/bin/ld")

354 .Default("/usr/bin/ld");

355}

356

359}

360

362

364 ArgStringList &CC1Args) const {

366

367 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))

368 return;

369

370 if (!DriverArgs.hasArg(options::OPT_nostdlibinc))

371 addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/local/include");

372

373 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {

375 llvm::sys::path::append(P, "include");

377 }

378

379 if (DriverArgs.hasArg(options::OPT_nostdlibinc))

380 return;

381

382

383 StringRef CIncludeDirs(C_INCLUDE_DIRS);

384 if (CIncludeDirs != "") {

386 CIncludeDirs.split(dirs, ":");

387 for (StringRef dir : dirs) {

388 StringRef Prefix =

389 llvm::sys::path::is_absolute(dir) ? "" : StringRef(D.SysRoot);

391 }

392 return;

393 }

394

395

399 if (Callback) {

403 }

404 }

405

407}

408

410 const llvm::opt::ArgList &DriverArgs,

411 llvm::opt::ArgStringList &CC1Args) const {

412

413

415 return;

416

417

418

419

424

425

428 CC1Args);

429}

static StringRef getSolarisLibSuffix(const llvm::Triple &Triple)

static bool getPIE(const ArgList &Args, const ToolChain &TC)

Compilation - A set of tasks to perform for a single driver invocation.

Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...

DiagnosticBuilder Diag(unsigned DiagID) const

InputInfo - Wrapper for information about an input source.

const char * getFilename() const

const IncludeDirsFunc & includeDirsCallback() const

std::function< std::vector< std::string >(const Multilib &M)> IncludeDirsFunc

This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag.

const std::string & gccSuffix() const

Get the detected GCC installation path suffix for the multi-arch target variant.

const std::string & includeSuffix() const

Get the include directory suffix.

bool needsStatsRt() const

bool needsUbsanRt() const

bool requiresMinimalRuntime() const

bool needsSharedRt() const

The JSON file list parser is used to communicate input to InstallAPI.

@ C

Languages that the frontend can parse and compile.

LangStandard - Information about the properties of a particular language standard.

static const LangStandard * getLangStandardForName(StringRef Name)

clang::Language getLanguage() const

Get the language that this standard describes.

bool isGNUMode() const

isGNUMode - Language includes GNU extensions.

bool isC99() const

isC99 - Language is a superset of C99.

static constexpr ResponseFileSupport None()

Returns a ResponseFileSupport indicating that response files are not supported.