[PATCH] D55654: [clang] [Driver] [NetBSD] Add -D_REENTRANT when using sanitizers

Michał Górny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 13 07:06:30 PST 2018


mgorny created this revision.
mgorny added reviewers: krytarowski, vitalybuka, joerg, bkramer.
Herald added subscribers: jfb, cryptoad.

Requested by @krytarowski with the following rationale:

  We intend to support only reentrant interfaces in interceptors and if
  we use -lpthread without _REENTRANT defined, things are not guaranteed
  to work. This defined _REENTRANT is especially important for <stdio.h>
  and sanitization of interfaces around struct FILE. Some APIs have
  alternative modes depending on whether there is _REENTRANT enabled in
  the preprocessor namespace. We intend to sanitize only the _REENTRANT
  ones.


Repository:
  rC Clang

https://reviews.llvm.org/D55654

Files:
  lib/Driver/ToolChains/NetBSD.cpp
  lib/Driver/ToolChains/NetBSD.h


Index: lib/Driver/ToolChains/NetBSD.h
===================================================================
--- lib/Driver/ToolChains/NetBSD.h
+++ lib/Driver/ToolChains/NetBSD.h
@@ -76,6 +76,10 @@
 
   SanitizerMask getSupportedSanitizers() const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+                             llvm::opt::ArgStringList &CC1Args,
+                             Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: lib/Driver/ToolChains/NetBSD.cpp
===================================================================
--- lib/Driver/ToolChains/NetBSD.cpp
+++ lib/Driver/ToolChains/NetBSD.cpp
@@ -457,3 +457,18 @@
   }
   return Res;
 }
+
+void NetBSD::addClangTargetOptions(const ArgList &,
+                                   ArgStringList &CC1Args,
+                                   Action::OffloadKind) const {
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.needsAsanRt() || SanArgs.needsHwasanRt() ||
+      SanArgs.needsDfsanRt() || SanArgs.needsLsanRt() ||
+      SanArgs.needsMsanRt() || SanArgs.needsTsanRt() ||
+      SanArgs.needsUbsanRt() || SanArgs.needsSafeStackRt() ||
+      SanArgs.needsCfiRt() || SanArgs.needsCfiDiagRt() ||
+      SanArgs.needsStatsRt() || SanArgs.needsEsanRt() ||
+      SanArgs.needsScudoRt()) {
+    CC1Args.push_back("-D_REENTRANT");
+  }
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55654.178057.patch
Type: text/x-patch
Size: 1465 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181213/a01a3102/attachment-0001.bin>


More information about the cfe-commits mailing list