Open7

bdwgc "Exclusion ranges overlap" なぜ

yharayhara

これね。

/Users/yhara/proj/shiika % rake tmp
cd src/rustlib
cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
cd -
llvm-as examples/b.sk.ll
clang -target x86_64-apple-macosx10.15.7 -L/usr/local/opt/bdw-gc/lib/ -lgc -o b.out ~/tmp/shiika/debug/librustlib.a examples/b.sk.bc builtin/builtin.bc
./b.out
Exclusion ranges overlap
yharayhara

Rust側(関係ないものも含む)

use bdwgc_alloc::Allocator;
use std::collections::HashMap;

#[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator;

#[no_mangle]
extern "C" fn shiika_bad(_b: Bad) -> Bad {
    let mut h = HashMap::new();
    h.insert("hello".to_string(), 1);
    let b = Box::new(h);
    Bad { 
       v: Box::leak(b)
    }
}
#[repr(C)]
#[derive(Debug)]
pub struct Bad {
    v: *const HashMap<String, i64>,
}
#[no_mangle]
extern "C" fn shiika_nop() {
}
#[no_mangle]
extern "C" fn shiika_hello(number: *const SkInt) -> *const SkInt {
    unsafe {
        box_int( (*number).value + 1 )
    }
}

extern {
    fn box_int(number: i64) -> *const SkInt;
}

#[repr(C)]
#[derive(Debug)]
pub struct SkInt {
    vtable: *const u8,
    value: i64,
}
yharayhara

main側

define void @user_main() {
...
  call void @shiika_nop()
...
}

define i32 @main() {
  call void @GC_init()
  call void @init_constants()
  call void @user_main()
  ret i32 0
}

declare void @shiika_nop()
yharayhara

不思議なのはこの call void @shiika_nop() を外すとエラーが消えること。

アセンブラのdiffも取ってみたけど、以下のようにcallq以外違いがなかった。

86a87
>       callq   _shiika_nop
yharayhara

↑そのようにしたらエラーはなくなったのでとりあえずヨシとする。