[PATCH] D35922: [Driver] Enable AddressSanitizer for Fuchsia targets

Roland McGrath via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 26 15:37:22 PDT 2017


mcgrathr created this revision.
mcgrathr added a project: Sanitizers.
Herald added subscribers: mgorny, srhines.

Repository:
  rL LLVM

https://reviews.llvm.org/D35922

Files:
  cmake/caches/Fuchsia-stage2.cmake
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChains/Fuchsia.cpp


Index: lib/Driver/ToolChains/Fuchsia.cpp
===================================================================
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -14,6 +14,7 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
 
@@ -68,22 +69,21 @@
   else
     CmdArgs.push_back("--build-id");
 
-  if (!Args.hasArg(options::OPT_static))
-    CmdArgs.push_back("--eh-frame-hdr");
+  CmdArgs.push_back("--eh-frame-hdr");
 
   if (Args.hasArg(options::OPT_static))
     CmdArgs.push_back("-Bstatic");
   else if (Args.hasArg(options::OPT_shared))
     CmdArgs.push_back("-shared");
 
-  if (!Args.hasArg(options::OPT_static)) {
-    if (Args.hasArg(options::OPT_rdynamic))
-      CmdArgs.push_back("-export-dynamic");
-
-    if (!Args.hasArg(options::OPT_shared)) {
-      CmdArgs.push_back("-dynamic-linker");
-      CmdArgs.push_back(Args.MakeArgString(D.DyldPrefix + "ld.so.1"));
-    }
+  if (!Args.hasArg(options::OPT_shared)) {
+    std::string Dyld = D.DyldPrefix;
+    if (ToolChain.getSanitizerArgs().needsAsanRt() &&
+        ToolChain.getSanitizerArgs().needsSharedAsanRt())
+      Dyld += "asan/";
+    Dyld += "ld.so.1";
+    CmdArgs.push_back("-dynamic-linker");
+    CmdArgs.push_back(Args.MakeArgString(Dyld));
   }
 
   CmdArgs.push_back("-o");
@@ -100,6 +100,8 @@
 
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
+  addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
@@ -284,5 +286,6 @@
 SanitizerMask Fuchsia::getSupportedSanitizers() const {
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::SafeStack;
+  Res |= SanitizerKind::Address;
   return Res;
 }
Index: lib/Driver/SanitizerArgs.cpp
===================================================================
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -561,8 +561,9 @@
 
   if (AllAddedKinds & Address) {
     AsanSharedRuntime =
-        Args.hasArg(options::OPT_shared_libasan) || TC.getTriple().isAndroid();
-    NeedPIE |= TC.getTriple().isAndroid();
+        Args.hasArg(options::OPT_shared_libasan) ||
+        TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia();
+    NeedPIE |= TC.getTriple().isAndroid() || TC.getTriple().isOSFuchsia();
     if (Arg *A =
             Args.getLastArg(options::OPT_fsanitize_address_field_padding)) {
         StringRef S = A->getValue();
@@ -596,7 +597,7 @@
     // globals in ASan is disabled by default on ELF targets.
     // See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
     AsanGlobalsDeadStripping =
-        !TC.getTriple().isOSBinFormatELF() ||
+        !TC.getTriple().isOSBinFormatELF() || TC.getTriple().isOSFuchsia() ||
         Args.hasArg(options::OPT_fsanitize_address_globals_dead_stripping);
   } else {
     AsanUseAfterScope = false;
Index: cmake/caches/Fuchsia-stage2.cmake
===================================================================
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -47,6 +47,7 @@
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXX_ABI_VERSION 2 CACHE STRING "")
+  set(RUNTIMES_${target}-fuchsia_SANITIZER_USE_COMPILER_RT ON CACHE BOOL "")
 endforeach()
 
 # Setup toolchain.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35922.108373.patch
Type: text/x-patch
Size: 3621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170726/7b3edb38/attachment.bin>


More information about the cfe-commits mailing list