Skip to content

Commit 453f88f

Browse files
committed
Make ASAN default option string built-in libruby
The content depends on ruby internal, not responsibility of the caller. Revive `RUBY_GLOBAL_SETUP` macro to define the hook function.
1 parent f23146f commit 453f88f

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

include/ruby/ruby.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,14 @@ __extension__({ \
426426
# include "ruby/backward.h"
427427
#endif
428428

429+
#ifndef RUBY__ASAN_DEFAULT_OPTIONS
430+
# define RUBY__ASAN_DEFAULT_OPTIONS
431+
#endif
432+
433+
#define RUBY_GLOBAL_SETUP \
434+
RUBY__ASAN_DEFAULT_OPTIONS \
435+
/* RUBY_GLOBAL_SETUP end */
436+
429437
RBIMPL_SYMBOL_EXPORT_END()
430438

431439
#endif /* RUBY_RUBY_H */

internal/sanitizers.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,17 @@ asan_get_fake_stack_extents(void *thread_fake_stack_handle, VALUE slot,
314314
return false;
315315
}
316316

317+
extern const char ruby_asan_default_options[];
318+
319+
#ifdef RUBY_ASAN_ENABLED
320+
/* Compile in the ASAN options Ruby needs, rather than relying on environment variables, so
321+
* that even tests which fork ruby with a clean environment will run ASAN with the right
322+
* settings */
323+
# undef RUBY__ASAN_DEFAULT_OPTIONS
324+
# define RUBY__ASAN_DEFAULT_OPTIONS \
325+
RBIMPL_SYMBOL_EXPORT_BEGIN() \
326+
const char * __asan_default_options(void) {return ruby_asan_default_options;} \
327+
RBIMPL_SYMBOL_EXPORT_END()
328+
#endif
317329

318330
#endif /* INTERNAL_SANITIZERS_H */

main.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
# undef RUBY_DEBUG_ENV
3333
#endif
3434

35+
RUBY_GLOBAL_SETUP
36+
3537
static int
3638
rb_main(int argc, char **argv)
3739
{
@@ -64,16 +66,3 @@ main(int argc, char **argv)
6466
ruby_sysinit(&argc, &argv);
6567
return rb_main(argc, argv);
6668
}
67-
68-
#ifdef RUBY_ASAN_ENABLED
69-
/* Compile in the ASAN options Ruby needs, rather than relying on environment variables, so
70-
* that even tests which fork ruby with a clean environment will run ASAN with the right
71-
* settings */
72-
RUBY_SYMBOL_EXPORT_BEGIN
73-
const char *
74-
__asan_default_options(void)
75-
{
76-
return "use_sigaltstack=0:detect_leaks=0";
77-
}
78-
RUBY_SYMBOL_EXPORT_END
79-
#endif

ruby.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3188,3 +3188,9 @@ ruby_sysinit(int *argc, char ***argv)
31883188
}
31893189
fill_standard_fds();
31903190
}
3191+
3192+
#ifdef RUBY_ASAN_ENABLED
3193+
RUBY_SYMBOL_EXPORT_BEGIN
3194+
const char ruby_asan_default_options[] = "use_sigaltstack=0:detect_leaks=0";
3195+
RUBY_SYMBOL_EXPORT_END
3196+
#endif

0 commit comments

Comments
 (0)