Skip to content

Commit 12f6be0

Browse files
committed
CHB:ELF: import symbol names for global variables
1 parent 9e94c3a commit 12f6be0

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CodeHawk/CHB/bchlibelf/bCHELFHeader.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ object(self)
977977
symboltable#set_symbol_names stringtable ;
978978
symboltable#set_function_entry_points ;
979979
symboltable#set_function_names;
980+
symboltable#set_data_object_names;
980981
(if system_settings#is_arm then symboltable#set_mapping_symbols);
981982
end
982983
else
@@ -989,7 +990,8 @@ object(self)
989990
begin
990991
symboltable#set_symbol_names stringtable ;
991992
symboltable#set_function_entry_points ;
992-
symboltable#set_function_names
993+
symboltable#set_function_names;
994+
symboltable#set_data_object_names
993995
end
994996
else
995997
chlog#add "no symbols found" (STR "No symbols found")

CodeHawk/CHB/bchlibelf/bCHELFSymbolTable.ml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Copyright (c) 2005-2020 Kestrel Technology LLC
88
Copyright (c) 2020 Henny Sipma
9-
Copyright (c) 2021-2023 Aarno Labs LLC
9+
Copyright (c) 2021-2024 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
@@ -143,6 +143,8 @@ object (self)
143143

144144
method is_function = self#get_st_type = 2
145145

146+
method is_data_object = self#get_st_type = 1
147+
146148
method has_address_value = not (st_value#equal wordzero)
147149

148150
method write_xml (node:xml_element_int) =
@@ -240,6 +242,21 @@ object (self)
240242
v in
241243
(functions_data#add_function addr)#add_name e#get_name) entries
242244

245+
method set_data_object_names =
246+
H.iter (fun _ e ->
247+
if e#is_data_object && e#has_address_value && e#has_name then
248+
let cdef = {
249+
xconst_name = e#get_name;
250+
xconst_value = e#get_st_value;
251+
xconst_type = BCHBCTypeUtil.t_unknown;
252+
xconst_desc = "symbol-table";
253+
xconst_is_addr = true;
254+
} in
255+
BCHConstantDefinitions.add_address cdef
256+
else
257+
()
258+
) entries
259+
243260
method set_mapping_symbols =
244261
let symbols = H.create 13 in
245262
let _ =
@@ -311,6 +328,9 @@ object (self)
311328
(BCH_failure
312329
(LBLOCK [STR "Symbol with index "; INT index; STR " not found"]))
313330

331+
method has_symbol (index: int) =
332+
H.mem entries index
333+
314334
method write_xml_symbols (node:xml_element_int) =
315335
let table = mk_num_record_table "symbol-table" in
316336
begin

CodeHawk/CHB/bchlibelf/bCHELFTypes.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class type elf_symbol_table_entry_int =
259259
method has_address_value: bool
260260
method has_name: bool
261261
method is_function: bool
262+
method is_data_object: bool
262263
method to_rep_record: string list * int list
263264
method write_xml: xml_element_int -> unit
264265
end
@@ -270,12 +271,14 @@ class type elf_symbol_table_int =
270271
method set_symbol_names: elf_string_table_int -> unit
271272
method set_function_entry_points: unit
272273
method set_function_names: unit
274+
method set_data_object_names: unit
273275
method set_mapping_symbols: unit
274276
method get_xstring: string
275277
method get_size: int
276278
method get_xsubstring: doubleword_int -> int -> string
277279
method get_vaddr: doubleword_int
278280
method get_symbol: int -> elf_symbol_table_entry_int
281+
method has_symbol: int -> bool
279282
method get_string_reference: doubleword_int -> string option
280283
method includes_VA: doubleword_int -> bool
281284
method write_xml: xml_element_int -> unit

0 commit comments

Comments
 (0)