7 from operator
import itemgetter
10 current_arch
= sys
.argv
[1]
12 print("Building Index Table")
14 if current_arch
not in ("x86_64", "arm64"):
17 binary_file_directory
= os
.path
.join(os
.getenv("OBJECT_FILE_DIR_" + os
.getenv("CURRENT_VARIANT")), current_arch
)
19 if not os
.path
.isdir(binary_file_directory
):
20 print("Failed to build index table at " + binary_file_directory
)
23 framework_directory
= os
.path
.join(os
.getenv("BUILT_PRODUCTS_DIR"), os
.getenv("JAVASCRIPTCORE_RESOURCES_DIR"), "Runtime", current_arch
)
25 symbol_table_location
= os
.path
.join(framework_directory
, "Runtime.symtbl")
29 symbol_table_is_out_of_date
= False
31 symbol_table_modification_time
= 0
33 if os
.path
.isfile(symbol_table_location
):
34 symbol_table_modification_time
= os
.path
.getmtime(symbol_table_location
)
37 file_suffix_length
= len(file_suffix
)
39 for bitcode_file
in glob
.iglob(os
.path
.join(framework_directory
, "*." + file_suffix
)):
40 bitcode_basename
= os
.path
.basename(bitcode_file
)
41 binary_file
= os
.path
.join(binary_file_directory
, bitcode_basename
[:-file_suffix_length
] + "o")
42 if os
.path
.getmtime(binary_file
) < symbol_table_modification_time
:
45 symbol_table_is_out_of_date
= True
47 print("Appending symbols from " + bitcode_basename
)
48 lines
= subprocess
.check_output(["nm", "-U", "-j", binary_file
]).splitlines()
51 if symbol
[:2] == "__" and symbol
[-3:] != ".eh":
52 symbol_table
[symbol
] = bitcode_basename
[1:]
54 if not symbol_table_is_out_of_date
:
57 if os
.path
.isfile(symbol_table_location
):
58 with open(symbol_table_location
, 'r') as file:
59 print("Loading symbol table")
61 symbol
, _
, location
= line
[:-1].partition(" ")
62 # don't overwrite new symbols with old locations
63 if not symbol
in symbol_table
:
64 symbol_table
[symbol
] = location
66 symbol_list
= symbol_table
.items()
68 print("Writing symbol table")
70 with open(symbol_table_location
, "w") as file:
71 for symbol
, location
in symbol_list
:
72 file.write("{} {}\n".format(symbol
, location
))