Skip to content

Commit ee95371

Browse files
committed
CHB:ARM: disable hearistic for finding non-returning functions
1 parent 8ed461a commit ee95371

File tree

3 files changed

+66
-48
lines changed

3 files changed

+66
-48
lines changed

CodeHawk/CHB/bchlib/bCHVersion.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ end
9595

9696

9797
let version = new version_info_t
98-
~version:"0.6.0_20241125"
99-
~date:"2024-11-25"
98+
~version:"0.6.0_20241127"
99+
~date:"2024-11-27"
100100
~licensee: None
101101
~maxfilesize: None
102102
()

CodeHawk/CHB/bchlibarm32/bCHDisassembleARM.ml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ open BCHELFTypes
5656
open BCHARMAssemblyFunctions
5757
open BCHARMAssemblyInstruction
5858
open BCHARMAssemblyInstructions
59-
open BCHARMCallSitesRecords
6059
open BCHARMInstructionAggregate
6160
open BCHARMPseudocode
6261
open BCHARMOpcodeRecords
@@ -455,6 +454,18 @@ let get_so_target (tgtaddr:doubleword_int) (_instr:arm_assembly_instruction_int)
455454
None
456455

457456

457+
let register_non_returning_functions () =
458+
List.map (fun fndata ->
459+
if fndata#is_non_returning then
460+
()
461+
else if fndata#has_name then
462+
let fname = fndata#get_function_name in
463+
if function_summary_library#has_so_function fname then
464+
let fsum = function_summary_library#get_so_function fname in
465+
if fsum#is_nonreturning then
466+
fndata#set_non_returning) functions_data#get_functions
467+
468+
458469
(* can be used before functions have been constructed *)
459470
let is_nr_call_instruction (instr:arm_assembly_instruction_int) =
460471
match instr#get_opcode with
@@ -947,9 +958,11 @@ let construct_functions_arm ?(construct_all_functions=false) () =
947958
List.iter
948959
(fun dw -> ignore (functions_data#add_function dw))
949960
(List.map (fun s -> TR.tget_ok (string_to_doubleword s)) fns_included) in
961+
let _ = register_non_returning_functions () in
950962
let _ = collect_call_targets () in
951963
let _ = set_block_boundaries () in
952964
let _ = pr_timing [STR "block boundaries set"] in
965+
(* Disabled for now; it generates too many spurious non-returning functions.
953966
let _ = !arm_assembly_instructions#collect_callsites in
954967
let _ = pr_timing [STR "callsites collected"] in
955968
let _ =
@@ -958,7 +971,7 @@ let construct_functions_arm ?(construct_all_functions=false) () =
958971
if functions_data#is_function_entry_point faddr then
959972
let fndata = functions_data#get_function faddr in
960973
fndata#set_non_returning) nonrfns in
961-
let _ = pr_timing [STR "non-returning functions set"] in
974+
let _ = pr_timing [STR "non-returning functions set"] in *)
962975
let fnentrypoints =
963976
if ((List.length fns_included) = 0) || construct_all_functions then
964977
functions_data#get_function_entry_points

CodeHawk/CHB/bchlibarm32/bCHTranslateARMToCHIF.ml

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -643,13 +643,14 @@ let translate_arm_instruction
643643
| Some dw -> (get_aggregate dw)#is_jumptable
644644
| _ -> false in
645645
let check_storage (_op: arm_operand_int) (v: variable_t) =
646-
if (floc#env#is_unknown_memory_variable v) || v#isTemporary then
647-
ch_error_log#add
648-
"unknown storage location"
649-
(LBLOCK [
650-
floc#l#toPretty;
651-
STR " ";
652-
STR (arm_opcode_to_string instr#get_opcode)]) in
646+
if BCHSystemSettings.system_settings#collect_data then
647+
if (floc#env#is_unknown_memory_variable v) || v#isTemporary then
648+
ch_error_log#add
649+
"unknown storage location"
650+
(LBLOCK [
651+
floc#l#toPretty;
652+
STR " ";
653+
STR (arm_opcode_to_string instr#get_opcode)]) in
653654

654655
let calltgt_cmds (_tgt: arm_operand_int): cmd_t list =
655656
let callargs = floc#get_call_arguments in
@@ -2803,18 +2804,19 @@ let translate_arm_instruction
28032804
let xrn = rewrite_expr floc (rn#to_expr floc) in
28042805
let xrm = rewrite_expr floc (rm#to_expr floc) in
28052806
begin
2806-
ch_error_log#add
2807-
"assignment to unknown memory"
2808-
(LBLOCK [
2809-
floc#l#toPretty;
2810-
STR " STR [";
2811-
rn#toPretty;
2812-
STR ", ";
2813-
rm#toPretty;
2814-
STR "]; base: ";
2815-
x2p xrn;
2816-
STR ", offset: ";
2817-
x2p xrm]);
2807+
(if BCHSystemSettings.system_settings#collect_data then
2808+
ch_error_log#add
2809+
"assignment to unknown memory"
2810+
(LBLOCK [
2811+
floc#l#toPretty;
2812+
STR " STR [";
2813+
rn#toPretty;
2814+
STR ", ";
2815+
rm#toPretty;
2816+
STR "]; base: ";
2817+
x2p xrn;
2818+
STR ", offset: ";
2819+
x2p xrm]));
28182820
[]
28192821
end
28202822
else
@@ -2870,18 +2872,19 @@ let translate_arm_instruction
28702872
let xrn = rewrite_expr floc (rn#to_expr floc) in
28712873
let xrm = rewrite_expr floc (rm#to_expr floc) in
28722874
begin
2873-
ch_error_log#add
2874-
"assignment to unknown memory"
2875-
(LBLOCK [
2876-
floc#l#toPretty;
2877-
STR " STRB [";
2878-
rn#toPretty;
2879-
STR ", ";
2880-
rm#toPretty;
2881-
STR "]; base: ";
2882-
x2p xrn;
2883-
STR ", offset: ";
2884-
x2p xrm]);
2875+
(if BCHSystemSettings.system_settings#collect_data then
2876+
ch_error_log#add
2877+
"assignment to unknown memory"
2878+
(LBLOCK [
2879+
floc#l#toPretty;
2880+
STR " STRB [";
2881+
rn#toPretty;
2882+
STR ", ";
2883+
rm#toPretty;
2884+
STR "]; base: ";
2885+
x2p xrn;
2886+
STR ", offset: ";
2887+
x2p xrm]));
28852888
[]
28862889
end
28872890
else
@@ -3033,18 +3036,19 @@ let translate_arm_instruction
30333036
let xrn = rewrite_expr floc (rn#to_expr floc) in
30343037
let xrm = rewrite_expr floc (rm#to_expr floc) in
30353038
begin
3036-
ch_error_log#add
3037-
"assignment to unknown memory"
3038-
(LBLOCK [
3039-
floc#l#toPretty;
3040-
STR " STRH [";
3041-
rn#toPretty;
3042-
STR ", ";
3043-
rm#toPretty;
3044-
STR "]; base: ";
3045-
x2p xrn;
3046-
STR ", offset: ";
3047-
x2p xrm]);
3039+
(if BCHSystemSettings.system_settings#collect_data then
3040+
ch_error_log#add
3041+
"assignment to unknown memory"
3042+
(LBLOCK [
3043+
floc#l#toPretty;
3044+
STR " STRH [";
3045+
rn#toPretty;
3046+
STR ", ";
3047+
rm#toPretty;
3048+
STR "]; base: ";
3049+
x2p xrn;
3050+
STR ", offset: ";
3051+
x2p xrm]));
30483052
[]
30493053
end
30503054
else
@@ -3069,7 +3073,8 @@ let translate_arm_instruction
30693073
if mem#is_offset_address_writeback then
30703074
let addr_r = mem#to_updated_offset_address floc in
30713075
log_tfold_default
3072-
(log_error "invalid write-back address" ((p2s floc#l#toPretty) ^ ": STRH"))
3076+
(log_error
3077+
"invalid write-back address" ((p2s floc#l#toPretty) ^ ": STRH"))
30733078
(fun (_, addr) ->
30743079
let rnreg = rn#to_register in
30753080
let (vrn, ucmds) =

0 commit comments

Comments
 (0)