Skip to content

Commit 3613555

Browse files
committed
CHB:ARM: make typing rules configurable
1 parent 164770f commit 3613555

File tree

4 files changed

+550
-347
lines changed

4 files changed

+550
-347
lines changed

CodeHawk/CHB/bchlib/bCHFunctionData.ml

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -280,31 +280,39 @@ object (self)
280280
__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
281281
^ "No stackvar annotation found at offset " ^ (string_of_int offset)]
282282

283-
method is_typing_rule_enabled (loc: string) (name: string): bool =
283+
method is_typing_rule_enabled ?(rdef=None) (loc: string) (name: string): bool =
284+
let rdefloc =
285+
match rdef with
286+
| None -> loc
287+
| Some rdefaddr -> loc ^ ":" ^ rdefaddr in
284288
match self#get_function_annotation with
285-
| None -> false
289+
| None -> BCHSystemSettings.system_settings#is_typing_rule_enabled name
286290
| Some a ->
287-
List.fold_left
288-
(fun acc tra ->
289-
acc ||
290-
(if tra.tra_action = "enable" && tra.tra_name = name then
291-
(List.mem "all" tra.tra_locations)
292-
|| (List.mem loc tra.tra_locations)
293-
else
294-
false)) false a.typingrules
295-
296-
method is_typing_rule_disabled (loc: string) (name: string): bool =
297-
match self#get_function_annotation with
298-
| None -> false
299-
| Some a ->
300-
List.fold_left
301-
(fun acc tra ->
302-
acc ||
303-
(if tra.tra_action = "disable" && tra.tra_name = name then
304-
(List.mem "all" tra.tra_locations)
305-
|| (List.mem loc tra.tra_locations)
306-
else
307-
false)) false a.typingrules
291+
let is_user_enabled () =
292+
List.fold_left
293+
(fun acc tra ->
294+
acc ||
295+
(if tra.tra_action = "enable" && tra.tra_name = name then
296+
(List.mem "all" tra.tra_locations)
297+
|| (List.mem loc tra.tra_locations)
298+
else
299+
false)) false a.typingrules in
300+
let is_user_disabled () =
301+
List.fold_left
302+
(fun acc tra ->
303+
acc ||
304+
(if tra.tra_action = "disable" && tra.tra_name = name then
305+
(List.mem "all" tra.tra_locations)
306+
|| (List.mem loc tra.tra_locations)
307+
|| (List.mem rdefloc tra.tra_locations)
308+
else
309+
false)) false a.typingrules in
310+
if is_user_enabled () then
311+
true
312+
else if is_user_disabled () then
313+
false
314+
else
315+
BCHSystemSettings.system_settings#is_typing_rule_enabled name
308316

309317
method add_inlined_block (baddr:doubleword_int) =
310318
inlined_blocks <- baddr :: inlined_blocks

CodeHawk/CHB/bchlib/bCHLibTypes.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,7 @@ object
14431443
method is_elf: bool
14441444
method is_pe: bool
14451445
method is_verbose: bool
1446+
method is_typing_rule_enabled: string -> bool
14461447
method is_debug_excluded: bool
14471448
method is_sideeffects_on_global_enabled: string -> bool
14481449
method is_abstract_stackvars_disabled: bool
@@ -1574,8 +1575,7 @@ class type function_data_int =
15741575
method has_regvar_type_cast: doubleword_int -> bool
15751576
method has_stackvar_type_annotation: int -> bool
15761577
method has_stackvar_type_cast: int -> bool
1577-
method is_typing_rule_enabled: string -> string -> bool
1578-
method is_typing_rule_disabled: string -> string -> bool
1578+
method is_typing_rule_enabled: ?rdef:string option -> string -> string -> bool
15791579
method has_class_info: bool
15801580
method has_callsites: bool
15811581
method has_path_contexts: bool

