Skip to content

Commit 01ea27b

Browse files
author
Eric Holk
committed
Step 1 of moving task startup to always be cdecl.
1 parent 766d54d commit 01ea27b

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

src/comp/middle/trans.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5842,7 +5842,8 @@ fn mk_spawn_wrapper(&@block_ctxt cx, &@ast::expr func, &ty::t args_ty) ->
58425842
let str wrap_name =
58435843
mangle_internal_name_by_path_and_seq(cx.fcx.lcx.ccx, cx.fcx.lcx.path,
58445844
"spawn_wrapper");
5845-
auto llfndecl = decl_fastcall_fn(llmod, wrap_name, wrapper_fn_type);
5845+
auto llfndecl = decl_cdecl_fn(llmod, wrap_name, wrapper_fn_type);
5846+
58465847
auto fcx = new_fn_ctxt(cx.fcx.lcx, cx.sp, llfndecl);
58475848
auto fbcx = new_top_block_ctxt(fcx);
58485849
// 3u to skip the three implicit args

src/rt/main.ll.in

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010
@_rust_crate_map_toplevel = external global %0
1111

1212
declare fastcc void @_rust_main(i1* nocapture, %task*, %2* nocapture, %5*);
13-
declare i32 @rust_start(i32, i32, i32, i32)
13+
declare i32 @rust_start(i32, i32, i32, i32, i32)
1414

1515
%tydesc = type { %tydesc**, i32, i32, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*, i8*, i8)* }
1616

1717
%task = type { i32, i32, i32, i32, i32, i32, i32, i32 }
1818

19+
define void @_rust_main_wrap(i1* nocapture, %task *, %2* nocapture, %5 *)
20+
{
21+
tail call fastcc void @_rust_main(i1* %0, %task *%1, %2* nocapture %2, %5 *%3)
22+
ret void
23+
}
24+
1925
define i32 @"MAIN"(i32, i32) {
20-
%3 = tail call i32 @rust_start(i32 ptrtoint (void (i1*, %task*, %2*, %5*)* @_rust_main to i32), i32 %0, i32 %1, i32 ptrtoint (%0* @_rust_crate_map_toplevel to i32))
26+
; %3 = tail call i32 @rust_start(i32 ptrtoint (void (i1*, %task*, %2*, %5*)* @_rust_main_wrap to i32), i32 %0, i32 %1, i32 ptrtoint (%0* @_rust_crate_map_toplevel to i32))
27+
%3 = tail call i32 @rust_start(i32 0, i32 %0, i32 %1, i32 ptrtoint (%0* @_rust_crate_map_toplevel to i32), i32 ptrtoint (void (i1*, %task*, %2*, %5*)* @_rust_main_wrap to i32))
2128
ret i32 %3
2229
}

src/rt/rust.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,24 @@ command_line_args : public dom_owned<command_line_args>
7171
}
7272
};
7373

74+
// THIS IS AN UGLY HACK TO MAKE rust_start STILL WORK WITH STAGE0 WHILE WE
75+
// TRANSITION TO ALL-CDECL TASK STARTUP FUNCTIONS.
76+
void FASTCALL
77+
(*real_main)(uintptr_t a, uintptr_t b, uintptr_t c, uintptr_t d) = NULL;
78+
79+
void CDECL fake_main(uintptr_t a, uintptr_t b, uintptr_t c, uintptr_t d)
80+
{
81+
real_main(a, b, c, d);
82+
}
83+
7484
/**
7585
* Main entry point into the Rust runtime. Here we create a Rust service,
7686
* initialize the kernel, create the root domain and run it.
7787
*/
7888

7989
extern "C" CDECL int
80-
rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
90+
rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map,
91+
uintptr_t main_fn_cdecl) {
8192

8293
update_log_settings(crate_map, getenv("RUST_LOG"));
8394
rust_srv *srv = new rust_srv();
@@ -93,12 +104,9 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
93104
DLOG(dom, dom, "startup: arg[%d] = '%s'", i, args->argv[i]);
94105
}
95106

96-
/*
97-
uintptr_t main_args[4] = {0, 0, 0, (uintptr_t)args->args};
98-
dom->root_task->start(main_fn,
99-
(uintptr_t)&main_args, sizeof(main_args));
100-
*/
101-
dom->root_task->start(main_fn,
107+
real_main = (typeof(real_main))main_fn;
108+
if(main_fn) { printf("using fastcall main\n"); }
109+
dom->root_task->start(main_fn ? (uintptr_t)fake_main : main_fn_cdecl,
102110
(uintptr_t)args->args, sizeof(args->args));
103111

104112
int ret = dom->start_main_loop();

src/rt/rust_task.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct spawn_args {
118118
rust_task *task;
119119
uintptr_t a3;
120120
uintptr_t a4;
121-
void (*FASTCALL f)(int *, rust_task *,
121+
void (*CDECL f)(int *, rust_task *,
122122
uintptr_t, uintptr_t);
123123
};
124124

0 commit comments

Comments
 (0)