Skip to content

Commit 25416bf

Browse files
committed
rustc: Introduce ABI versioning so we can change value representations without breaking the compiler
1 parent 2f65003 commit 25416bf

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

mk/rt.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ RUNTIME_CS := rt/sync/timer.cpp \
2626
rt/rust_shape.cpp \
2727
rt/rust_obstack.cpp \
2828
rt/rust_gc.cpp \
29+
rt/rust_abi.cpp \
2930
rt/memory_region.cpp \
3031
rt/test/rust_test_harness.cpp \
3132
rt/test/rust_test_runtime.cpp \

src/comp/back/abi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ const ivec_heap_elt_elems: uint = 1u;
112112

113113
const worst_case_glue_call_args: int = 7;
114114

115+
const abi_version: uint = 1u;
116+
115117
fn memcpy_glue_name() -> str { ret "rust_memcpy_glue"; }
116118

117119
fn bzero_glue_name() -> str { ret "rust_bzero_glue"; }

src/comp/middle/shape.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,20 @@ fn eq_res_info(a: &res_info, b: &res_info) -> bool {
8484
ret a.did.crate == b.did.crate && a.did.node == b.did.node && a.t == b.t;
8585
}
8686

87-
fn mk_global(ccx: &@crate_ctxt, name: &str, llval: ValueRef) -> ValueRef {
87+
fn mk_global(ccx: &@crate_ctxt, name: &str, llval: ValueRef,
88+
internal: bool) -> ValueRef {
8889
let llglobal =
8990
lib::llvm::llvm::LLVMAddGlobal(ccx.llmod, val_ty(llval),
9091
str::buf(name));
9192
lib::llvm::llvm::LLVMSetInitializer(llglobal, llval);
9293
lib::llvm::llvm::LLVMSetGlobalConstant(llglobal, True);
93-
lib::llvm::llvm::LLVMSetLinkage(llglobal,
94-
lib::llvm::LLVMInternalLinkage as
95-
lib::llvm::llvm::Linkage);
94+
95+
if (internal) {
96+
lib::llvm::llvm::LLVMSetLinkage(llglobal,
97+
lib::llvm::LLVMInternalLinkage as
98+
lib::llvm::llvm::Linkage);
99+
}
100+
96101
ret llglobal;
97102
}
98103

@@ -510,7 +515,7 @@ fn gen_tag_shapes(ccx: &@crate_ctxt) -> ValueRef {
510515
header += data;
511516
header += lv_table;
512517

513-
ret mk_global(ccx, "tag_shapes", C_bytes(header));
518+
ret mk_global(ccx, "tag_shapes", C_bytes(header), true);
514519
}
515520

516521
fn gen_resource_shapes(ccx: &@crate_ctxt) -> ValueRef {
@@ -523,7 +528,7 @@ fn gen_resource_shapes(ccx: &@crate_ctxt) -> ValueRef {
523528
i += 1u;
524529
}
525530

526-
ret mk_global(ccx, "resource_shapes", C_struct(dtors));
531+
ret mk_global(ccx, "resource_shapes", C_struct(dtors), true);
527532
}
528533

529534
fn gen_shape_tables(ccx: &@crate_ctxt) {

src/comp/middle/trans.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6926,6 +6926,12 @@ fn write_metadata(cx: &@crate_ctxt, crate: &@ast::crate) {
69266926
llvm::LLVMSetInitializer(llvm_used, C_array(t_ptr_i8, [llglobal]));
69276927
}
69286928

6929+
// Writes the current ABI version into the crate.
6930+
fn write_abi_version(ccx: &@crate_ctxt) {
6931+
shape::mk_global(ccx, "rust_abi_version", C_uint(abi::abi_version),
6932+
false);
6933+
}
6934+
69296935
fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
69306936
output: &str, amap: &ast_map::map) -> ModuleRef {
69316937
let llmod =
@@ -7001,6 +7007,7 @@ fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
70017007
create_crate_map(ccx);
70027008
emit_tydescs(ccx);
70037009
shape::gen_shape_tables(ccx);
7010+
write_abi_version(ccx);
70047011

70057012
// Translate the metadata.
70067013
write_metadata(cx.ccx, crate);

src/rt/rust_abi.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <cstdlib>
2+
#include <stdint.h>
3+
#include "rust_abi.h"
4+
5+
weak_symbol<uint32_t> abi_version("rust_abi_version");
6+
7+
uint32_t get_abi_version() {
8+
return (*abi_version == NULL) ? 0 : **abi_version;
9+
}
10+

src/rt/rust_abi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef RUST_ABI_H
22
#define RUST_ABI_H
33

4+
#include <cstdlib>
5+
46
#ifdef __WIN32__
57
#include <windows.h>
68
#else
@@ -34,5 +36,7 @@ class weak_symbol {
3436
T *&operator*() { fill(); return data; }
3537
};
3638

39+
uint32_t get_abi_version();
40+
3741
#endif
3842

0 commit comments

Comments
 (0)