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

Strip out YJIT at build time when unsupported or disabled (#5003)

In an effort to minimize build issues on non x64 platforms, we can
decide at build time to not build the bulk of YJIT. This should fix
obscure build errors like this one on riscv64:

    yjit_asm.c:137:(.text+0x3fa): relocation truncated to fit: R_RISCV_PCREL_HI20 against `alloc_exec_mem'

We also don't need to bulid YJIT on `--disable-jit-support` builds.

One wrinkle to this is that the YJIT Ruby module will not be defined
when YJIT is stripped from the build. I think that's a fair change as
it's only meant to be used for YJIT development.
This commit is contained in:
Alan Wu 2021-10-25 10:45:22 -04:00 committed by GitHub
parent e943511455
commit 244c98e635
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2021-10-25 23:45:58 +09:00
Merged-By: maximecb <maximecb@ruby-lang.org>
3 changed files with 41 additions and 3 deletions

View file

@ -3,7 +3,7 @@ require 'test/unit'
require 'envutil'
require 'tmpdir'
return unless YJIT.enabled?
return unless defined?(YJIT) && YJIT.enabled?
# Tests for YJIT with assertions on compilation and side exits
# insipired by the MJIT tests in test/ruby/test_jit.rb

35
yjit.c
View file

@ -10,8 +10,6 @@
#include "vm_sync.h"
#include "yjit.h"
#include "yjit_asm.c"
#ifndef YJIT_CHECK_MODE
# define YJIT_CHECK_MODE 0
#endif
@ -31,6 +29,11 @@
// USE_MJIT comes from configure options
#define JIT_ENABLED USE_MJIT
// Check if we need to include YJIT in the build
#if JIT_ENABLED && PLATFORM_SUPPORTED_P
#include "yjit_asm.c"
// Code block into which we write machine code
static codeblock_t block;
static codeblock_t *cb = NULL;
@ -154,3 +157,31 @@ static uint32_t yjit_codepage_frozen_bytes = 0;
#include "yjit_core.c"
#include "yjit_iface.c"
#include "yjit_codegen.c"
#else
// !JIT_ENABLED || !PLATFORM_SUPPORTED_P
// In these builds, YJIT could never be turned on. Provide dummy
// implementations for YJIT functions exposed to the rest of the code base.
// See yjit.h.
void Init_builtin_yjit(void) {}
bool rb_yjit_enabled_p(void) { return false; }
unsigned rb_yjit_call_threshold(void) { return UINT_MAX; }
void rb_yjit_invalidate_all_method_lookup_assumptions(void) {};
void rb_yjit_method_lookup_change(VALUE klass, ID mid) {};
void rb_yjit_cme_invalidate(VALUE cme) {}
void rb_yjit_collect_vm_usage_insn(int insn) {}
void rb_yjit_collect_binding_alloc(void) {}
void rb_yjit_collect_binding_set(void) {}
bool rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec) { return false; }
void rb_yjit_init(struct rb_yjit_options *options) {}
void rb_yjit_bop_redefined(VALUE klass, const rb_method_entry_t *me, enum ruby_basic_operators bop) {}
void rb_yjit_constant_state_changed(void) {}
void rb_yjit_iseq_mark(const struct rb_iseq_constant_body *body) {}
void rb_yjit_iseq_update_references(const struct rb_iseq_constant_body *body) {}
void rb_yjit_iseq_free(const struct rb_iseq_constant_body *body) {}
void rb_yjit_before_ractor_spawn(void) {}
void rb_yjit_constant_ic_update(const rb_iseq_t *iseq, IC ic) {}
void rb_yjit_tracing_invalidate_all(void) {}
#endif // if JIT_ENABLED && PLATFORM_SUPPORTED_P

View file

@ -1,3 +1,10 @@
# This module allows for introspection on YJIT, CRuby's experimental in-process
# just-in-time compiler. This module is for development purposes only;
# everything in this module is highly implementation specific and comes with no
# API stability guarantee whatsoever.
#
# This module is only defined when YJIT has support for the particular platform
# on which CRuby is built.
module YJIT
if defined?(Disasm)
def self.disasm(iseq, tty: $stdout && $stdout.tty?)