@@ -1063,10 +1063,13 @@ getDarwinLibraryNameSuffixForTriple(const llvm::Triple &triple) {
10631063}
10641064
10651065static std::string
1066- getSanitizerRuntimeLibNameForDarwin (StringRef Sanitizer, const llvm::Triple &Triple) {
1066+ getSanitizerRuntimeLibNameForDarwin (StringRef Sanitizer,
1067+ const llvm::Triple &Triple,
1068+ bool shared = true ) {
10671069 return (Twine (" libclang_rt." )
10681070 + Sanitizer + " _"
1069- + getDarwinLibraryNameSuffixForTriple (Triple) + " _dynamic.dylib" ).str ();
1071+ + getDarwinLibraryNameSuffixForTriple (Triple)
1072+ + (shared ? " _dynamic.dylib" : " .a" )).str ();
10701073}
10711074
10721075static std::string
@@ -1141,16 +1144,19 @@ addLinkRuntimeLibForLinux(const ArgList &Args, ArgStringList &Arguments,
11411144static void
11421145addLinkSanitizerLibArgsForDarwin (const ArgList &Args,
11431146 ArgStringList &Arguments,
1144- StringRef Sanitizer, const ToolChain &TC) {
1147+ StringRef Sanitizer,
1148+ const ToolChain &TC,
1149+ bool shared = true
1150+ ) {
11451151 // Sanitizer runtime libraries requires C++.
11461152 Arguments.push_back (" -lc++" );
11471153 // Add explicit dependency on -lc++abi, as -lc++ doesn't re-export
11481154 // all RTTI-related symbols that are used.
11491155 Arguments.push_back (" -lc++abi" );
11501156
11511157 addLinkRuntimeLibForDarwin (Args, Arguments,
1152- getSanitizerRuntimeLibNameForDarwin (Sanitizer, TC.getTriple ()),
1153- /* AddRPath=*/ true , TC);
1158+ getSanitizerRuntimeLibNameForDarwin (Sanitizer, TC.getTriple (), shared ),
1159+ /* AddRPath=*/ shared , TC);
11541160}
11551161
11561162static void
@@ -1175,40 +1181,6 @@ addLinkSanitizerLibArgsForLinux(const ArgList &Args,
11751181 Arguments.push_back (" -ldl" );
11761182}
11771183
1178- static void
1179- addLinkFuzzerLibArgsForDarwin (const ArgList &Args,
1180- ArgStringList &Arguments,
1181- const ToolChain &TC) {
1182-
1183- // libFuzzer requires C++.
1184- Arguments.push_back (" -lc++" );
1185-
1186- // Link libfuzzer.
1187- SmallString<128 > Dir;
1188- getRuntimeLibraryPath (Dir, Args, TC);
1189- llvm::sys::path::remove_filename (Dir);
1190- llvm::sys::path::append (Dir, " llvm" , " libLLVMFuzzer.a" );
1191- SmallString<128 > P (Dir);
1192-
1193- Arguments.push_back (Args.MakeArgString (P));
1194- }
1195-
1196- static void
1197- addLinkFuzzerLibArgsForLinux (const ArgList &Args,
1198- ArgStringList &Arguments,
1199- const ToolChain &TC) {
1200- Arguments.push_back (" -lstdc++" );
1201-
1202- // Link libfuzzer.
1203- SmallString<128 > Dir;
1204- getRuntimeLibraryPath (Dir, Args, TC);
1205- llvm::sys::path::remove_filename (Dir);
1206- llvm::sys::path::append (Dir, " llvm" , " libLLVMFuzzer.a" );
1207- SmallString<128 > P (Dir);
1208-
1209- Arguments.push_back (Args.MakeArgString (P));
1210- }
1211-
12121184ToolChain::InvocationInfo
12131185toolchains::Darwin::constructInvocation (const LinkJobAction &job,
12141186 const JobContext &context) const {
@@ -1348,7 +1320,8 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
13481320 // Only link in libFuzzer for executables.
13491321 if (job.getKind () == LinkKind::Executable &&
13501322 (context.OI .SelectedSanitizers & SanitizerKind::Fuzzer))
1351- addLinkFuzzerLibArgsForDarwin (context.Args , Arguments, *this );
1323+ addLinkSanitizerLibArgsForDarwin (
1324+ context.Args , Arguments, " fuzzer" , *this , /* shared=*/ false );
13521325
13531326 if (context.Args .hasArg (options::OPT_embed_bitcode,
13541327 options::OPT_embed_bitcode_marker)) {
@@ -1724,7 +1697,9 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
17241697 addLinkSanitizerLibArgsForLinux (context.Args , Arguments, " tsan" , *this );
17251698
17261699 if (context.OI .SelectedSanitizers & SanitizerKind::Fuzzer)
1727- addLinkFuzzerLibArgsForLinux (context.Args , Arguments, *this );
1700+ addLinkRuntimeLibForLinux (context.Args , Arguments,
1701+ getSanitizerRuntimeLibNameForLinux (
1702+ " fuzzer" , this ->getTriple ()), *this );
17281703 }
17291704 }
17301705
0 commit comments