@@ -156,15 +156,19 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
156
156
addLinkerCompressDebugSectionsOption (ToolChain, Args, CmdArgs);
157
157
AddLinkerInputs (ToolChain, Inputs, Args, CmdArgs, JA);
158
158
159
+ // Sample these options first so they are claimed even under -nostdlib et al.
160
+ bool NoLibc = Args.hasArg (options::OPT_nolibc);
161
+ bool OnlyLibstdcxxStatic = Args.hasArg (options::OPT_static_libstdcxx) &&
162
+ !Args.hasArg (options::OPT_static);
163
+ bool Pthreads = Args.hasArg (options::OPT_pthread, options::OPT_pthreads);
164
+ bool SplitStack = Args.hasArg (options::OPT_fsplit_stack);
159
165
if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nodefaultlibs,
160
166
options::OPT_r)) {
161
167
if (Args.hasArg (options::OPT_static))
162
168
CmdArgs.push_back (" -Bdynamic" );
163
169
164
170
if (D.CCCIsCXX ()) {
165
171
if (ToolChain.ShouldLinkCXXStdlib (Args)) {
166
- bool OnlyLibstdcxxStatic = Args.hasArg (options::OPT_static_libstdcxx) &&
167
- !Args.hasArg (options::OPT_static);
168
172
CmdArgs.push_back (" --push-state" );
169
173
CmdArgs.push_back (" --as-needed" );
170
174
if (OnlyLibstdcxxStatic)
@@ -188,14 +192,13 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
188
192
189
193
AddRunTimeLibs (ToolChain, D, CmdArgs, Args);
190
194
191
- if (Args.hasArg (options::OPT_pthread) ||
192
- Args.hasArg (options::OPT_pthreads))
195
+ if (Pthreads)
193
196
CmdArgs.push_back (" -lpthread" );
194
197
195
- if (Args. hasArg (options::OPT_fsplit_stack) )
198
+ if (SplitStack )
196
199
CmdArgs.push_back (" --wrap=pthread_create" );
197
200
198
- if (!Args. hasArg (options::OPT_nolibc) )
201
+ if (!NoLibc )
199
202
CmdArgs.push_back (" -lc" );
200
203
}
201
204
@@ -229,7 +232,7 @@ void fuchsia::StaticLibTool::ConstructJob(Compilation &C, const JobAction &JA,
229
232
230
233
for (const auto &II : Inputs) {
231
234
if (II.isFilename ()) {
232
- CmdArgs.push_back (II.getFilename ());
235
+ CmdArgs.push_back (II.getFilename ());
233
236
}
234
237
}
235
238
@@ -343,16 +346,14 @@ std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList &Args,
343
346
return Triple.str ();
344
347
}
345
348
346
- Tool *Fuchsia::buildLinker () const {
347
- return new tools::fuchsia::Linker (*this );
348
- }
349
+ Tool *Fuchsia::buildLinker () const { return new tools::fuchsia::Linker (*this ); }
349
350
350
351
Tool *Fuchsia::buildStaticLibTool () const {
351
352
return new tools::fuchsia::StaticLibTool (*this );
352
353
}
353
354
354
- ToolChain::RuntimeLibType Fuchsia::GetRuntimeLibType (
355
- const ArgList &Args) const {
355
+ ToolChain::RuntimeLibType
356
+ Fuchsia::GetRuntimeLibType ( const ArgList &Args) const {
356
357
if (Arg *A = Args.getLastArg (clang::driver::options::OPT_rtlib_EQ)) {
357
358
StringRef Value = A->getValue ();
358
359
if (Value != " compiler-rt" )
@@ -363,13 +364,12 @@ ToolChain::RuntimeLibType Fuchsia::GetRuntimeLibType(
363
364
return ToolChain::RLT_CompilerRT;
364
365
}
365
366
366
- ToolChain::CXXStdlibType
367
- Fuchsia::GetCXXStdlibType (const ArgList &Args) const {
367
+ ToolChain::CXXStdlibType Fuchsia::GetCXXStdlibType (const ArgList &Args) const {
368
368
if (Arg *A = Args.getLastArg (options::OPT_stdlib_EQ)) {
369
369
StringRef Value = A->getValue ();
370
370
if (Value != " libc++" )
371
371
getDriver ().Diag (diag::err_drv_invalid_stdlib_name)
372
- << A->getAsString (Args);
372
+ << A->getAsString (Args);
373
373
}
374
374
375
375
return ToolChain::CST_Libcxx;
0 commit comments