[clang] [Darwin][Driver] Avoid duplicate -lc++ with -fsanitize=fuzzer (PR #161304)
Dan Blackwell via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 30 03:17:40 PDT 2025
================
@@ -1609,7 +1609,12 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
- // Libfuzzer is written in C++ and requires libcxx.
+ // Libfuzzer is written in C++ and requires libcxx.
+ // Since darwin::Linker::ConstructJob already adds -l++ for clang++
+ // by default (checked via ShouldLinkCXXStdlib), we only link if
+ // we are not invoked as CXX. This avoids duplicate library errors
+ // on Darwin.
+ if (!getDriver().CCCIsCXX())
----------------
DanBlackwell wrote:
It looks like there are some more conditions to the `ShouldLinkCXXStdlib` check:
https://github.com/ndrewh/llvm-project/blob/4096bc5f104537a993db036b02d90ece37e2c6fd/clang/lib/Driver/ToolChain.cpp#L1529
```
!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_nostdlibxx);
```
Is it possible that this evaluates to false and then we end up failing to link libc++ because we assumed that we'd have it due to invoking clang++? Perhaps this would be better:
```
if (!CmdArgs.contains("-lc++")) // pseudocode
AddCXXStdlibLibArgs(Args, CmdArgs);
```
https://github.com/llvm/llvm-project/pull/161304
More information about the cfe-commits
mailing list