mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-18 23:11:36 +00:00
adding support for using llvm ASAN (#5536)
This commit is contained in:
committed by
Andreas Rumpf
parent
0ff1190fe7
commit
93753926f5
@@ -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"
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user