@@ -687,7 +687,7 @@ object (self)
687687 (fun memoff ->
688688 TR. tbind
689689 ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
690- self#env#mk_global_variable
690+ ( self#env#mk_global_variable self#l)
691691 (get_total_constant_offset memoff))
692692 memoffset_r
693693 else if memref#is_stack_reference then
@@ -736,7 +736,7 @@ object (self)
736736 let dw = numerical_mod_to_doubleword n in
737737 if system_info#get_image_base#le dw then
738738 tprop
739- (self#env#mk_global_variable ~size n)
739+ (self#env#mk_global_variable self#l ~size n)
740740 (__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : memref:global" )
741741 else
742742 Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
@@ -791,7 +791,7 @@ object (self)
791791 (self#cia ^ " : constant: " ^ n#toString))
792792 (fun v -> v)
793793 (default () )
794- (self#env#mk_global_variable ~size n)
794+ (self#env#mk_global_variable ~size self#l n)
795795 else
796796 default () )
797797 (default () )
@@ -809,7 +809,7 @@ object (self)
809809 (default () )
810810 (TR. tbind
811811 ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
812- self#env#mk_global_variable
812+ ( self#env#mk_global_variable self#l)
813813 (get_total_constant_offset memoffset))
814814 else
815815 (TR. tfold_default
@@ -845,7 +845,7 @@ object (self)
845845 (fun memoff ->
846846 TR. tbind
847847 ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
848- (self#env#mk_global_variable ~size )
848+ (self#env#mk_global_variable ~size self#l )
849849 (get_total_constant_offset memoff))
850850 memoff_r
851851 else
@@ -946,7 +946,7 @@ object (self)
946946 (default () )
947947 (TR. tbind
948948 ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
949- self#env#mk_global_variable
949+ ( self#env#mk_global_variable self#l)
950950 (get_total_constant_offset memoffset))
951951 else
952952 TR. tfold_default
@@ -983,7 +983,7 @@ object (self)
983983 (self#cia ^ " ; constant: " ^ n#toString))
984984 (fun v -> v)
985985 (default () )
986- (self#env#mk_global_variable n)
986+ (self#env#mk_global_variable self#l n)
987987 else
988988 default () )
989989 (default () )
@@ -1002,7 +1002,7 @@ object (self)
10021002 (self#cia ^ " : constant: " ^ n#toString))
10031003 (fun v -> v)
10041004 (default () )
1005- (self#env#mk_global_variable n)
1005+ (self#env#mk_global_variable self#l n)
10061006 else
10071007 default () )
10081008 (default () )
@@ -1266,9 +1266,32 @@ object (self)
12661266 ~tag: " get_var_at_address"
12671267 __FILE__ __LINE__
12681268 [" addrvalue: " ^ (x2s addrvalue);
1269- " btype: " ^ (btype_to_string btype)] in
1269+ " btype: " ^ (btype_to_string btype);
1270+ " size: " ^ (if Option. is_some size then (string_of_int (Option. get size)) else " ?" )] in
12701271
12711272 match self#normalize_addrvalue addrvalue with
1273+ | XOp ((Xf "addressofvar" ), [XVar v ]) when self#env#is_global_variable v ->
1274+ let gvaddr_r = self#f#env#get_global_variable_address v in
1275+ TR. tbind
1276+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
1277+ (fun gvaddr ->
1278+ if memmap#has_location gvaddr then
1279+ let gloc = memmap#get_location gvaddr in
1280+ let varresult =
1281+ TR. tmap
1282+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
1283+ (fun offset -> self#f#env#mk_gloc_variable gloc offset)
1284+ (gloc#address_offset_memory_offset
1285+ ~tgtsize: size ~tgtbtype: btype self#l zero_constant_expr) in
1286+ varresult
1287+ else
1288+ Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1289+ ^ (p2s self#l#toPretty)
1290+ ^ " : "
1291+ ^ " Global location at address "
1292+ ^ gvaddr#to_hex_string
1293+ ^ " not found" ])
1294+ gvaddr_r
12721295 | XOp ((Xf "addressofvar" ), [XVar v ]) -> Ok v
12731296 | XOp (XPlus , [XOp ((Xf " addressofvar" ), [XVar v]); xoff])
12741297 when self#f#env#is_global_variable v ->
@@ -1286,7 +1309,7 @@ object (self)
12861309 (TR. tbind
12871310 (fun xoff ->
12881311 gloc#address_offset_memory_offset
1289- ~tgtsize: size ~tgtbtype: btype xoff)
1312+ ~tgtsize: size ~tgtbtype: btype self#l xoff)
12901313 cxoff_r) in
12911314 let _ =
12921315 log_diagnostics_result
@@ -1312,7 +1335,7 @@ object (self)
13121335 (TR. tmap
13131336 ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
13141337 (fun offset -> self#f#env#mk_gloc_variable gloc offset)
1315- (gloc#address_memory_offset ~tgtsize: size ~tgtbtype: btype addrvalue))
1338+ (gloc#address_memory_offset ~tgtsize: size ~tgtbtype: btype self#l addrvalue))
13161339 | _ ->
13171340 let (memref_r, memoff_r) = self#decompose_memaddr addrvalue in
13181341 TR. tmap2
@@ -2024,6 +2047,12 @@ object (self)
20242047 * if not, identify the variable most likely to be the base pointer.
20252048 *)
20262049 method decompose_address (x :xpr_t ): (memory_reference_int * memory_offset_t) =
2050+ let _ =
2051+ log_diagnostics_result
2052+ ~msg: (p2s self#l#toPretty)
2053+ ~tag: " decompose-address"
2054+ __FILE__ __LINE__
2055+ [" x: " ^ (x2s x)] in
20272056 let default () =
20282057 (self#env#mk_unknown_memory_reference (x2s x), UnknownOffset ) in
20292058 let is_external_constant v = self#env#is_function_initial_value v in
@@ -2184,7 +2213,7 @@ object (self)
21842213 (self#cia ^ " : constant: " ^ n#toString))
21852214 (fun v -> v)
21862215 (default () )
2187- (self#env#mk_global_variable n)
2216+ (self#env#mk_global_variable self#l n)
21882217 else
21892218 default () )
21902219 (default () )
@@ -2315,7 +2344,7 @@ object (self)
23152344 ~tag: " assign global variable address" __FILE__ __LINE__ e;
23162345 rhs
23172346 end )
2318- (self#f#env#mk_global_variable n)
2347+ (self#f#env#mk_global_variable self#l n)
23192348 else
23202349 rhs
23212350 | _ -> rhs in
@@ -2492,7 +2521,7 @@ object (self)
24922521 let argvar = self#env#mk_register_variable r in
24932522 self#rewrite_variable_to_external argvar
24942523 | [GlobalParameter (a, _)] when not (a#equal wordzero) ->
2495- let argvar = self#env#mk_global_variable a#to_numerical in
2524+ let argvar = self#env#mk_global_variable self#l a#to_numerical in
24962525 (match argvar with
24972526 | Error e ->
24982527 raise
@@ -2577,7 +2606,7 @@ object (self)
25772606 (self#cia ^ " : constant: " ^ num#toString))
25782607 (fun v -> Some v)
25792608 None
2580- (self#env#mk_global_variable num)
2609+ (self#env#mk_global_variable self#l num)
25812610 else
25822611 None )
25832612 None
0 commit comments