Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CodeHawk/CHB/bchcmdline/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ defs: make_dirs libsum appsum constsum classsum structdef
chx86_analyze: $(OBJECTS) $(CMIS) $(CHLIB)/chlib.cmxa $(CIL)/goblintCil.cmxa $(ZIPLIB)/zip.cmxa $(CHUTIL)/chutil.cmxa $(BCHCIL)/bchcil.cmxa $(BCHLIB)/bchlib.cmxa $(PELIB)/bchlibpe.cmxa $(X86LIB)/bchlibx86.cmxa $(MIPSLIB)/bchlibmips32.cmxa $(ARMLIB)/bchlibarm32.cmxa $(PWRLIB)/bchlibpower32.cmxa $(ANALYZ)/bchanalyze.cmxa cmi/bCHXBinaryAnalyzer.cmi cmx/bCHXBinaryAnalyzer.cmx
$(CAMLLINK) -o $@ cmx/bCHXBinaryAnalyzer.cmx

chx86_inspect_summaries: $(OBJECTS) $(CMIS) $(CHLIB)/chlib.cmxa $(ZIPLIB)/zip.cmxa $(CHUTIL)/chutil.cmxa $(BCHLIB)/bchlib.cmxa cmi/bCHXInspectSummaries.cmi cmx/bCHXInspectSummaries.cmx
$(CAMLLINK) -o $@ $(OBJECTS) cmx/bCHXInspectSummaries.cmx
chx86_inspect_summaries: $(OBJECTS) $(CMIS) $(CHLIB)/chlib.cmxa $(CIL)/goblintCil.cmxa $(ZIPLIB)/zip.cmxa $(CHUTIL)/chutil.cmxa $(BCHCIL)/bchcil.cmxa $(BCHLIB)/bchlib.cmxa cmi/bCHXInspectSummaries.cmi cmx/bCHXInspectSummaries.cmx
$(CAMLLINK) -o $@ cmx/bCHXInspectSummaries.cmx

