WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit a247e2b2 authored by qinsoon's avatar qinsoon
Browse files

set global int seems working

(cannot load this test as dylib, it would involve PIC code on linux)
parent 290b22ce
......@@ -1026,8 +1026,17 @@ impl ASMCodeGen {
loc_cursor += 1;
},
Value_::Memory(MemoryLocation::Symbolic{ref base, ref label}) => {
result_str.push_str(&symbol(label.clone()));
loc_cursor += label.len();
if base.is_some() && base.as_ref().unwrap().id() == x86_64::RIP.id() {
// pc relative address
// let pic_symbol = pic_symbol(label.clone());
let pic_symbol = symbol(label.clone()); // not sure if we need this
result_str.push_str(&pic_symbol);
loc_cursor += label.len();
} else {
let symbol = symbol(label.clone());
result_str.push_str(&symbol);
loc_cursor += label.len();
}
if base.is_some() {
result_str.push('(');
......@@ -2838,12 +2847,22 @@ fn directive_comm(name: String, size: ByteSize, align: ByteSize) -> String {
pub fn symbol(name: String) -> String {
name
}
#[cfg(target_os = "macos")]
pub fn symbol(name: String) -> String {
format!("_{}", name)
}
#[allow(dead_code)]
#[cfg(target_os = "linux")]
pub fn pic_symbol(name: String) -> String {
format!("{}@GOTPCREL", name)
}
#[allow(dead_code)]
#[cfg(target_os = "macos")]
pub fn pic_symbol(name: String) -> String {
symbol(name)
}
use compiler::machine_code::CompiledFunction;
pub fn spill_rewrite(
......
......@@ -72,23 +72,23 @@ pub fn resolve_backend_type_info (ty: &MuType, vm: &VM) -> BackendTypeInfo {
match size_in_bit {
1 => BackendTypeInfo{
size: 1, alignment: 1, struct_layout: None,
gc_type: mm::add_gc_type(GCType::new_noreftype(1))
gc_type: mm::add_gc_type(GCType::new_noreftype(1, 1))
},
8 => BackendTypeInfo{
size: 1, alignment: 1, struct_layout: None,
gc_type: mm::add_gc_type(GCType::new_noreftype(1))
gc_type: mm::add_gc_type(GCType::new_noreftype(1, 1))
},
16 => BackendTypeInfo{
size: 2, alignment: 2, struct_layout: None,
gc_type: mm::add_gc_type(GCType::new_noreftype(2))
gc_type: mm::add_gc_type(GCType::new_noreftype(2, 2))
},
32 => BackendTypeInfo{
size: 4, alignment: 4, struct_layout: None,
gc_type: mm::add_gc_type(GCType::new_noreftype(4))
gc_type: mm::add_gc_type(GCType::new_noreftype(4, 4))
},
64 => BackendTypeInfo{
size: 8, alignment: 8, struct_layout: None,
gc_type: mm::add_gc_type(GCType::new_noreftype(8))
gc_type: mm::add_gc_type(GCType::new_noreftype(8, 8))
},
_ => unimplemented!()
}
......@@ -107,18 +107,18 @@ pub fn resolve_backend_type_info (ty: &MuType, vm: &VM) -> BackendTypeInfo {
| MuType_::ThreadRef
| MuType_::StackRef => BackendTypeInfo{
size: 8, alignment: 8, struct_layout: None,
gc_type: mm::add_gc_type(GCType::new_noreftype(8))
gc_type: mm::add_gc_type(GCType::new_noreftype(8, 8))
},
// tagref
MuType_::Tagref64 => unimplemented!(),
// floating point
MuType_::Float => BackendTypeInfo{
size: 4, alignment: 4, struct_layout: None,
gc_type: mm::add_gc_type(GCType::new_noreftype(4))
gc_type: mm::add_gc_type(GCType::new_noreftype(4, 4))
},
MuType_::Double => BackendTypeInfo {
size: 8, alignment: 8, struct_layout: None,
gc_type: mm::add_gc_type(GCType::new_noreftype(8))
gc_type: mm::add_gc_type(GCType::new_noreftype(8, 8))
},
// array
MuType_::Array(ref ty, len) => {
......@@ -131,6 +131,7 @@ pub fn resolve_backend_type_info (ty: &MuType, vm: &VM) -> BackendTypeInfo {
gc_type : mm::add_gc_type(GCType {
id : GCTYPE_INIT_ID,
size : ele_ty.size * len,
alignment: ele_ty.alignment,
non_repeat_refs: None,
repeat_refs : Some(RepeatingRefPattern{
pattern: RefPattern::NestedType(vec![ele_ty.gc_type]),
......@@ -184,7 +185,7 @@ pub fn resolve_backend_type_info (ty: &MuType, vm: &VM) -> BackendTypeInfo {
// void
MuType_::Void => BackendTypeInfo{
size: 0, alignment: 8, struct_layout: None,
gc_type: mm::add_gc_type(GCType::new_noreftype(0))
gc_type: mm::add_gc_type(GCType::new_noreftype(0, 8))
},
// vector
MuType_::Vector(_, _) => unimplemented!()
......@@ -249,6 +250,7 @@ fn layout_struct(tys: &Vec<P<MuType>>, vm: &VM) -> BackendTypeInfo {
gc_type : mm::add_gc_type(GCType {
id : GCTYPE_INIT_ID,
size : size,
alignment: struct_align,
non_repeat_refs: Some(if use_ref_offsets {
RefPattern::Map {
offsets: ref_offsets,
......
......@@ -11,15 +11,17 @@ pub const GCTYPE_INIT_ID: u32 = u32::MAX;
pub struct GCType {
pub id: u32,
pub size: ByteSize,
pub alignment: ByteSize,
pub non_repeat_refs: Option<RefPattern>,
pub repeat_refs : Option<RepeatingRefPattern>,
}
impl GCType {
pub fn new_noreftype(size: ByteSize) -> GCType {
pub fn new_noreftype(size: ByteSize, align: ByteSize) -> GCType {
GCType {
id: GCTYPE_INIT_ID,
size: size,
alignment: align,
non_repeat_refs: None,
repeat_refs : None,
}
......@@ -29,6 +31,7 @@ impl GCType {
GCType {
id: GCTYPE_INIT_ID,
size: POINTER_SIZE,
alignment: POINTER_SIZE,
non_repeat_refs: Some(RefPattern::Map{
offsets: vec![0],
size: POINTER_SIZE
......@@ -126,6 +129,7 @@ mod tests {
let a = GCType{
id: 0,
size: 16,
alignment: 8,
non_repeat_refs: Some(RefPattern::Map{
offsets: vec![0],
size: 16
......@@ -137,6 +141,7 @@ mod tests {
let b = GCType {
id: 1,
size: 160,
alignment: 8,
non_repeat_refs: None,
repeat_refs : Some(RepeatingRefPattern {
pattern: RefPattern::Map{
......@@ -151,6 +156,7 @@ mod tests {
let c = GCType {
id: 2,
size: 1600,
alignment: 8,
non_repeat_refs: None,
repeat_refs : Some(RepeatingRefPattern {
pattern: RefPattern::NestedType(vec![Arc::new(b.clone()).clone()]),
......@@ -177,6 +183,7 @@ mod tests {
let int = GCType {
id: 3,
size: 8,
alignment: 8,
non_repeat_refs: None,
repeat_refs: None
};
......
......@@ -273,6 +273,7 @@ mod tests {
let a = GCType{
id: 0,
size: 16,
alignment: 8,
non_repeat_refs: Some(RefPattern::Map{
offsets: vec![0],
size: 16
......@@ -295,6 +296,7 @@ mod tests {
let a = GCType{
id: 0,
size: 32,
alignment: 8,
non_repeat_refs: Some(RefPattern::Map{
offsets: vec![0, 8],
size: 32
......@@ -317,6 +319,7 @@ mod tests {
const N_REF : usize = 64;
let a = GCType{
id: 999,
alignment: 8,
size: N_REF * POINTER_SIZE,
non_repeat_refs: Some(RefPattern::Map{
offsets: (0..N_REF).map(|x| x * POINTER_SIZE).collect(),
......@@ -339,6 +342,7 @@ mod tests {
let a = GCType {
id: 1,
size: 160,
alignment: 8,
non_repeat_refs: None,
repeat_refs : Some(RepeatingRefPattern {
pattern: RefPattern::Map{
......@@ -364,6 +368,7 @@ mod tests {
let b = GCType {
id: 1,
size: 160,
alignment: 8,
non_repeat_refs: None,
repeat_refs : Some(RepeatingRefPattern {
pattern: RefPattern::Map{
......@@ -378,6 +383,7 @@ mod tests {
let a = GCType {
id: 2,
size: 1600,
alignment: 8,
non_repeat_refs: None,
repeat_refs : Some(RepeatingRefPattern {
pattern: RefPattern::NestedType(vec![Arc::new(b.clone()).clone()]),
......
......@@ -55,6 +55,7 @@ fn link_dylib_internal (files: Vec<PathBuf>, out: PathBuf) -> PathBuf {
let mut gcc = Command::new(get_test_clang_path());
gcc.arg("-shared");
gcc.arg("-fPIC");
gcc.arg("-Wl");
gcc.arg("-undefined");
gcc.arg("dynamic_lookup");
......
......@@ -505,7 +505,7 @@ impl <'a> VM {
while expect_id < gc_type.id {
use runtime::mm::common::gctype::GCType;
mm::add_gc_type(GCType::new_noreftype(0));
mm::add_gc_type(GCType::new_noreftype(0, 8));
expect_id += 1;
}
}
......
......@@ -3,6 +3,7 @@ extern crate log;
extern crate libloading;
use test_ir::test_ir::global_access;
use test_compiler::test_call::gen_ccall_exit;
use self::mu::compiler::*;
use self::mu::vm::VM;
use self::mu::runtime::thread::MuThread;
......@@ -13,6 +14,7 @@ use self::mu::ast::op::*;
use utils::Address;
use utils::LinkedHashMap;
use mu::testutil;
use mu::testutil::aot;
use mu::vm::handle;
use std::sync::RwLock;
......@@ -53,9 +55,9 @@ fn test_set_global_by_api() {
set_global_by_api(&vm);
let compiler = Compiler::new(CompilerPolicy::default(), vm.clone());
let func_id = vm.id_of("set_global_by_api");
{
let func_id = vm.id_of("set_global_by_api");
let funcs = vm.funcs().read().unwrap();
let func = funcs.get(&func_id).unwrap().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
......@@ -66,39 +68,35 @@ fn test_set_global_by_api() {
// set global by api here
{
let global_id = vm.id_of("a");
let global_id = vm.id_of("my_global");
let global_handle = vm.handle_from_global(global_id);
let uint64_1_handle = vm.handle_from_uint64(1, 64);
let uint64_10_handle = vm.handle_from_uint64(10, 64);
debug!("write {:?} to location {:?}", uint64_1_handle, global_handle);
handle::store(MemoryOrder::Relaxed, global_handle, uint64_1_handle);
debug!("write {:?} to location {:?}", uint64_10_handle, global_handle);
handle::store(MemoryOrder::Relaxed, global_handle, uint64_10_handle);
}
// then emit context (global will be put into context.s
vm.make_primordial_thread(func_id, vec![]);
backend::emit_context(&vm);
// link
let lib = {
let libname = &testutil::get_dylib_name("set_global_by_api");
let dylib = testutil::aot::link_dylib(vec![Mu("set_global_by_api")], libname, &vm);
libloading::Library::new(dylib.as_os_str()).unwrap()
};
let executable = aot::link_primordial(vec![Mu("set_global_by_api")], "set_global_by_api_test", &vm);
let output = aot::execute_nocheck(executable);
unsafe {
let set_global_by_api : libloading::Symbol<unsafe extern fn () -> u64> = lib.get(b"set_global_by_api").unwrap();
assert!(output.status.code().is_some());
let res = set_global_by_api();
println!("set_global_by_api() = {}", res);
assert!(res == 1);
}
let ret_code = output.status.code().unwrap();
println!("return code: {} (i.e. the value set before)", ret_code);
assert!(ret_code == 10);
}
fn set_global_by_api(vm: &VM) {
typedef! ((vm) int64 = mu_int(64));
typedef! ((vm) iref_int64 = mu_iref(int64));
globaldef! ((vm) <int64> a);
globaldef! ((vm) <int64> my_global);
funcsig! ((vm) sig = () -> (int64));
funcdecl! ((vm) <sig> set_global_by_api);
......@@ -107,17 +105,20 @@ fn set_global_by_api(vm: &VM) {
// blk entry
block! ((vm, set_global_by_api_v1) blk_entry);
ssa! ((vm, set_global_by_api_v1) <int64> val);
global! ((vm, set_global_by_api_v1) blk_entry_a = a);
global! ((vm, set_global_by_api_v1) blk_entry_my_global = my_global);
inst! ((vm, set_global_by_api_v1) blk_entry_load:
val = LOAD blk_entry_a (is_ptr: false, order: MemoryOrder::SeqCst)
val = LOAD blk_entry_my_global (is_ptr: false, order: MemoryOrder::SeqCst)
);
let blk_entry_exit = gen_ccall_exit(val.clone(), &mut set_global_by_api_v1, &vm);
// won't execute this inst
inst! ((vm, set_global_by_api_v1) blk_entry_ret:
RET (val)
);
define_block! ((vm, set_global_by_api_v1) blk_entry() {
blk_entry_load, blk_entry_ret
blk_entry_load, blk_entry_exit, blk_entry_ret
});
define_func_ver!((vm) set_global_by_api_v1 (entry: blk_entry) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment