From aaff4fc494e61fee1b58613837b154868de5f126 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Mon, 27 May 2019 05:45:08 +0000 Subject: [PATCH] Introduce a rake test:asan task for convenient running of Address Sanitizer (#141) --- Rakefile | 15 +++++++++++++++ ext/mini_racer_extension/extconf.rb | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index da68b3d..67da443 100644 --- a/Rakefile +++ b/Rakefile @@ -16,6 +16,21 @@ Rake::ExtensionTask.new( 'mini_racer_extension', gem ) # via http://blog.flavorjon.es/2009/06/easily-valgrind-gdb-your-ruby-c.html namespace :test do + desc "run test suite with Address Sanitizer" + task :asan do + ENV["CONFIGURE_ARGS"] = [ENV["CONFIGURE_ARGS"], '--enable-asan'].compact.join(' ') + Rake::Task['compile'].invoke + + asan_path = `ldconfig -N -p | grep libasan | sed 's/.* => \\(.*\\)$/\\1/'`.chomp + + cmdline = "env LD_PRELOAD=\"#{asan_path}\" ruby test/test_leak.rb" + puts cmdline + system cmdline + + cmdline = "env LD_PRELOAD=\"#{asan_path}\" rake test" + puts cmdline + system cmdline + end # partial-loads-ok and undef-value-errors necessary to ignore # spurious (and eminently ignorable) warnings from the ruby # interpreter diff --git a/ext/mini_racer_extension/extconf.rb b/ext/mini_racer_extension/extconf.rb index 4819638..55d7334 100644 --- a/ext/mini_racer_extension/extconf.rb +++ b/ext/mini_racer_extension/extconf.rb @@ -49,10 +49,15 @@ if CONFIG['warnflags'] CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '') end -if enable_config('debug') +if enable_config('debug') || enable_config('asan') CONFIG['debugflags'] << ' -ggdb3 -O0' end Libv8.configure_makefile +if enable_config('asan') + $CPPFLAGS.insert(0, " -fsanitize=address ") + $LDFLAGS.insert(0, " -fsanitize=address ") +end + create_makefile 'mini_racer_extension'