chx86_save_exports: $(OBJECTS) $(CMIS) $(CHLIB)/chlib.cmxa $(ZIPLIB)/zip.cmxa $(CHUTIL)/chutil.cmxa $(BCHLIB)/bchlib.cmxa $(PELIB)/bchlibpe.cmxa cmx/bCHXSaveExports.cmx
$(CAMLLINK) -o $@ $(OBJECTS) cmx/bCHXSaveExports.cmx
Expand Down
1 change: 1 addition & 0 deletions CodeHawk/CHB/bchcmdline/bCHXBinaryAnalyzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ let main () =
let _ = disassembly_summary#set_disassembly_metrics
(get_arm_disassembly_metrics ()) in
let _ = pr_debug [NL; NL; disassembly_summary#toPretty; NL] in
let _ = save_bc_files () in
(*
let _ =
pr_debug [
Expand Down
4 changes: 2 additions & 2 deletions CodeHawk/CHB/bchlib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ OCAMLDEP := ocamldep

MLIS := \
bCHBCTypes \
bCHBCAttributes \
bCHBCSumTypeSerializer \
bCHBCTypeTransformer \
bCHLibTypes \
Expand All @@ -41,7 +42,6 @@ MLIS := \
bCHBCFunDeclarations \
bCHBCWriteXml \
bCHBCFiles \
bCHBCAttributes \
bCHInterfaceDictionary \
bCHVarDictionary \
bCHInvDictionary \
Expand Down Expand Up @@ -131,10 +131,10 @@ SOURCES := \
bCHBCDictionary \
bCHBCFunDeclarations \
bCHBCWriteXml \
bCHBCAttributes \
bCHBCFiles \
bCHBCTypeUtil \
bCHBCTypeXml \
bCHBCAttributes \
bCHSumTypeSerializer \
bCHDictionary \
bCHInterfaceDictionary \
Expand Down
41 changes: 35 additions & 6 deletions CodeHawk/CHB/bchlib/bCHBCAttributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
------------------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2024 Aarno Labs LLC
Copyright (c) 2024-2025 Aarno Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -50,6 +50,40 @@ let gcc_attributes_to_precondition_attributes
| _ -> acc) [] attrs


let gcc_attributes_to_srcmapinfo
(attrs: b_attributes_t): srcmapinfo_t option =
let optsrcloc =
List.fold_left (fun acc a ->
match acc with
| Some _ -> acc
| _ ->
match a with
| Attr ("chkc_srcloc", params) ->
(match params with
| [AStr filename; AInt linenumber] ->
Some {srcloc_filename=filename;
srcloc_linenumber=linenumber;
srcloc_notes=[]}
| _ -> None)
| _ -> None) None attrs in
match optsrcloc with
| Some srcloc ->
let binloc =
List.fold_left (fun acc a ->
match acc with
| Some _ -> acc
| _ ->
match a with
| Attr ("chkx_binloc", params) ->
(match params with
| [AStr address] -> Some address
| _ -> None)
| _ -> None) None attrs in
Some {srcmap_srcloc = srcloc; srcmap_binloc = binloc}
| _ -> None



let precondition_attributes_t_to_gcc_attributes
(preattrs: precondition_attribute_t list): b_attributes_t =
let get_params (refindex: int) (optsizeindex: int option) =
Expand All @@ -67,8 +101,3 @@ let precondition_attributes_t_to_gcc_attributes
| APCReadWrite (refindex, optsizeindex) ->
(get_access "read_write" (get_params refindex optsizeindex)) :: acc
| _ -> acc) [] preattrs





3 changes: 3 additions & 0 deletions CodeHawk/CHB/bchlib/bCHBCAttributes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ open BCHBCTypes
val gcc_attributes_to_precondition_attributes:
b_attributes_t -> precondition_attribute_t list

val gcc_attributes_to_srcmapinfo:
b_attributes_t -> srcmapinfo_t option


val precondition_attributes_t_to_gcc_attributes:
precondition_attribute_t list -> b_attributes_t
70 changes: 59 additions & 11 deletions CodeHawk/CHB/bchlib/bCHBCFiles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author: Henny Sipma
------------------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2021-2024 Aarno Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -12,10 +12,10 @@
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -60,6 +60,9 @@ object (self)
val gvardecls = H.create 3 (* bvname -> (varinfo.ix, loc.ix) *)
val gvars = H.create 3 (* idem *)
val gfuns = H.create 3 (* bsvar.bvname -> (fundec, loc.ix) *)
val vinfo_srcmap = H.create 3
(* varinfo.ix -> (ix(filename), linenr, binloc, [ix(notes)]) *)

val mutable varinfo_vid_counter = 10000

method private get_varinfo_id =
Expand All @@ -70,6 +73,24 @@ object (self)

method add_bcfile (f: bcfile_t) =
let i = bcd#index_location in

let add_srcmapinfo (vinfo: bvarinfo_t) =
match BCHBCAttributes.gcc_attributes_to_srcmapinfo vinfo.bvattr with
| Some srcmap ->
let vix = bcd#index_varinfo vinfo in
if H.mem vinfo_srcmap vix then
()
else
let srcloc = srcmap.srcmap_srcloc in
let ixfilename = bcd#index_string srcloc.srcloc_filename in
let linenumber = srcloc.srcloc_linenumber in
let ixnotes = List.map bcd#index_string srcloc.srcloc_notes in
let binloc =
match srcmap.srcmap_binloc with
| Some s -> s
| _ -> "none" in
H.add vinfo_srcmap vix (ixfilename, linenumber, binloc, ixnotes)
| _ -> () in
begin
List.iter (fun g ->
match g with
Expand Down Expand Up @@ -100,8 +121,10 @@ object (self)
()
else
let _ = chlog#add "bcfiles:add gvardecl" (STR vinfo.bvname) in
let _ = add_srcmapinfo vinfo in
H.replace gvardecls vinfo.bvname (bcd#index_varinfo vinfo, i loc)
| GVar (vinfo, iinfo, loc) ->
let _ = add_srcmapinfo vinfo in
let _ = chlog#add "bcfiles:add gvar" (STR vinfo.bvname) in
H.replace gvars
vinfo.bvname
Expand All @@ -112,7 +135,7 @@ object (self)
i loc)
| GFun (fundec, loc) ->
let _ = chlog#add "bcfiles:add gfun" (STR fundec.bsvar.bvname) in
H.replace gfuns fundec.bsvar.bvname (fundec, bcd#index_location loc);
H.replace gfuns fundec.bsvar.bvname (fundec, bcd#index_location loc);
| _ -> ()) f.bglobals;
chlog#add
"bcfiles:add_bcfile"
Expand Down Expand Up @@ -411,7 +434,7 @@ object (self)
result := (v2s (bcd#get_varinfo ix)) :: !result) gvardecls;
!result
end

method has_gfun (name: string) = H.mem gfuns name

method get_gfun (name: string) =
Expand Down Expand Up @@ -495,7 +518,7 @@ object (self)
match cn#getIntListAttribute "ixs" with
| [cix; locix] -> H.add gcomptags (name, ckey) (cix, locix)
| _ -> ()) (getcc "cid")

method private write_xml_genums (node: xml_element_int) =
let genums = H.fold (fun k v a -> (k, v)::a) genumtags [] in
node#appendChildren
Expand Down Expand Up @@ -533,7 +556,7 @@ object (self)
match en#getIntListAttribute "ixs" with
| [eix; locix] -> H.add genumtagdecls name (eix, locix)
| _ -> ()) (getcc "eid")

method private write_xml_gvars (node: xml_element_int) =
let gvarinfos = H.fold (fun k v a -> (k, v)::a) gvars [] in
node#appendChildren
Expand Down Expand Up @@ -591,7 +614,29 @@ object (self)
let locix = gn#getIntAttribute "locix" in
let fundec = read_xml_function_definition gn in
H.add gfuns name (fundec, locix)) (getcc "gfun")


method private write_xml_srcmap (node: xml_element_int) =
let srcmapentries = H.fold (fun k v a -> (k, v)::a) vinfo_srcmap [] in
node#appendChildren
(List.map (fun (vix, (ixfn, lnr, binloc, _ixnotes)) ->
let snode = xmlElement "srcloc" in
begin
snode#setIntAttribute "vix" vix;
snode#setIntAttribute "ixfn" ixfn;
snode#setIntAttribute "lnr" lnr;
snode#setAttribute "binloc" binloc;
snode
end) srcmapentries)

method private read_xml_srcmap (node: xml_element_int) =
let getcc = node#getTaggedChildren in
List.iter (fun gs ->
let vix = gs#getIntAttribute "vix" in
let ixfn = gs#getIntAttribute "ixfn" in
let lnr = gs#getIntAttribute "lnr" in
let binloc = gs#getAttribute "binloc" in
H.add vinfo_srcmap vix (ixfn, lnr, binloc, [])) (getcc "srcloc")

method write_xml (node: xml_element_int) =
let tnode = xmlElement "typeinfos" in
let cnode = xmlElement "compinfos" in
Expand All @@ -601,6 +646,7 @@ object (self)
let vnode = xmlElement "varinfos" in
let vdnode = xmlElement "varinfodecls" in
let gfunnode = xmlElement "gfuns" in
let srcmapnode = xmlElement "srcmap" in
begin
self#write_xml_gtypes tnode;
self#write_xml_gcomps cnode;
Expand All @@ -610,8 +656,9 @@ object (self)
self#write_xml_gvars vnode;
self#write_xml_gvardecls vdnode;
self#write_xml_gfuns gfunnode;
self#write_xml_srcmap srcmapnode;
node#appendChildren[
tnode; cnode; cdnode; enode; ednode; vnode; vdnode; gfunnode]
tnode; cnode; cdnode; enode; ednode; vnode; vdnode; gfunnode; srcmapnode]
end

