summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSamantha Marshall <samdmarshall@users.noreply.github.com>2017-03-14 18:33:56 -0400
committerAndreas Rumpf <rumpf_a@web.de>2017-03-14 23:33:56 +0100
commit93753926f5db8fa0cd94afa7e0783bba23949441 (patch)
treedb0a908bbda4e380920c84fe8bc40112dc9930b4
parent0ff1190fe704179745e4303a2e09ba8baf566c01 (diff)
downloadNim-93753926f5db8fa0cd94afa7e0783bba23949441.tar.gz
adding support for using llvm ASAN (#5536)
-rw-r--r--lib/nimbase.h24
-rw-r--r--lib/system/gc.nim8
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/nimbase.h b/lib/nimbase.h
index df715188f..a535d0da9 100644
--- a/lib/nimbase.h
+++ b/lib/nimbase.h
@@ -23,6 +23,30 @@ __clang__
 #ifndef NIMBASE_H
 #define NIMBASE_H
 
+/*------------ declaring a custom attribute to support using LLVM's Address Sanitizer ------------ */
+
+/*
+   This definition exists to provide support for using the LLVM ASAN (Address SANitizer) tooling with Nim. This 
+   should only be used to mark implementations of the GC system that raise false flags with the ASAN tooling, or
+   for functions that are hot and need to be disabled for performance reasons. Based on the official ASAN 
+   documentation, both the clang and gcc compilers are supported. In addition to that, a check is performed to 
+   verify that the necessary attribute is supported by the compiler.
+
+   To flag a proc as ignored, append the following code pragma to the proc declaration:
+      {.codegenDecl: "CLANG_NO_SANITIZE_ADDRESS $# $#$#".} 
+
+   For further information, please refer to the official documentation:
+     https://github.com/google/sanitizers/wiki/AddressSanitizer
+ */
+#define CLANG_NO_SANITIZE_ADDRESS
+#if defined(__clang__)
+#  if __has_attribute(no_sanitize_address)
+#    undef CLANG_NO_SANITIZE_ADDRESS
+#    define CLANG_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
+#  endif
+#endif
+
+
 /* ------------ ignore typical warnings in Nim-generated files ------------- */
 #if defined(__GNUC__) || defined(__clang__)
 #  pragma GCC diagnostic ignored "-Wpragmas"
diff --git a/lib/system/gc.nim b/lib/system/gc.nim
index 8db60ab0f..66a5df73c 100644
--- a/lib/system/gc.nim
+++ b/lib/system/gc.nim
@@ -751,7 +751,13 @@ proc gcMark(gch: var GcHeap, p: pointer) {.inline.} =
         add(gch.decStack, cell)
   sysAssert(allocInv(gch.region), "gcMark end")
 
-proc markStackAndRegisters(gch: var GcHeap) {.noinline, cdecl.} =
+#[
+  This method is conditionally marked with an attribute so that it gets ignored by the LLVM ASAN
+  (Address SANitizer) intrumentation as it will raise false errors due to the implementation of 
+  garbage collection that is used by Nim. For more information, please see the documentation of 
+  `CLANG_NO_SANITIZE_ADDRESS` in `lib/nimbase.h`.
+ ]#
+proc markStackAndRegisters(gch: var GcHeap) {.noinline, cdecl, codegenDecl: "CLANG_NO_SANITIZE_ADDRESS $# $#$#".} =
   forEachStackSlot(gch, gcMark)
 
 proc collectZCT(gch: var GcHeap): bool =