Skip to content

Commit 8ecbe49

Browse files
committed
Add -minimal mode to rustboot that skips emitting code that's broken or unneeded for rustc. Shrink rustc by 300kb. Back under 1mb.
1 parent d1e59d6 commit 8ecbe49

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

src/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ endif
368368

369369
$(CFG_COMPILER): $(COMPILER_INPUTS) $(CFG_BOOT) $(CFG_RUNTIME) $(CFG_STDLIB)
370370
@$(call CFG_ECHO, compile: $<)
371-
$(CFG_QUIET)OCAMLRUNPARAM="b1" $(CFG_BOOT) $(CFG_BOOT_FLAGS) -o $@ $<
371+
$(CFG_QUIET)OCAMLRUNPARAM="b1" $(CFG_BOOT) $(CFG_BOOT_FLAGS) \
372+
-minimal -o $@ $<
372373
$(CFG_QUIET)chmod 0755 $@
373374

374375
self: $(CFG_COMPILER)

src/boot/be/abi.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ type abi =
126126
-> Common.nabi
127127
-> Common.fixup (* grow_task *)
128128
-> bool (* is_obj_fn *)
129-
-> unit);
129+
-> bool (* minimal *)
130+
-> unit);
130131

131132
abi_emit_fn_epilogue: (Il.emitter -> unit);
132133

src/boot/be/x86.ml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@ let fn_prologue
12361236
(nabi:nabi)
12371237
(grow_task_fixup:fixup)
12381238
(is_obj_fn:bool)
1239+
(minimal:bool)
12391240
: unit =
12401241

12411242
let esi_n = word_n (h esi) in
@@ -1372,8 +1373,11 @@ let fn_prologue
13721373
in
13731374

13741375
(* "Full" frame size-check. *)
1375-
stack_growth_check e nabi grow_task_fixup
1376-
dynamic_frame_sz dynamic_grow_jmp restart_pc (h esi) (h edi);
1376+
match dynamic_grow_jmp with
1377+
None when minimal -> ()
1378+
| _ ->
1379+
stack_growth_check e nabi grow_task_fixup
1380+
dynamic_frame_sz dynamic_grow_jmp restart_pc (h esi) (h edi);
13771381

13781382

13791383
(* Establish a frame, wherever we landed. *)

src/boot/driver/main.ml

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let (sess:Session.sess) =
2424
Session.sess_out = None;
2525
Session.sess_library_mode = false;
2626
Session.sess_alt_backend = false;
27+
Session.sess_minimal = false;
2728
Session.sess_use_pexps = false;
2829
(* FIXME (issue #69): need something fancier here for unix
2930
* sub-flavours.
@@ -229,6 +230,10 @@ let argspecs =
229230
(flag (fun _ -> sess.Session.sess_use_pexps <- true)
230231
"-pexp" "use pexp portion of AST");
231232

233+
(flag (fun _ -> sess.Session.sess_minimal <- true)
234+
"-minimal" ("reduce code size by disabling various features"
235+
^ " (use at own risk)"));
236+
232237
("-zc", Arg.Int (fun i -> sess.Session.sess_fuzz_item_count <- i),
233238
"count of items to generate when fuzzing");
234239

src/boot/driver/session.ml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type sess =
1313
mutable sess_out: filename option;
1414
mutable sess_library_mode: bool;
1515
mutable sess_alt_backend: bool;
16+
mutable sess_minimal: bool;
1617
mutable sess_use_pexps: bool;
1718
mutable sess_targ: target;
1819
mutable sess_log_lex: bool;

src/boot/me/trans.ml

+22-12
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,7 @@ let trans_visitor
14881488
let frame_fns =
14891489
match fnid with
14901490
None -> zero
1491+
| Some _ when cx.ctxt_sess.Session.sess_minimal -> zero
14911492
| Some fnid -> get_frame_glue_fns fnid
14921493
in
14931494
let crate_ptr_reg = next_vreg () in
@@ -1499,14 +1500,19 @@ let trans_visitor
14991500
mov (word_at (fp_imm frame_fns_disp)) frame_fns
15001501

15011502
and check_interrupt_flag _ =
1502-
let dom = next_vreg_cell wordptr_ty in
1503-
let flag = next_vreg_cell word_sty in
1504-
mov dom (Il.Cell (tp_imm (word_n Abi.task_field_dom)));
1505-
mov flag (Il.Cell (deref_imm dom
1506-
(word_n Abi.dom_field_interrupt_flag)));
1507-
let null_jmp = null_check flag in
1508-
trans_yield ();
1509-
patch null_jmp
1503+
if cx.ctxt_sess.Session.sess_minimal
1504+
then ()
1505+
else
1506+
begin
1507+
let dom = next_vreg_cell wordptr_ty in
1508+
let flag = next_vreg_cell word_sty in
1509+
mov dom (Il.Cell (tp_imm (word_n Abi.task_field_dom)));
1510+
mov flag (Il.Cell (deref_imm dom
1511+
(word_n Abi.dom_field_interrupt_flag)));
1512+
let null_jmp = null_check flag in
1513+
trans_yield ();
1514+
patch null_jmp
1515+
end
15101516

15111517
and trans_glue_frame_entry
15121518
(callsz:size)
@@ -1534,7 +1540,8 @@ let trans_visitor
15341540
push_new_emitter_with_vregs None;
15351541
iflog (fun _ -> annotate "prologue");
15361542
abi.Abi.abi_emit_fn_prologue (emitter())
1537-
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task") false;
1543+
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task")
1544+
false cx.ctxt_sess.Session.sess_minimal;
15381545
write_frame_info_ptrs None;
15391546
(* FIXME: not clear why, but checking interrupt in glue context
15401547
* causes many.rs to crash when run on a sufficiently large number
@@ -4766,7 +4773,8 @@ let trans_visitor
47664773
push_new_emitter_with_vregs (Some id);
47674774
iflog (fun _ -> annotate "prologue");
47684775
abi.Abi.abi_emit_fn_prologue (emitter())
4769-
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task") false;
4776+
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task")
4777+
false cx.ctxt_sess.Session.sess_minimal;
47704778
write_frame_info_ptrs None;
47714779
iflog (fun _ -> annotate "finished prologue");
47724780
trans_block fe.Ast.for_each_body;
@@ -5371,7 +5379,8 @@ let trans_visitor
53715379
(string_of_size callsz)));
53725380
abi.Abi.abi_emit_fn_prologue
53735381
(emitter()) framesz callsz nabi_rust
5374-
(upcall_fixup "upcall_grow_task") obj_fn;
5382+
(upcall_fixup "upcall_grow_task") obj_fn
5383+
cx.ctxt_sess.Session.sess_minimal;
53755384

53765385
write_frame_info_ptrs (Some fnid);
53775386
if yield_check
@@ -5765,7 +5774,8 @@ let trans_visitor
57655774
push_new_emitter_with_vregs (Some b.id);
57665775
iflog (fun _ -> annotate "prologue");
57675776
abi.Abi.abi_emit_fn_prologue (emitter())
5768-
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task") true;
5777+
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task")
5778+
true cx.ctxt_sess.Session.sess_minimal;
57695779
write_frame_info_ptrs None;
57705780
iflog (fun _ -> annotate "finished prologue");
57715781
trans_block b;

0 commit comments

Comments
 (0)