method read_xml (node: xml_element_int) =
Expand All @@ -624,9 +671,10 @@ object (self)
self#read_xml_genumdecls (getc "enuminfodecls");
self#read_xml_gvars (getc "varinfos");
self#read_xml_gvardecls (getc "varinfodecls");
self#read_xml_gfuns (getc "gfuns")
self#read_xml_gfuns (getc "gfuns");
self#read_xml_srcmap (getc "srcmap")
end

end


Expand Down
13 changes: 13 additions & 0 deletions CodeHawk/CHB/bchlib/bCHBCTypes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,19 @@ type bcfile_t = {
}


type srclocinfo_t = {
srcloc_filename: string;
srcloc_linenumber: int;
srcloc_notes: string list
}


type srcmapinfo_t = {
srcmap_srcloc: srclocinfo_t;
srcmap_binloc: string option
}


class type bcdictionary_int =
object

Expand Down
4 changes: 2 additions & 2 deletions CodeHawk/CHB/bchlib/bCHVersion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ end


let version = new version_info_t
~version:"0.6.0_20250502"
~date:"2025-05-02"
~version:"0.6.0_20250521"
~date:"2025-05-21"
~licensee: None
~maxfilesize: None
()
15 changes: 15 additions & 0 deletions CodeHawk/CHB/bchlibarm32/bCHARMOperand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,21 @@ object (self:'a)
let xoffset = int_constant_expr indexoffset in
(match srt with
| ARMImmSRT (_, 0)-> Ok (XOp (XPlus, [XVar indexvar; xoffset]))
| ARMImmSRT (SRType_LSL, 1) ->
let shifted = XOp (XMult, [XVar indexvar; int_constant_expr 2]) in
Ok (XOp (XPlus, [shifted; xoffset]))
| ARMImmSRT (SRType_LSL, 2) ->
let shifted = XOp (XMult, [XVar indexvar; int_constant_expr 4]) in
Ok (XOp (XPlus, [shifted; xoffset]))
| ARMImmSRT (SRType_LSL, 3) ->
let shifted = XOp (XMult, [XVar indexvar; int_constant_expr 8]) in
Ok (XOp (XPlus, [shifted; xoffset]))
| ARMImmSRT (SRType_LSL, 4) ->
let shifted = XOp (XMult, [XVar indexvar; int_constant_expr 16]) in
Ok (XOp (XPlus, [shifted; xoffset]))
| ARMImmSRT (SRType_LSL, 5) ->
let shifted = XOp (XMult, [XVar indexvar; int_constant_expr 32]) in
Ok (XOp (XPlus, [shifted; xoffset]))
| ARMImmSRT (SRType_ASR, 1) ->
let shifted = XOp (XDiv, [XVar indexvar; int_constant_expr 2]) in
Ok (XOp (XPlus, [shifted; xoffset]))
Expand All @@ -369,6 +381,9 @@ object (self:'a)
| ARMImmSRT (SRType_ASR, 3) ->
let shifted = XOp (XDiv, [XVar indexvar; int_constant_expr 8]) in
Ok (XOp (XPlus, [shifted; xoffset]))
| ARMImmSRT (SRType_ASR, 4) ->
let shifted = XOp (XDiv, [XVar indexvar; int_constant_expr 16]) in
Ok (XOp (XPlus, [shifted; xoffset]))
| ARMRegSRT (SRType_LSL, srtreg) ->
let shiftvar = env#mk_arm_register_variable srtreg in
let shifted = XOp (XLsl, [XVar indexvar; XVar shiftvar]) in
Expand Down
16 changes: 8 additions & 8 deletions CodeHawk/CHB/bchlibarm32/bCHFnARMDictionary.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2377,16 +2377,16 @@ object (self)
(tags, args)

| SignedBitFieldExtract (c, rd, rn) ->
let lhs_r = rd#to_variable floc in
let rhs_r = rn#to_expr floc in
let rrhs_r = TR.tmap rewrite_expr rhs_r in
let rdefs = [get_rdef_r rhs_r] in
let uses = [get_def_use_r lhs_r] in
let useshigh = [get_def_use_high_r lhs_r] in
let vrd_r = rd#to_variable floc in
let xrn_r = rn#to_expr floc in
let xxrn_r = TR.tmap rewrite_expr xrn_r in
let rdefs = [get_rdef_r xrn_r] in
let uses = [get_def_use_r vrd_r] in
let useshigh = [get_def_use_high_r vrd_r] in
let (tagstring, args) =
mk_instrx_data_r
~vars_r:[lhs_r]
~xprs_r:[rhs_r; rrhs_r]
~vars_r:[vrd_r]
~xprs_r:[xrn_r; xxrn_r]
~rdefs
~uses
~useshigh
Expand Down
2 changes: 1 addition & 1 deletion CodeHawk/CHC/cchlib/cCHCAttributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
------------------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2024 Aarno Labs LLC
Copyright (c) 2024-2025 Aarno Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading
Loading