Skip to content

Commit 9c4bc7b

Browse files
jyasskingraydon
authored andcommitted
In Mach-O shared libraries, avoid counting an extra load command. Closes rust-lang#99.
1 parent 6cf1fe8 commit 9c4bc7b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: src/boot/be/macho.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,20 @@ let macho_header_32
591591
(flags:file_flag list)
592592
(loadcmds:frag array) : frag =
593593
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
594599
let cmds = DEF (load_commands_fixup, SEQ loadcmds) in
595600
SEQ
596601
[|
597602
WORD (TY_u32, IMM mh_magic);
598603
WORD (TY_u32, IMM (cpu_type_code cpu));
599604
WORD (TY_u32, IMM (cpu_subtype_code sub));
600605
WORD (TY_u32, IMM (file_type_code ftype));
601-
WORD (TY_u32, IMM (Int64.of_int (Array.length loadcmds)));
606+
WORD (TY_u32,
607+
IMM (Int64.of_int (Array.fold_left count_non_mark 0 loadcmds)));
602608
WORD (TY_u32, F_SZ load_commands_fixup);
603609
WORD (TY_u32, IMM (fold_flags file_flag_code flags));
604610
cmds

0 commit comments

Comments
 (0)