@@ -156,15 +156,19 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
156156 addLinkerCompressDebugSectionsOption (ToolChain, Args, CmdArgs);
157157 AddLinkerInputs (ToolChain, Inputs, Args, CmdArgs, JA);
158158
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);
159165 if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nodefaultlibs,
160166 options::OPT_r)) {
161167 if (Args.hasArg (options::OPT_static))
162168 CmdArgs.push_back (" -Bdynamic" );
163169
164170 if (D.CCCIsCXX ()) {
165171 if (ToolChain.ShouldLinkCXXStdlib (Args)) {
166- bool OnlyLibstdcxxStatic = Args.hasArg (options::OPT_static_libstdcxx) &&
167- !Args.hasArg (options::OPT_static);
168172 CmdArgs.push_back (" --push-state" );
169173 CmdArgs.push_back (" --as-needed" );
170174 if (OnlyLibstdcxxStatic)
@@ -188,14 +192,13 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
188192
189193 AddRunTimeLibs (ToolChain, D, CmdArgs, Args);
190194
191- if (Args.hasArg (options::OPT_pthread) ||
192- Args.hasArg (options::OPT_pthreads))
195+ if (Pthreads)
193196 CmdArgs.push_back (" -lpthread" );
194197
195- if (Args. hasArg (options::OPT_fsplit_stack) )
198+ if (SplitStack )
196199 CmdArgs.push_back (" --wrap=pthread_create" );
197200
198- if (!Args. hasArg (options::OPT_nolibc) )
201+ if (!NoLibc )
199202 CmdArgs.push_back (" -lc" );
200203 }
201204
@@ -229,7 +232,7 @@ void fuchsia::StaticLibTool::ConstructJob(Compilation &C, const JobAction &JA,
229232
230233 for (const auto &II : Inputs) {
231234 if (II.isFilename ()) {
232- CmdArgs.push_back (II.getFilename ());
235+ CmdArgs.push_back (II.getFilename ());
233236 }
234237 }
235238
@@ -343,16 +346,14 @@ std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList &Args,
343346 return Triple.str ();
344347}
345348
346- Tool *Fuchsia::buildLinker () const {
347- return new tools::fuchsia::Linker (*this );
348- }
349+ Tool *Fuchsia::buildLinker () const { return new tools::fuchsia::Linker (*this ); }
349350
350351Tool *Fuchsia::buildStaticLibTool () const {
351352 return new tools::fuchsia::StaticLibTool (*this );
352353}
353354
354- ToolChain::RuntimeLibType Fuchsia::GetRuntimeLibType (
355- const ArgList &Args) const {
355+ ToolChain::RuntimeLibType
356+ Fuchsia::GetRuntimeLibType ( const ArgList &Args) const {
356357 if (Arg *A = Args.getLastArg (clang::driver::options::OPT_rtlib_EQ)) {
357358 StringRef Value = A->getValue ();
358359 if (Value != " compiler-rt" )
@@ -363,13 +364,12 @@ ToolChain::RuntimeLibType Fuchsia::GetRuntimeLibType(
363364 return ToolChain::RLT_CompilerRT;
364365}
365366
366- ToolChain::CXXStdlibType
367- Fuchsia::GetCXXStdlibType (const ArgList &Args) const {
367+ ToolChain::CXXStdlibType Fuchsia::GetCXXStdlibType (const ArgList &Args) const {
368368 if (Arg *A = Args.getLastArg (options::OPT_stdlib_EQ)) {
369369 StringRef Value = A->getValue ();
370370 if (Value != " libc++" )
371371 getDriver ().Diag (diag::err_drv_invalid_stdlib_name)
372- << A->getAsString (Args);
372+ << A->getAsString (Args);
373373 }
374374
375375 return ToolChain::CST_Libcxx;
0 commit comments