summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2025-06-27 08:51:16 -0400
committerPeter Zhu <peter@peterzhu.ca>2025-06-30 10:25:58 -0400
commitead3739c34b50b081140f1206cd36f13fc7db8ee (patch)
treece41e8bd497a9bfd2c832a7525bd147df1333bcb
parent3071c5d04cb4369ee8118ece30fb2887205f6c61 (diff)
Inline ASAN poison functions when ASAN is not enabled
The ASAN poison functions was always defined in gc.c, even if ASAN was not enabled. This made function calls to happen all the time even if ASAN is not enabled. This commit defines these functions as empty macros when ASAN is not enabled.
-rw-r--r--gc.c2
-rw-r--r--internal/sanitizers.h6
2 files changed, 8 insertions, 0 deletions
diff --git a/gc.c b/gc.c
index 047fcdb3c0..63e86d5ca2 100644
--- a/gc.c
+++ b/gc.c
@@ -4940,6 +4940,7 @@ rb_raw_obj_info_buitin_type(char *const buff, const size_t buff_size, const VALU
#undef C
+#ifdef RUBY_ASAN_ENABLED
void
rb_asan_poison_object(VALUE obj)
{
@@ -4960,6 +4961,7 @@ rb_asan_poisoned_object_p(VALUE obj)
MAYBE_UNUSED(struct RVALUE *) ptr = (void *)obj;
return __asan_region_is_poisoned(ptr, rb_gc_obj_slot_size(obj));
}
+#endif
static void
raw_obj_info(char *const buff, const size_t buff_size, VALUE obj)
diff --git a/internal/sanitizers.h b/internal/sanitizers.h
index 279cbbe069..8e6e87ddc8 100644
--- a/internal/sanitizers.h
+++ b/internal/sanitizers.h
@@ -127,6 +127,7 @@ asan_poison_memory_region(const volatile void *ptr, size_t size)
#define asan_poison_object_if(ptr, obj) ((void)(ptr), (void)(obj))
#endif
+#ifdef RUBY_ASAN_ENABLED
RUBY_SYMBOL_EXPORT_BEGIN
/**
* This is a variant of asan_poison_memory_region that takes a VALUE.
@@ -153,6 +154,11 @@ void *rb_asan_poisoned_object_p(VALUE obj);
void rb_asan_unpoison_object(VALUE obj, bool newobj_p);
RUBY_SYMBOL_EXPORT_END
+#else
+# define rb_asan_poison_object(obj) ((void)obj)
+# define rb_asan_poisoned_object_p(obj) ((void)obj, NULL)
+# define rb_asan_unpoison_object(obj, newobj_p) ((void)obj, (void)newobj_p)
+#endif
/**
* This function asserts that a (formally poisoned) memory region from ptr to