Skip to content

Commit ecbb8b0

Browse files
authored
Merge pull request #273 from sipma/armvectorinstr
Armvectorinstr
2 parents fe0c916 + 44b10d1 commit ecbb8b0

19 files changed

Lines changed: 409 additions & 101 deletions

‎CodeHawk/CHB/bchlib/bCHFloc.ml‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ object (self)
24642464
TR.tfold
24652465
~ok:(fun optty ->
24662466
match optty with
2467-
| Some ty -> Ok ty
2467+
| LhsResolved ty -> Ok ty
24682468
| _ ->
24692469
Error [
24702470
(elocm __LINE__);
@@ -3412,6 +3412,8 @@ object (self)
34123412
(List.length vars) > 0
34133413
&& List.for_all is_fixed_type (variables_in_expr x)
34143414

3415+
(* Note: the rhs gets reduced by taking the modulo with the operand max size.
3416+
Default operand width is 32 bits. *)
34153417
method get_assign_commands_r
34163418
?(signed=false)
34173419
?(size=4)
@@ -3448,13 +3450,20 @@ object (self)
34483450
if not signed then
34493451
match rhs with
34503452
| XConst (IntConst n) ->
3451-
let n =
3453+
let n' =
34523454
match size with
34533455
| 1 -> n#modulo numerical_e8
34543456
| 2 -> n#modulo numerical_e16
34553457
| 4 -> n#modulo numerical_e32
34563458
| _ -> n in
3457-
num_constant_expr n
3459+
let _ =
3460+
if not (n#equal n') then
3461+
log_diagnostics_result
3462+
~msg:(p2s self#l#toPretty)
3463+
~tag:"get_assign_commands_r: rhs reduced to fit size"
3464+
__FILE__ __LINE__
3465+
[n#toString ^ " truncated to " ^ n'#toString] in
3466+
num_constant_expr n'
34583467
| _ -> rhs
34593468
else
34603469
rhs in

‎CodeHawk/CHB/bchlib/bCHFunctionData.ml‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ object (self)
152152
val mutable functiontype = t_unknown
153153
val mutable callsites = 0
154154
val mutable pathcontexts = [] (* (ctxt_iaddress_t, ctxt_iaddress_t list) list *)
155-
val mutable reglhstypes = [] (* (register_t * iaddr * btype_t option) list *)
156-
val mutable stacklhstypes = [] (* (offset * btype_t option) list *)
155+
val mutable reglhstypes = [] (* (register_t * iaddr * lhs_type_result_t) list *)
156+
val mutable stacklhstypes = [] (* (offset * lhs_type_result_t) list *)
157157

158158
method set_function_type (ty: btype_t) = functiontype <- ty
159159

@@ -194,29 +194,30 @@ object (self)
194194

195195
method has_callsites = callsites > 0
196196

197-
method set_reglhs_types (regtypes: (register_t * string * btype_t option) list) =
197+
method set_reglhs_types
198+
(regtypes: (register_t * string * lhs_type_result_t) list) =
198199
reglhstypes <- regtypes
199200

200201
method get_reglhs_types = reglhstypes
201202

202-
method get_reglhs_type (reg: register_t) (iaddr: string): btype_t option =
203+
method get_reglhs_type (reg: register_t) (iaddr: string): lhs_type_result_t =
203204
List.fold_left (fun acc (r, i, t) ->
204205
match acc with
205-
| Some _ -> acc
206+
| LhsResolved _ | LhsConflict _ -> acc
206207
| _ ->
207208
if BCHCPURegisters.register_equal reg r && i = iaddr then t else acc)
208-
None reglhstypes
209+
LhsNoEvidence reglhstypes
209210

210-
method set_stack_offset_types (stacktypes: (int * btype_t option) list) =
211+
method set_stack_offset_types (stacktypes: (int * lhs_type_result_t) list) =
211212
stacklhstypes <- stacktypes
212213

213214
method get_stack_offset_types = stacklhstypes
214215

215-
method get_stack_offset_type (offset: int): btype_t option =
216+
method get_stack_offset_type (offset: int): lhs_type_result_t =
216217
List.fold_left (fun acc (o, t) ->
217218
match acc with
218-
| Some _ -> acc
219-
| _ -> if offset == o then t else acc) None stacklhstypes
219+
| LhsResolved _ | LhsConflict _ -> acc
220+
| _ -> if offset == o then t else acc) LhsNoEvidence stacklhstypes
220221

221222
method add_name (s:string) =
222223
let s = sanitize_function_name s in

‎CodeHawk/CHB/bchlib/bCHLibTypes.mli‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,13 @@ type function_annotation_t = {
15551555
constglobalvars: string list
15561556
}
15571557

1558+
1559+
type lhs_type_result_t =
1560+
| LhsResolved of btype_t
1561+
| LhsNoEvidence
1562+
| LhsConflict of btype_t list
1563+
1564+
15581565
class type function_data_int =
15591566
object
15601567

@@ -1613,9 +1620,10 @@ class type function_data_int =
16131620
returns the number of remaining call sites.*)
16141621
method remove_callsite: int
16151622

1616-
method set_reglhs_types: ((register_t * string * btype_t option) list) -> unit
1623+
method set_reglhs_types:
1624+
((register_t * string * lhs_type_result_t) list) -> unit
16171625

1618-
method set_stack_offset_types: ((int * btype_t option) list) -> unit
1626+
method set_stack_offset_types: ((int * lhs_type_result_t) list) -> unit
16191627

16201628
(** {1 Function annotations} *)
16211629

@@ -1643,10 +1651,10 @@ class type function_data_int =
16431651

16441652
method get_inlined_blocks: doubleword_int list
16451653
method get_path_contexts: (string * string list) list
1646-
method get_reglhs_types: (register_t * string * btype_t option) list
1647-
method get_reglhs_type: register_t -> string -> btype_t option
1648-
method get_stack_offset_types: (int * btype_t option) list
1649-
method get_stack_offset_type: int -> btype_t option
1654+
method get_reglhs_types: (register_t * string * lhs_type_result_t) list
1655+
method get_reglhs_type: register_t -> string -> lhs_type_result_t
1656+
method get_stack_offset_types: (int * lhs_type_result_t) list
1657+
method get_stack_offset_type: int -> lhs_type_result_t
16501658

16511659
(* predicates *)
16521660

@@ -3526,14 +3534,14 @@ class type type_constraint_store_int =
35263534
format-string parameter, implying the function is variadic. *)
35273535

35283536
method resolve_reglhs_type:
3529-
register_t -> string -> string -> btype_t option
3537+
register_t -> string -> string -> lhs_type_result_t
35303538

3531-
method resolve_stack_lhs_type: int -> string -> btype_t option
3539+
method resolve_stack_lhs_type: int -> string -> lhs_type_result_t
35323540

35333541
method resolve_reglhs_types:
3534-
string -> (register_t * string * btype_t option) list
3542+
string -> (register_t * string * lhs_type_result_t) list
35353543

3536-
method resolve_local_stack_lhs_types: string -> (int * btype_t option) list
3544+
method resolve_local_stack_lhs_types: string -> (int * lhs_type_result_t) list
35373545

35383546
method write_xml: xml_element_int -> unit
35393547

‎CodeHawk/CHB/bchlib/bCHTypeConstraintStore.ml‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ object (self)
765765
(result, !returnresult, varargs)
766766

767767
method resolve_reglhs_type
768-
(reg: register_t) (faddr: string) (iaddr: string): btype_t option =
768+
(reg: register_t) (faddr: string) (iaddr: string): lhs_type_result_t =
769769
let evaluation = self#evaluate_reglhs_type reg faddr iaddr in
770770
let log_evaluation () =
771771
log_diagnostics_result
@@ -825,26 +825,26 @@ object (self)
825825
if result#isEmpty then
826826
begin
827827
log_evaluation ();
828-
None
828+
LhsNoEvidence
829829
end
830830
else
831831
match result#singleton with
832-
| Some ixty -> Some (bcd#get_typ ixty)
832+
| Some ixty -> LhsResolved (bcd#get_typ ixty)
833833
| _ ->
834834
match result#toList with
835835
| [ixty1; ixty2] ->
836836
(match (bcd#get_typ ixty1), (bcd#get_typ ixty2) with
837837
| TPtr (TVoid _, _), TPtr _ ->
838-
Some (bcd#get_typ ixty2)
838+
LhsResolved (bcd#get_typ ixty2)
839839
| TPtr _, TPtr (TVoid _, _) ->
840-
Some (bcd#get_typ ixty1)
840+
LhsResolved (bcd#get_typ ixty1)
841841
| TPtr (tty1, _), TPtr (tty2, _)
842842
when is_struct_type tty1 && is_scalar tty2 ->
843-
Some (bcd#get_typ ixty1)
843+
LhsResolved (bcd#get_typ ixty1)
844844
| TPtr (tty1, _), TPtr (tty2, _)
845845
when is_struct_type tty2 && is_scalar tty1 ->
846-
Some (bcd#get_typ ixty2)
847-
| _ ->
846+
LhsResolved (bcd#get_typ ixty2)
847+
| (t1, t2) ->
848848
begin
849849
log_evaluation ();
850850
log_diagnostics_result
@@ -855,7 +855,7 @@ object (self)
855855
(List.map bcd#get_typ result#toList)
856856
(fun ty -> STR (btype_to_string ty))
857857
"[" "; " "]"))];
858-
None
858+
LhsConflict [t1; t2]
859859
end)
860860
| _ ->
861861
begin
@@ -868,13 +868,13 @@ object (self)
868868
(List.map bcd#get_typ result#toList)
869869
(fun ty -> STR (btype_to_string ty))
870870
"[" "; " "]"))];
871-
None
871+
LhsConflict (List.map bcd#get_typ result#toList)
872872
end
873873

874874
end
875875

876876
method resolve_stack_lhs_type
877-
(offset: int) (faddr: string): btype_t option =
877+
(offset: int) (faddr: string): lhs_type_result_t =
878878
let evaluation = self#evaluate_stack_lhs_type offset faddr in
879879
let log_evaluation () =
880880
log_diagnostics_result
@@ -992,10 +992,10 @@ object (self)
992992
| _ -> ()) consts) vars) evaluation;
993993
let btypes = result#fold (fun acc tix -> (bcd#get_typ tix) :: acc) [] in
994994
match join_integer_btypes btypes with
995-
| Some ty -> Some ty
995+
| Some ty -> LhsResolved ty
996996
| _ ->
997997
match first_field_struct result with
998-
| Some ty -> Some ty
998+
| Some ty -> LhsResolved ty
999999
| _ ->
10001000
begin
10011001
log_evaluation ();
@@ -1006,12 +1006,15 @@ object (self)
10061006
^ (p2s (pretty_print_list
10071007
(List.map bcd#get_typ result#toList)
10081008
(fun ty -> STR (btype_to_string ty)) "[" "; " "]"))];
1009-
None
1009+
(if result#isEmpty then
1010+
LhsNoEvidence
1011+
else
1012+
LhsConflict (List.map bcd#get_typ result#toList))
10101013
end
10111014
end
10121015

10131016
method resolve_reglhs_types (faddr: string):
1014-
(register_t * string * btype_t option) list =
1017+
(register_t * string * lhs_type_result_t) list =
10151018
let result = ref [] in
10161019
let _ =
10171020
if H.mem reglhss faddr then
@@ -1026,7 +1029,7 @@ object (self)
10261029
!result
10271030

10281031
method resolve_local_stack_lhs_types (faddr: string):
1029-
(int * btype_t option) list =
1032+
(int * lhs_type_result_t) list =
10301033
let result = ref [] in
10311034
let _ =
10321035
if H.mem stacklhss faddr then

‎CodeHawk/CHB/bchlib/bCHVersion.ml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ object (self)
9494
end
9595

9696

97+
9798
let version = new version_info_t
9899
~version:"0.6.0_20261102"
99100
~date:"2026-11-02"

‎CodeHawk/CHB/bchlibarm32/bCHARMAnalysisResults.ml‎

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ open CHXmlDocument
3131

3232
(* bchlib *)
3333
open BCHBasicTypes
34-
open BCHBCTypes
3534
open BCHByteUtilities
3635
open BCHFloc
3736
open BCHFunctionInfo
@@ -248,40 +247,78 @@ object (self)
248247

249248
method write_xml_register_types
250249
(node: xml_element_int)
251-
(regtypes: (register_t * string * btype_t option) list) =
250+
(regtypes: (register_t * string * lhs_type_result_t) list) =
252251
let regnode = xmlElement "register-lhs-types" in
253252
begin
254-
List.iter (fun (reg, iaddr, optty) ->
253+
List.iter (fun (reg, iaddr, lhs_type_result) ->
255254
let inode = xmlElement "reglhs" in
256255
begin
257256
bd#write_xml_register inode reg;
258257
inode#setAttribute "iaddr" iaddr;
259-
(match optty with
260-
| Some ty ->
258+
(match lhs_type_result with
259+
| LhsResolved ty ->
261260
begin
262261
log_result __FILE__ __LINE__
263262
["reglhs: " ^ iaddr ^ ": " ^
264263
(BCHBCTypePretty.btype_to_string ty)];
265264
bcd#write_xml_typ inode ty
266265
end
267-
| _ -> ());
266+
| LhsNoEvidence ->
267+
begin
268+
log_diagnostics_result __FILE__ __LINE__
269+
["reglhs: " ^ iaddr ^ ": no evidence"];
270+
inode#setAttribute "reason" "no-evidence"
271+
end
272+
| LhsConflict tylist ->
273+
begin
274+
log_diagnostics_result __FILE__ __LINE__
275+
["reglhs: " ^ iaddr ^ ": type conflict: "
276+
^ (String.concat
277+
", " (List.map BCHBCTypePretty.btype_to_string tylist))];
278+
inode#setAttribute "reason" "conflict";
279+
List.iter (fun cty ->
280+
let tynode = xmlElement "cty" in
281+
begin
282+
bcd#write_xml_typ tynode cty;
283+
inode#appendChildren [tynode]
284+
end) tylist
285+
end);
268286
regnode#appendChildren [inode]
269287
end) regtypes;
270288
node#appendChildren [regnode]
271289
end
272290

273291
method write_xml_stack_types
274292
(node: xml_element_int)
275-
(stacktypes: (int * btype_t option) list) =
293+
(stacktypes: (int * lhs_type_result_t) list) =
276294
let stacknode = xmlElement "stack-variable-types" in
277295
begin
278-
List.iter (fun (offset, optty) ->
296+
List.iter (fun (offset, lhs_type_result) ->
279297
let inode = xmlElement "offset" in
280298
begin
281299
inode#setIntAttribute "off" offset;
282-
(match optty with
283-
| Some ty -> bcd#write_xml_typ inode ty
284-
| _ -> ());
300+
(match lhs_type_result with
301+
| LhsResolved ty -> bcd#write_xml_typ inode ty
302+
| LhsNoEvidence ->
303+
begin
304+
log_diagnostics_result __FILE__ __LINE__
305+
["stacklhs: " ^ (string_of_int offset) ^ ": no evidence"];
306+
inode#setAttribute "reason" "no-evidence"
307+
end
308+
| LhsConflict tylist ->
309+
begin
310+
log_diagnostics_result __FILE__ __LINE__
311+
["stacklhs: " ^ (string_of_int offset) ^ ": conflict: "
312+
^ (String.concat
313+
", " (List.map BCHBCTypePretty.btype_to_string tylist))];
314+
inode#setAttribute "reason" "conflict";
315+
List.iter (fun cty ->
316+
let tynode = xmlElement "cty" in
317+
begin
318+
bcd#write_xml_typ tynode cty;
319+
inode#appendChildren [tynode]
320+
end) tylist
321+
end);
285322
stacknode#appendChildren [inode]
286323
end) stacktypes;
287324
node#appendChildren [stacknode]

‎CodeHawk/CHB/bchlibarm32/bCHARMDictionary.ml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ object (self)
147147
| ARMRegBitSequence (r, lsb, widthm1) ->
148148
(tags @ [ arm_reg_mfts#ts r ],[ lsb; widthm1 ])
149149
| ARMAbsolute addr -> (tags, [bd#index_address addr])
150-
| ARMLiteralAddress addr -> (tags, [bd#index_address addr])
150+
| ARMLiteralAddress (addr, size) -> (tags, [bd#index_address addr; size])
151151
| ARMMemMultiple (r, align, n, size) ->
152152
(tags @ [ arm_reg_mfts#ts r ],[align; n; size])
153153
| ARMOffsetAddress (r, align, offset, isadd, iswback, isindex, size) ->
@@ -493,6 +493,8 @@ object (self)
493493
(ctags c, [di dt; oi dst; oi src; oi imm])
494494
| VectorShiftRightNarrow (c, dt, dst, src, imm) ->
495495
(ctags c, [di dt; oi dst; oi src; oi imm])
496+
| VectorSquareRoot (c, dt, dst, src) ->
497+
(ctags c, [di dt; oi dst; oi src])
496498
| VStoreRegister (c, src, base, mem) ->
497499
(ctags c, [oi src; oi base; oi mem])
498500
| VectorStoreMultipleDecrementBefore (wb, c, rn, rl, mem) ->

0 commit comments

Comments
 (0)