Ignore ghost subroutines for clang
A ghost subroutine is a subroutine having, in the IR representation, no content. At clang -O0, some might be generated, eg. <foo_func>: foo_addr nop which translates to Empty in BIL.
This commit is contained in:
parent
6c18d9f537
commit
344ac84ef3
1 changed files with 22 additions and 5 deletions
|
@ -98,6 +98,15 @@ let opt_addr_of_blk_elt = function
|
||||||
| `Jmp jmp -> opt_addr_of jmp
|
| `Jmp jmp -> opt_addr_of jmp
|
||||||
| `Phi phi -> opt_addr_of phi
|
| `Phi phi -> opt_addr_of phi
|
||||||
|
|
||||||
|
let is_ghost_sub sub =
|
||||||
|
(** Check whether the subroutine has content *)
|
||||||
|
let is_ghost_block blk =
|
||||||
|
BStd.Blk.elts blk
|
||||||
|
|> BStd.Seq.is_empty
|
||||||
|
in
|
||||||
|
let blk_seq = BStd.Term.enum BStd.blk_t sub in
|
||||||
|
BStd.Seq.for_all blk_seq ~f:is_ghost_block
|
||||||
|
|
||||||
let entrypoint_address blk =
|
let entrypoint_address blk =
|
||||||
(** Find the first instruction address in the current block.
|
(** Find the first instruction address in the current block.
|
||||||
Return None if no instruction has address. *)
|
Return None if no instruction has address. *)
|
||||||
|
@ -746,8 +755,12 @@ let of_prog prog next_instr_graph : subroutine_cfa_map =
|
||||||
(** Extracts the `cfa_changes` of a program *)
|
(** Extracts the `cfa_changes` of a program *)
|
||||||
let fold_step accu sub =
|
let fold_step accu sub =
|
||||||
(try
|
(try
|
||||||
let subroutine_data = process_sub sub next_instr_graph in
|
(match is_ghost_sub sub with
|
||||||
StrMap.add (BStd.Sub.name sub) subroutine_data accu
|
| true -> accu
|
||||||
|
| false ->
|
||||||
|
let subroutine_data = process_sub sub next_instr_graph in
|
||||||
|
StrMap.add (BStd.Sub.name sub) subroutine_data accu
|
||||||
|
)
|
||||||
with
|
with
|
||||||
| InvalidSub -> accu
|
| InvalidSub -> accu
|
||||||
| Inconsistent tid ->
|
| Inconsistent tid ->
|
||||||
|
@ -767,9 +780,13 @@ let build_sub_ranges prog: (memory_address) AddrMap.t =
|
||||||
easy fast access to a member (cf Map.S.find_first) *)
|
easy fast access to a member (cf Map.S.find_first) *)
|
||||||
|
|
||||||
let fold_subroutine accu sub =
|
let fold_subroutine accu sub =
|
||||||
let first_addr = int64_addr_of sub in
|
(match is_ghost_sub sub with
|
||||||
let last_addr = find_last_addr sub in
|
| true -> accu
|
||||||
AddrMap.add first_addr (last_addr) accu
|
| false ->
|
||||||
|
let first_addr = int64_addr_of sub in
|
||||||
|
let last_addr = find_last_addr sub in
|
||||||
|
AddrMap.add first_addr (last_addr) accu
|
||||||
|
)
|
||||||
in
|
in
|
||||||
|
|
||||||
let subroutines = BStd.Term.enum BStd.sub_t prog in
|
let subroutines = BStd.Term.enum BStd.sub_t prog in
|
||||||
|
|
Loading…
Reference in a new issue