[前][次][番号順一覧][スレッド一覧]

ruby-changes:73175

From: Maxime <ko1@a...>
Date: Tue, 30 Aug 2022 00:58:00 +0900 (JST)
Subject: [ruby-changes:73175] 8d743e965e (master): Fix compile errors on arm on the CI (https://github.com/Shopify/ruby/pull/313)

https://git.ruby-lang.org/ruby.git/commit/?id=8d743e965e

From 8d743e965e6bf95ea1649839fc1fe2429564c2d9 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maximechevalierb@g...>
Date: Tue, 12 Jul 2022 17:04:09 -0400
Subject: Fix compile errors on arm on the CI
 (https://github.com/Shopify/ruby/pull/313)

* Fix compile errors on arm on the CI

* Fix typo
---
 yjit/src/backend/tests.rs |  7 +++++--
 yjit/src/core.rs          | 18 ++++++++++--------
 yjit/src/cruby.rs         |  2 +-
 yjit/src/utils.rs         | 43 ++++++++++++++++++++++++++++++++-----------
 4 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/yjit/src/backend/tests.rs b/yjit/src/backend/tests.rs
index 27f799fc31..d386d31d73 100644
--- a/yjit/src/backend/tests.rs
+++ b/yjit/src/backend/tests.rs
@@ -5,6 +5,7 @@ use crate::virtualmem::{CodePtr}; https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/tests.rs#L5
 use crate::backend::ir::*;
 use crate::cruby::*;
 use crate::core::*;
+use crate::utils::c_callable;
 use InsnOpnd::*;
 
 // Test that this function type checks
@@ -193,8 +194,10 @@ fn test_base_insn_out() https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/tests.rs#L194
 #[test]
 fn test_c_call()
 {
-    extern "sysv64" fn dummy_c_fun(v0: usize, v1: usize)
-    {
+    c_callable! {
+        fn dummy_c_fun(v0: usize, v1: usize)
+        {
+        }
     }
 
     let (mut asm, mut cb) = setup_asm();
diff --git a/yjit/src/core.rs b/yjit/src/core.rs
index 1b90260248..6c7044c843 100644
--- a/yjit/src/core.rs
+++ b/yjit/src/core.rs
@@ -1584,14 +1584,16 @@ fn make_branch_entry(block: &BlockRef, src_ctx: &Context, gen_fn: BranchGenFn) - https://github.com/ruby/ruby/blob/trunk/yjit/src/core.rs#L1584
 
 /// Generated code calls this function with the SysV calling convention.
 /// See [get_branch_target].
-extern "sysv64" fn branch_stub_hit(
-    branch_ptr: *const c_void,
-    target_idx: u32,
-    ec: EcPtr,
-) -> *const u8 {
-    with_vm_lock(src_loc!(), || {
-        branch_stub_hit_body(branch_ptr, target_idx, ec)
-    })
+c_callable! {
+    fn branch_stub_hit(
+        branch_ptr: *const c_void,
+        target_idx: u32,
+        ec: EcPtr,
+    ) -> *const u8 {
+        with_vm_lock(src_loc!(), || {
+            branch_stub_hit_body(branch_ptr, target_idx, ec)
+        })
+    }
 }
 
 /// Called by the generated code when a branch stub is executed
diff --git a/yjit/src/cruby.rs b/yjit/src/cruby.rs
index 8543b6d971..1c31b8c149 100644
--- a/yjit/src/cruby.rs
+++ b/yjit/src/cruby.rs
@@ -610,7 +610,7 @@ impl From<VALUE> for u16 { https://github.com/ruby/ruby/blob/trunk/yjit/src/cruby.rs#L610
 /// Produce a Ruby string from a Rust string slice
 #[cfg(feature = "asm_comments")]
 pub fn rust_str_to_ruby(str: &str) -> VALUE {
-    unsafe { rb_utf8_str_new(str.as_ptr() as *const i8, str.len() as i64) }
+    unsafe { rb_utf8_str_new(str.as_ptr() as *const _, str.len() as i64) }
 }
 
 /// Produce a Ruby symbol from a Rust string slice
diff --git a/yjit/src/utils.rs b/yjit/src/utils.rs
index ade573b8da..dd89413090 100644
--- a/yjit/src/utils.rs
+++ b/yjit/src/utils.rs
@@ -151,6 +151,19 @@ yjit_print_iseq(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/yjit/src/utils.rs#L151
 }
 */
 
+#[cfg(target_arch = "aarch64")]
+macro_rules! c_callable {
+    (fn $f:ident $args:tt -> $ret:ty $body:block) => { fn $f $args -> $ret $body };
+    (fn $f:ident $args:tt $body:block) => { fn $f $args $body };
+}
+
+#[cfg(target_arch = "x86_64")]
+macro_rules! c_callable {
+    (fn $f:ident $args:tt -> $ret:ty $body:block) => { extern "sysv64" fn $f $args -> $ret $body };
+    (fn $f:ident $args:tt $body:block) => { extern "sysv64" fn $f $args $body };
+}
+pub(crate) use c_callable;
+
 // Save caller-save registers on the stack before a C call
 fn push_regs(cb: &mut CodeBlock) {
     push(cb, RAX);
@@ -180,8 +193,10 @@ fn pop_regs(cb: &mut CodeBlock) { https://github.com/ruby/ruby/blob/trunk/yjit/src/utils.rs#L193
 }
 
 pub fn print_int(cb: &mut CodeBlock, opnd: X86Opnd) {
-    extern "sysv64" fn print_int_fn(val: i64) {
-        println!("{}", val);
+    c_callable!{
+        fn print_int_fn(val: i64) {
+            println!("{}", val);
+        }
     }
 
     push_regs(cb);
@@ -208,8 +223,10 @@ pub fn print_int(cb: &mut CodeBlock, opnd: X86Opnd) { https://github.com/ruby/ruby/blob/trunk/yjit/src/utils.rs#L223
 
 /// Generate code to print a pointer
 pub fn print_ptr(cb: &mut CodeBlock, opnd: X86Opnd) {
-    extern "sysv64" fn print_ptr_fn(ptr: *const u8) {
-        println!("{:p}", ptr);
+    c_callable!{
+        fn print_ptr_fn(ptr: *const u8) {
+            println!("{:p}", ptr);
+        }
     }
 
     assert!(opnd.num_bits() == 64);
@@ -223,8 +240,10 @@ pub fn print_ptr(cb: &mut CodeBlock, opnd: X86Opnd) { https://github.com/ruby/ruby/blob/trunk/yjit/src/utils.rs#L240
 
 /// Generate code to print a value
 pub fn print_value(cb: &mut CodeBlock, opnd: X86Opnd) {
-    extern "sysv64" fn print_value_fn(val: VALUE) {
-        unsafe { rb_obj_info_dump(val) }
+    c_callable!{
+        fn print_value_fn(val: VALUE) {
+            unsafe { rb_obj_info_dump(val) }
+        }
     }
 
     assert!(opnd.num_bits() == 64);
@@ -240,11 +259,13 @@ pub fn print_value(cb: &mut CodeBlock, opnd: X86Opnd) { https://github.com/ruby/ruby/blob/trunk/yjit/src/utils.rs#L259
 
 /// Generate code to print constant string to stdout
 pub fn print_str(cb: &mut CodeBlock, str: &str) {
-    extern "sysv64" fn print_str_cfun(ptr: *const u8, num_bytes: usize) {
-        unsafe {
-            let slice = slice::from_raw_parts(ptr, num_bytes);
-            let str = std::str::from_utf8(slice).unwrap();
-            println!("{}", str);
+    c_callable!{
+        fn print_str_cfun(ptr: *const u8, num_bytes: usize) {
+            unsafe {
+                let slice = slice::from_raw_parts(ptr, num_bytes);
+                let str = std::str::from_utf8(slice).unwrap();
+                println!("{}", str);
+            }
         }
     }
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]