From 9c4bc7b872569a7d71622c9f56a11e81edec741d Mon Sep 17 00:00:00 2001 From: Jeffrey Yasskin Date: Sat, 10 Jul 2010 15:43:48 +0800 Subject: [PATCH] In Mach-O shared libraries, avoid counting an extra load command. Closes #99. --- src/boot/be/macho.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/boot/be/macho.ml b/src/boot/be/macho.ml index 7fccdfd3548..cdb16ba36bf 100644 --- a/src/boot/be/macho.ml +++ b/src/boot/be/macho.ml @@ -591,6 +591,11 @@ let macho_header_32 (flags:file_flag list) (loadcmds:frag array) : frag = let load_commands_fixup = new_fixup "load commands" in + let count_non_mark so_far elem = + match elem with + MARK -> so_far + | _ -> so_far + 1 + in let cmds = DEF (load_commands_fixup, SEQ loadcmds) in SEQ [| @@ -598,7 +603,8 @@ let macho_header_32 WORD (TY_u32, IMM (cpu_type_code cpu)); WORD (TY_u32, IMM (cpu_subtype_code sub)); WORD (TY_u32, IMM (file_type_code ftype)); - WORD (TY_u32, IMM (Int64.of_int (Array.length loadcmds))); + WORD (TY_u32, + IMM (Int64.of_int (Array.fold_left count_non_mark 0 loadcmds))); WORD (TY_u32, F_SZ load_commands_fixup); WORD (TY_u32, IMM (fold_flags file_flag_code flags)); cmds