8 from operator import itemgetter
11 current_arch = sys.argv[1]
13 print("Building Index Table")
15 if current_arch not in ("x86_64", "arm64"):
18 binary_file_directory = os.path.join(os.getenv("OBJECT_FILE_DIR_" + os.getenv("CURRENT_VARIANT")), current_arch)
20 if not os.path.isdir(binary_file_directory):
21 print("Failed to build index table at " + binary_file_directory)
24 framework_directory = os.path.join(os.getenv("BUILT_PRODUCTS_DIR"), os.getenv("JAVASCRIPTCORE_RESOURCES_DIR"), "Runtime", current_arch)
27 symbol_table_location = os.path.join(framework_directory, "Runtime.symtbl")
31 symbol_table_is_out_of_date = False
33 symbol_table_modification_time = 0
35 if os.path.isfile(symbol_table_location):
36 symbol_table_modification_time = os.path.getmtime(symbol_table_location)
39 file_suffix_length = len(file_suffix)
41 tested_symbols_location = "./tested-symbols.symlst"
42 include_symbol_table_location = os.path.join(os.getenv("SHARED_DERIVED_FILE_DIR"), "JavaScriptCore/InlineRuntimeSymbolTable.h")
44 tested_symbols = Set([])
46 if os.path.isfile(tested_symbols_location):
47 with open(tested_symbols_location, 'r') as file:
48 print("Loading tested symbols")
50 tested_symbols.add(line[:-1])
52 for bitcode_file in glob.iglob(os.path.join(framework_directory, "*." + file_suffix)):
53 bitcode_basename = os.path.basename(bitcode_file)
54 binary_file = os.path.join(binary_file_directory, bitcode_basename[:-file_suffix_length] + "o")
55 if os.path.getmtime(binary_file) < symbol_table_modification_time:
58 symbol_table_is_out_of_date = True
60 print("Appending symbols from " + bitcode_basename)
61 lines = subprocess.check_output(["nm", "-U", "-j", binary_file]).splitlines()
64 if symbol[:2] == "__" and symbol[-3:] != ".eh" and symbol in tested_symbols:
65 symbol_table[symbol[1:]] = bitcode_basename
67 if not symbol_table_is_out_of_date:
70 if os.path.isfile(symbol_table_location):
71 with open(symbol_table_location, 'r') as file:
72 print("Loading symbol table")
74 symbol, _, location = line[:-1].partition(" ")
75 # don't overwrite new symbols with old locations
76 if not symbol in symbol_table:
77 symbol_table[symbol] = location
79 symbol_list = symbol_table.items()
81 print("Writing symbol table")
83 with open(symbol_table_location, "w") as symbol_file:
84 with open(include_symbol_table_location, "w") as include_file:
85 include_file.write("#define FOR_EACH_LIBRARY_SYMBOL(macro)")
86 for symbol, location in symbol_list:
87 symbol_file.write("{} {}\n".format(symbol, location))
88 include_file.write(" \\\nmacro(\"{}\", \"{}\")".format(symbol, location))
89 include_file.write("\n")