Author: Chandler Carruth Date: 2020-10-27T01:36:54Z New Revision: aaf7ffd4e1aa81c7f4cc8da4f943982ca2e131f4
URL: https://github.com/llvm/llvm-project/commit/aaf7ffd4e1aa81c7f4cc8da4f943982ca2e131f4 DIFF: https://github.com/llvm/llvm-project/commit/aaf7ffd4e1aa81c7f4cc8da4f943982ca2e131f4.diff LOG: Teach `-fsanitize=fuzzer` to respect `-static` and `-static-libstdc++` when adding C++ standard libraries. Summary: Makes linking the sanitizers follow the same logic as the rest of the driver with respect to the static linking strategy for the C++ standard library. Subscribers: mcrosier, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D80488 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/fuzzer.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 692d0600bad3..23522e0886ff 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -833,8 +833,15 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, if (SanArgs.needsFuzzerInterceptors()) addSanitizerRuntime(TC, Args, CmdArgs, "fuzzer_interceptors", false, true); - if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx)) + if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx)) { + bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) && + !Args.hasArg(options::OPT_static); + if (OnlyLibstdcxxStatic) + CmdArgs.push_back("-Bstatic"); TC.AddCXXStdlibLibArgs(Args, CmdArgs); + if (OnlyLibstdcxxStatic) + CmdArgs.push_back("-Bdynamic"); + } } for (auto RT : SharedRuntimes) diff --git a/clang/test/Driver/fuzzer.c b/clang/test/Driver/fuzzer.c index 3fdf5ab9c9b9..d91dd573dec3 100644 --- a/clang/test/Driver/fuzzer.c +++ b/clang/test/Driver/fuzzer.c @@ -29,6 +29,23 @@ // RUN: %clang -fsanitize=fuzzer -fsanitize-coverage=trace-pc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-MSG %s // CHECK-MSG-NOT: argument unused during compilation +// Check that we respect whether thes tandard library should be linked +// statically. +// +// RUN: %clang -fsanitize=fuzzer -target i386-unknown-linux -stdlib=libstdc++ %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LIBSTDCXX-DYNAMIC %s +// CHECK-LIBSTDCXX-DYNAMIC-NOT: -Bstatic +// CHECK-LIBSTDCXX-DYNAMIC: -lstdc++ +// +// RUN: %clang -fsanitize=fuzzer -target i386-unknown-linux -stdlib=libstdc++ -static-libstdc++ %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LIBSTDCXX-STATIC %s +// CHECK-LIBSTDCXX-STATIC: "-Bstatic" "-lstdc++" +// +// RUN: %clang -fsanitize=fuzzer -target i386-unknown-linux -stdlib=libc++ %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LIBCXX-DYNAMIC %s +// CHECK-LIBCXX-DYNAMIC-NOT: -Bstatic +// CHECK-LIBCXX-DYNAMIC: -lc++ +// +// RUN: %clang -fsanitize=fuzzer -target i386-unknown-linux -stdlib=libc++ -static-libstdc++ %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LIBCXX-STATIC %s +// CHECK-LIBCXX-STATIC: "-Bstatic" "-lc++" + int LLVMFuzzerTestOneInput(const char *Data, long Size) { return 0; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits