adding support for using llvm ASAN (#5536)
This commit is contained in:
parent
0ff1190fe7
commit
93753926f5
2 changed files with 31 additions and 1 deletions
|
|
@ -23,6 +23,30 @@ __clang__
|
||||||
#ifndef NIMBASE_H
|
#ifndef NIMBASE_H
|
||||||
#define 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 ------------- */
|
/* ------------ ignore typical warnings in Nim-generated files ------------- */
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
# pragma GCC diagnostic ignored "-Wpragmas"
|
# pragma GCC diagnostic ignored "-Wpragmas"
|
||||||
|
|
|
||||||
|
|
@ -751,7 +751,13 @@ proc gcMark(gch: var GcHeap, p: pointer) {.inline.} =
|
||||||
add(gch.decStack, cell)
|
add(gch.decStack, cell)
|
||||||
sysAssert(allocInv(gch.region), "gcMark end")
|
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)
|
forEachStackSlot(gch, gcMark)
|
||||||
|
|
||||||
proc collectZCT(gch: var GcHeap): bool =
|
proc collectZCT(gch: var GcHeap): bool =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue