1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Compile with MicroJIT disabled when scrape fails

This is just so we can build successfully on -O0 and other cases that
are not supported by the code scraper.
This commit is contained in:
Alan Wu 2020-10-05 07:21:45 -04:00
parent 726bdd4d35
commit a3e58f4df8
3 changed files with 17 additions and 12 deletions

View file

@ -176,21 +176,21 @@ module RubyVM::MicroJIT
else
raise 'Unkonwn platform. Only Mach-O on macOS and ELF on Linux are supported'
end
[true, comma_separated_hex_string(@pre_call_bytes), comma_separated_hex_string(@post_call_bytes)]
rescue => e
print_warning("scrape failed: #{e.message}")
[false, '', '']
end
def print_warning(text)
text = "ujit warning: #{text}"
text = "\x1b[1m#{text}\x1b[0m" if STDOUT.tty?
STDOUT.puts(text)
end
def comma_separated_hex_string(nums)
nums.map{ |byte| '0x'+byte}.join(', ')
end
def pre_call_bytes
scrape unless @pre_call_bytes
comma_separated_hex_string(@pre_call_bytes)
end
def post_call_bytes
scrape unless @post_call_bytes
comma_separated_hex_string(@post_call_bytes)
end
end
end

View file

@ -12,5 +12,7 @@
edit: __FILE__,
} -%>
static const uint8_t ujit_pre_call_bytes[] = { <%= RubyVM::MicroJIT.pre_call_bytes %> };
static const uint8_t ujit_post_call_bytes[] = { <%= RubyVM::MicroJIT.post_call_bytes %> };
% success, pre_call_bytes, post_call_bytes = RubyVM::MicroJIT.scrape
static const uint8_t ujit_scrape_successful = <%= success %>;
static const uint8_t ujit_pre_call_bytes[] = { <%= pre_call_bytes %> };
static const uint8_t ujit_post_call_bytes[] = { <%= post_call_bytes %> };

View file

@ -505,6 +505,9 @@ rb_ujit_enabled_p(void)
void
rb_ujit_init(void)
{
if (!ujit_scrape_successful) {
return;
}
// Initialize the code blocks
size_t mem_size = 64 * 1024 * 1024;
uint8_t* mem_block = alloc_exec_mem(mem_size);