Skip to content

Commit a74feaf

Browse files
committed
rustc: Link with intrinsics.bc; change intrinsics linkage to linkonce_odr
1 parent 48e0de2 commit a74feaf

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/comp/back/Link.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import driver.session;
22
import lib.llvm.llvm;
33
import middle.trans;
44
import std._str;
5+
import std.fs;
56

67
import lib.llvm.llvm.ModuleRef;
78
import lib.llvm.llvm.ValueRef;
89
import lib.llvm.mk_pass_manager;
910
import lib.llvm.mk_target_data;
1011
import lib.llvm.mk_type_names;
12+
import lib.llvm.False;
1113

1214
tag output_type {
1315
output_type_none;
@@ -16,8 +18,30 @@ tag output_type {
1618
output_type_object;
1719
}
1820

21+
fn llvm_err(session.session sess, str msg) {
22+
sess.err(msg + ": " + _str.str_from_cstr(llvm.LLVMRustGetLastError()));
23+
fail;
24+
}
25+
1926
fn link_intrinsics(session.session sess, ModuleRef llmod) {
20-
// TODO
27+
auto path = fs.connect(sess.get_opts().sysroot, "intrinsics.bc");
28+
auto membuf =
29+
llvm.LLVMRustCreateMemoryBufferWithContentsOfFile(_str.buf(path));
30+
if ((membuf as uint) == 0u) {
31+
llvm_err(sess, "installation problem: couldn't open intrinstics.bc");
32+
fail;
33+
}
34+
35+
auto llintrinsicsmod = llvm.LLVMRustParseBitcode(membuf);
36+
if ((llintrinsicsmod as uint) == 0u) {
37+
llvm_err(sess, "installation problem: couldn't parse intrinstics.bc");
38+
fail;
39+
}
40+
41+
if (llvm.LLVMLinkModules(llmod, llintrinsicsmod) == False) {
42+
llvm_err(sess, "couldn't link the module with the intrinsics");
43+
fail;
44+
}
2145
}
2246

2347
mod Write {

src/comp/back/x86.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ fn get_meta_sect_name() -> str {
336336

337337
fn get_data_layout() -> str {
338338
if (_str.eq(target_os(), "macos")) {
339-
ret "e-p:32:32-f64:32:64-i64:32:64-f80:128:128-n8:16:32";
339+
ret "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64" +
340+
"-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" +
341+
"-n8:16:32";
340342
}
341343
if (_str.eq(target_os(), "win32")) {
342344
ret "e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32";

src/rt/intrinsics/intrinsics.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Use `clang++ -emit-llvm -S -arch i386 -O3 -I../isaac -I../uthash -o
2+
// intrinsics.ll intrinsics.cpp`
3+
14
#include "../rust_internal.h"
25

36
extern "C" size_t

src/rt/intrinsics/intrinsics.ll.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ target triple = "@CFG_LLVM_TRIPLE@"
5151
%struct.stk_seg = type { i32, i32, [0 x i8] }
5252
%struct.type_desc = type { %struct.type_desc**, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.UT_hash_handle, i32, [0 x %struct.type_desc*] }
5353

54-
define i32 @rust_intrinsic_vec_len(%struct.rust_task* nocapture %task, %struct.type_desc* nocapture %ty, %struct.rust_vec* nocapture %v) nounwind readonly ssp {
54+
define linkonce_odr i32 @rust_intrinsic_vec_len(%struct.rust_task* nocapture %task, %struct.type_desc* nocapture %ty, %struct.rust_vec* nocapture %v) nounwind readonly ssp {
5555
entry:
5656
%fill = getelementptr inbounds %struct.rust_vec* %v, i32 0, i32 2
5757
%tmp1 = load i32* %fill, align 4, !tbaa !0

0 commit comments

Comments
 (0)