rustc: Introduce ABI versioning so we can change value representations without breaking the compiler
This commit is contained in:
parent
2f650038ad
commit
25416bfae1
1
mk/rt.mk
1
mk/rt.mk
@ -26,6 +26,7 @@ RUNTIME_CS := rt/sync/timer.cpp \
|
||||
rt/rust_shape.cpp \
|
||||
rt/rust_obstack.cpp \
|
||||
rt/rust_gc.cpp \
|
||||
rt/rust_abi.cpp \
|
||||
rt/memory_region.cpp \
|
||||
rt/test/rust_test_harness.cpp \
|
||||
rt/test/rust_test_runtime.cpp \
|
||||
|
@ -112,6 +112,8 @@ const ivec_heap_elt_elems: uint = 1u;
|
||||
|
||||
const worst_case_glue_call_args: int = 7;
|
||||
|
||||
const abi_version: uint = 1u;
|
||||
|
||||
fn memcpy_glue_name() -> str { ret "rust_memcpy_glue"; }
|
||||
|
||||
fn bzero_glue_name() -> str { ret "rust_bzero_glue"; }
|
||||
|
@ -84,15 +84,20 @@ fn eq_res_info(a: &res_info, b: &res_info) -> bool {
|
||||
ret a.did.crate == b.did.crate && a.did.node == b.did.node && a.t == b.t;
|
||||
}
|
||||
|
||||
fn mk_global(ccx: &@crate_ctxt, name: &str, llval: ValueRef) -> ValueRef {
|
||||
fn mk_global(ccx: &@crate_ctxt, name: &str, llval: ValueRef,
|
||||
internal: bool) -> ValueRef {
|
||||
let llglobal =
|
||||
lib::llvm::llvm::LLVMAddGlobal(ccx.llmod, val_ty(llval),
|
||||
str::buf(name));
|
||||
lib::llvm::llvm::LLVMSetInitializer(llglobal, llval);
|
||||
lib::llvm::llvm::LLVMSetGlobalConstant(llglobal, True);
|
||||
lib::llvm::llvm::LLVMSetLinkage(llglobal,
|
||||
lib::llvm::LLVMInternalLinkage as
|
||||
lib::llvm::llvm::Linkage);
|
||||
|
||||
if (internal) {
|
||||
lib::llvm::llvm::LLVMSetLinkage(llglobal,
|
||||
lib::llvm::LLVMInternalLinkage as
|
||||
lib::llvm::llvm::Linkage);
|
||||
}
|
||||
|
||||
ret llglobal;
|
||||
}
|
||||
|
||||
@ -510,7 +515,7 @@ fn gen_tag_shapes(ccx: &@crate_ctxt) -> ValueRef {
|
||||
header += data;
|
||||
header += lv_table;
|
||||
|
||||
ret mk_global(ccx, "tag_shapes", C_bytes(header));
|
||||
ret mk_global(ccx, "tag_shapes", C_bytes(header), true);
|
||||
}
|
||||
|
||||
fn gen_resource_shapes(ccx: &@crate_ctxt) -> ValueRef {
|
||||
@ -523,7 +528,7 @@ fn gen_resource_shapes(ccx: &@crate_ctxt) -> ValueRef {
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
ret mk_global(ccx, "resource_shapes", C_struct(dtors));
|
||||
ret mk_global(ccx, "resource_shapes", C_struct(dtors), true);
|
||||
}
|
||||
|
||||
fn gen_shape_tables(ccx: &@crate_ctxt) {
|
||||
|
@ -6926,6 +6926,12 @@ fn write_metadata(cx: &@crate_ctxt, crate: &@ast::crate) {
|
||||
llvm::LLVMSetInitializer(llvm_used, C_array(t_ptr_i8, [llglobal]));
|
||||
}
|
||||
|
||||
// Writes the current ABI version into the crate.
|
||||
fn write_abi_version(ccx: &@crate_ctxt) {
|
||||
shape::mk_global(ccx, "rust_abi_version", C_uint(abi::abi_version),
|
||||
false);
|
||||
}
|
||||
|
||||
fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
|
||||
output: &str, amap: &ast_map::map) -> ModuleRef {
|
||||
let llmod =
|
||||
@ -7001,6 +7007,7 @@ fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
|
||||
create_crate_map(ccx);
|
||||
emit_tydescs(ccx);
|
||||
shape::gen_shape_tables(ccx);
|
||||
write_abi_version(ccx);
|
||||
|
||||
// Translate the metadata.
|
||||
write_metadata(cx.ccx, crate);
|
||||
|
10
src/rt/rust_abi.cpp
Normal file
10
src/rt/rust_abi.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include "rust_abi.h"
|
||||
|
||||
weak_symbol<uint32_t> abi_version("rust_abi_version");
|
||||
|
||||
uint32_t get_abi_version() {
|
||||
return (*abi_version == NULL) ? 0 : **abi_version;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef RUST_ABI_H
|
||||
#define RUST_ABI_H
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#ifdef __WIN32__
|
||||
#include <windows.h>
|
||||
#else
|
||||
@ -34,5 +36,7 @@ public:
|
||||
T *&operator*() { fill(); return data; }
|
||||
};
|
||||
|
||||
uint32_t get_abi_version();
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user