From e0a636a060306fe61a746f0908a6029949765928 Mon Sep 17 00:00:00 2001 From: ivg Date: Tue, 19 Apr 2022 10:24:16 -0400 Subject: [PATCH 1/2] uses function starts as the entires when building the symtab Uses the same initial starting points when building whole program CFG and symbol table. This improves performance and prevents discrepancies between the set of instructions discovered during the disassembly and the set of instructions that are discovered when we build various graph representations. In certain cases, e.g., in the interworked binaries, such discrepancies could result in an abnormal termiantion of a program. --- lib/bap/bap.mli | 4 ++-- lib/bap_disasm/bap_disasm_rec.ml | 1 + lib/bap_disasm/bap_disasm_symtab.ml | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/bap/bap.mli b/lib/bap/bap.mli index 6f8f25b42..dbcedd054 100644 --- a/lib/bap/bap.mli +++ b/lib/bap/bap.mli @@ -7846,8 +7846,8 @@ module Std : sig function [fn] *) val span : fn -> unit memmap - (** [explicit_callee symtab address] returns a callee which is - called from a block with the given [address]. + (** [callee symtab address] returns a callee which is + called from a block with the given [address]. @since 2.5.0 *) diff --git a/lib/bap_disasm/bap_disasm_rec.ml b/lib/bap_disasm/bap_disasm_rec.ml index 662c17391..2433e566d 100644 --- a/lib/bap_disasm/bap_disasm_rec.ml +++ b/lib/bap_disasm/bap_disasm_rec.ml @@ -77,6 +77,7 @@ let has_conditional_jump blk = let global_cfg disasm = Driver.explore disasm ~init:Cfg.empty + ~entries:(Set.to_sequence@@Driver.subroutines disasm) ~block:(fun mem insns -> Driver.execution_order insns >>= KB.List.filter_map ~f:(fun label -> diff --git a/lib/bap_disasm/bap_disasm_symtab.ml b/lib/bap_disasm/bap_disasm_symtab.ml index 53b79d5d3..05513c170 100644 --- a/lib/bap_disasm/bap_disasm_symtab.ml +++ b/lib/bap_disasm/bap_disasm_symtab.ml @@ -174,6 +174,7 @@ let create_intra disasm calls = let create_inter disasm calls init = Disasm.explore disasm ~init + ~entries:(Set.to_sequence@@Disasm.subroutines disasm) ~block:(fun mem _ -> KB.return mem) ~node:(fun _ s -> KB.return s) ~edge:(fun src dst s -> From 6ca87b1304c33187e1428c5d69fea4cf16b036b3 Mon Sep 17 00:00:00 2001 From: ivg Date: Tue, 19 Apr 2022 13:01:44 -0400 Subject: [PATCH 2/2] keeps the whole program CFG as it was It is not really used other than for tests and probably we should eventually fix the tests. --- lib/bap_disasm/bap_disasm_rec.ml | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/bap_disasm/bap_disasm_rec.ml b/lib/bap_disasm/bap_disasm_rec.ml index 2433e566d..662c17391 100644 --- a/lib/bap_disasm/bap_disasm_rec.ml +++ b/lib/bap_disasm/bap_disasm_rec.ml @@ -77,7 +77,6 @@ let has_conditional_jump blk = let global_cfg disasm = Driver.explore disasm ~init:Cfg.empty - ~entries:(Set.to_sequence@@Driver.subroutines disasm) ~block:(fun mem insns -> Driver.execution_order insns >>= KB.List.filter_map ~f:(fun label ->