CodeHawk/CHB/bchlib/bCHSystemSettings.ml

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Copyright (c) 2005-2019 Kestrel Technology LLC
88
Copyright (c) 2020 Henny Sipma
9-
Copyright (c) 2021-2024 Aarno Labs LLC
9+
Copyright (c) 2021-2025 Aarno Labs LLC
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a copy
1212
of this software and associated documentation files (the "Software"), to deal
@@ -38,6 +38,7 @@ open BCHBasicTypes
3838
open BCHLibTypes
3939
open BCHUtilities
4040

41+
module H = Hashtbl
4142

4243
let fns_included = ref []
4344
let include_function (s: string) = fns_included := s :: !fns_included
@@ -49,6 +50,76 @@ let exclude_function (s: string) = fns_excluded := s :: !fns_excluded
4950
let excluded_functions () = !fns_excluded
5051

5152

53+
let arm_typingrules_settings = H.create 23
54+
55+
let _ =
56+
List.iter (fun (r, s) ->
57+
H.add arm_typingrules_settings r s)
58+
[(* propagation rules *)
59+
("ADD-c", "enable");
60+
("AND-rdef", "enable");
61+
("ASR-rdef", "enable");
62+
("CMP-rdef", "enable");
63+
("LSL_rdef", "enable");
64+
("LSR_rdef", "enable");
65+
("MOV-c", "enable");
66+
("MOV-rdef", "enable");
67+
("MVN-rdef", "enable");
68+
("ORR-rdef", "enable");
69+
("POP-rdef", "enable");
70+
("RSB-rdef", "enable");
71+
("SMULL-rdef", "enable");
72+
("STR-rdef", "enable");
73+
("SUB-rdef", "enable");
74+
("UBFX-rdef", "enable");
75+
76+
(* load/store rules *)
77+
("LDR-load", "enable");
78+
("LDRB-load", "enable");
79+
("LDRH-load", "enable");
80+
("STR-store", "enable");
81+
("STRB-store", "enable");
82+
("STRH-store", "enable");
83+
84+
(* function return type back propagation *)
85+
("ADD-exituse", "enable");
86+
("AND-exituse", "enable");
87+
("ASR-exituse", "enable");
88+
("LDR-exituse", "enable");
89+
("LDRB-exituse", "enable");
90+
("LDRH-exituse", "enable");
91+
("LSL-exituse", "enable");
92+
("LSR-exituse", "enable");
93+
("MOV-exituse", "enable");
94+
("MVN-exituse", "enable");
95+
("ORR-exituse", "enable");
96+
("RSB-exituse", "enable");
97+
("SUB-exituse", "enable");
98+
("UBFX-exituse", "enable");
99+
("UXTH-exituse", "enable");
100+
101+
(* default setting of lhs *)
102+
("ASR-def-lhs", "enable");
103+
("LDRB-def-lhs", "enable");
104+
("LDRH-def-lhs", "enable");
105+
("MVN-def-lhs", "enable");
106+
("SMULL-def-lhs", "enable");
107+
("UXTH-def-lhs", "enable");
108+
109+
(* misc rules *)
110+
("ADD-global", "enable");
111+
("BL-sig-regarg", "enable");
112+
("BL-sig-stackarg", "enable");
113+
("BL-sig-rv", "enable");
114+
("LDR-array", "enable");
115+
("LDR-memop-tc", "enable");
116+
("LDR-stack-addr", "enable");
117+
("LDR-struct-field", "enable");
118+
("LDRH-memop-tc", "enable");
119+
("POP-sig-rv", "enable")
120+
]
121+
122+
52123
(* -------------------------------------------------------------------------
53124
* Command-line switches:
54125
* - set_vftables: for all jump tables, if one of the targets is a function entry
@@ -313,6 +384,13 @@ object (self)
313384
| [] -> not (List.mem gv not_record_sideeffects_on_globals)
314385
| l -> List.mem gv l)
315386

387+
method is_typing_rule_enabled (name: string) =
388+
match self#get_architecture with
389+
| "arm" ->
390+
(H.mem arm_typingrules_settings name)
391+
&& (H.find arm_typingrules_settings name) == "enable"
392+
| _ -> false
393+
316394
end
317395

318396

0 commit comments

Comments
 (0)