@@ -15,6 +15,14 @@ let iflog (sess:Session.sess) (thunk:(unit -> unit)) : unit =
15
15
else ()
16
16
;;
17
17
18
+ let filter_marks (orig :frag array ) : frag array =
19
+ let not_mark (elem :frag ) =
20
+ match elem with
21
+ MARK -> None
22
+ | x -> Some x
23
+ in arr_map_partial orig not_mark
24
+ ;;
25
+
18
26
let (cpu_arch_abi64:int64 ) = 0x01000000L
19
27
;;
20
28
@@ -591,20 +599,14 @@ let macho_header_32
591
599
(flags :file_flag list )
592
600
(loadcmds :frag array ) : frag =
593
601
let load_commands_fixup = new_fixup " load commands" in
594
- let count_non_mark so_far elem =
595
- match elem with
596
- MARK -> so_far
597
- | _ -> so_far + 1
598
- in
599
602
let cmds = DEF (load_commands_fixup, SEQ loadcmds) in
600
603
SEQ
601
604
[|
602
605
WORD (TY_u32 , IMM mh_magic);
603
606
WORD (TY_u32 , IMM (cpu_type_code cpu));
604
607
WORD (TY_u32 , IMM (cpu_subtype_code sub));
605
608
WORD (TY_u32 , IMM (file_type_code ftype));
606
- WORD (TY_u32 ,
607
- IMM (Int64. of_int (Array. fold_left count_non_mark 0 loadcmds)));
609
+ WORD (TY_u32 , IMM (Int64. of_int (Array. length loadcmds)));
608
610
WORD (TY_u32 , F_SZ load_commands_fixup);
609
611
WORD (TY_u32 , IMM (fold_flags file_flag_code flags));
610
612
cmds
@@ -873,8 +875,10 @@ let emit_file
873
875
874
876
let load_commands =
875
877
[|
876
- macho_segment_command " __PAGEZERO" zero_segment_fixup
877
- [] [] [||];
878
+ if sess.Session. sess_library_mode
879
+ then MARK
880
+ else (macho_segment_command " __PAGEZERO" zero_segment_fixup
881
+ [] [] [||]);
878
882
879
883
macho_segment_command " __TEXT" text_segment_fixup
880
884
[VM_PROT_READ ; VM_PROT_EXECUTE ]
@@ -949,7 +953,7 @@ let emit_file
949
953
CPU_SUBTYPE_X86_ALL
950
954
(if sess.Session. sess_library_mode then MH_DYLIB else MH_EXECUTE )
951
955
[ MH_BINDATLOAD ; MH_DYLDLINK ; MH_TWOLEVEL ]
952
- load_commands
956
+ (filter_marks load_commands)
953
957
in
954
958
955
959
let objfile_start e start_fixup rust_start_fixup main_fn_fixup =
0 commit comments