Skip to content

Commit ead3739

Browse files
committed
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.
1 parent 3071c5d commit ead3739

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

gc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4940,6 +4940,7 @@ rb_raw_obj_info_buitin_type(char *const buff, const size_t buff_size, const VALU
49404940

49414941
#undef C
49424942

4943+
#ifdef RUBY_ASAN_ENABLED
49434944
void
49444945
rb_asan_poison_object(VALUE obj)
49454946
{
@@ -4960,6 +4961,7 @@ rb_asan_poisoned_object_p(VALUE obj)
49604961
MAYBE_UNUSED(struct RVALUE *) ptr = (void *)obj;
49614962
return __asan_region_is_poisoned(ptr, rb_gc_obj_slot_size(obj));
49624963
}
4964+
#endif
49634965

49644966
static void
49654967
raw_obj_info(char *const buff, const size_t buff_size, VALUE obj)

internal/sanitizers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ asan_poison_memory_region(const volatile void *ptr, size_t size)
127127
#define asan_poison_object_if(ptr, obj) ((void)(ptr), (void)(obj))
128128
#endif
129129

130+
#ifdef RUBY_ASAN_ENABLED
130131
RUBY_SYMBOL_EXPORT_BEGIN
131132
/**
132133
* 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);
153154
void rb_asan_unpoison_object(VALUE obj, bool newobj_p);
154155

155156
RUBY_SYMBOL_EXPORT_END
157+
#else
158+
# define rb_asan_poison_object(obj) ((void)obj)
159+
# define rb_asan_poisoned_object_p(obj) ((void)obj, NULL)
160+
# define rb_asan_unpoison_object(obj, newobj_p) ((void)obj, (void)newobj_p)
161+
#endif
156162

157163
/**
158164
* This function asserts that a (formally poisoned) memory region from ptr to

0 commit comments

Comments
 (0)