================
@@ -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())
----------------
ndrewh wrote:
I think it's probably possible to pass -nostdlib to clang++ and also link
libfuzzer. It's true that we won't add -lc++ in that case and it will fail, and
we should probably do something about that.
Checking if the option is already in CmdArgs was my initial idea, but:
- I couldn't find any precedent for using CmdArgs.contains to deduplicate the
options
- It is not obvious how this behaves on case insensitive filesystems (is -lC++
also allowed on these systems?)
- There are many ways to pass arguments to the linker, and as far as I
understand the order can matter too. It's possible we or the user are passing
this to the linker in another, equivalent way. So this solution isn't really
robust either.
- I intended to fix only the most obvious duplication inserted by the compiler
and didn't want to change behavior based on the user passing link args.
It'll look ridiculous, but what if we do `if (!ShouldLinkCXXStdlib)` instead,
so that the condition becomes "if we didn't add lc++ for any other reason".
https://github.com/llvm/llvm-project/pull/161304
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits