[PATCH] D80488: Teach `-fsanitize=fuzzer` to respect `-static` and `-static-libstdc++` when adding C++ standard libraries.

Chandler Carruth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 17:44:08 PDT 2020


chandlerc updated this revision to Diff 300842.
chandlerc marked an inline comment as done.
chandlerc added a comment.

Update with a regression test.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80488/new/

https://reviews.llvm.org/D80488

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/fuzzer.c


Index: clang/test/Driver/fuzzer.c
===================================================================
--- clang/test/Driver/fuzzer.c
+++ 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;
 }
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -833,8 +833,15 @@
     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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80488.300842.patch
Type: text/x-patch
Size: 2300 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201027/8b6abb90/attachment-0001.bin>


More information about the cfe-commits mailing list