Skip to content

Commit 9abb344

Browse files
authored
[Darwin][Driver] Avoid duplicate -lc++ with -fsanitize=fuzzer (#161304)
On Darwin, duplicate `-l` options cause a warning to be printed. Invoking clang as clang++ and using `-fsanitize=fuzzer` will cause `-lc++` to be passed twice to the linker, causing a warning. i.e. AddCXXStdlibLibArgs is called twice in this case: 1) https://github.com/llvm/llvm-project/blob/19c4e86f3e8582c3f087a9fec5ac036838e58ec4/clang/lib/Driver/ToolChains/Darwin.cpp#L743 because `ShouldLinkCXXStdlib(Args)` is true. 2) The subject of this PR We now skip adding the -lc++ argument if `ShouldLinkCXXStdlib(Args)` (since that means the other path already added it). rdar://136431775
1 parent daf81a6 commit 9abb344

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,12 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
16091609
if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
16101610
AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
16111611

1612-
// Libfuzzer is written in C++ and requires libcxx.
1612+
// Libfuzzer is written in C++ and requires libcxx.
1613+
// Since darwin::Linker::ConstructJob already adds -lc++ for clang++
1614+
// by default if ShouldLinkCXXStdlib(Args), we only add the option if
1615+
// !ShouldLinkCXXStdlib(Args). This avoids duplicate library errors
1616+
// on Darwin.
1617+
if (!ShouldLinkCXXStdlib(Args))
16131618
AddCXXStdlibLibArgs(Args, CmdArgs);
16141619
}
16151620
if (Sanitize.needsStatsRt()) {

0 commit comments

Comments
 (0)