]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | #!/usr/bin/python |
2 | ||
3 | import glob | |
4 | import os | |
5 | import subprocess | |
6 | import sys | |
7 | from operator import itemgetter | |
8 | ||
9 | ||
10 | current_arch = sys.argv[1] | |
11 | ||
12 | print("Building Index Table") | |
13 | ||
14 | if current_arch not in ("x86_64", "arm64"): | |
15 | sys.exit() | |
16 | ||
17 | binary_file_directory = os.path.join(os.getenv("OBJECT_FILE_DIR_" + os.getenv("CURRENT_VARIANT")), current_arch) | |
18 | ||
19 | if not os.path.isdir(binary_file_directory): | |
20 | print("Failed to build index table at " + binary_file_directory) | |
21 | sys.exit() | |
22 | ||
23 | framework_directory = os.path.join(os.getenv("BUILT_PRODUCTS_DIR"), os.getenv("JAVASCRIPTCORE_RESOURCES_DIR"), "Runtime", current_arch) | |
24 | ||
25 | symbol_table_location = os.path.join(framework_directory, "Runtime.symtbl") | |
26 | ||
27 | symbol_table = {} | |
28 | ||
29 | symbol_table_is_out_of_date = False | |
30 | ||
31 | symbol_table_modification_time = 0 | |
32 | ||
33 | if os.path.isfile(symbol_table_location): | |
34 | symbol_table_modification_time = os.path.getmtime(symbol_table_location) | |
35 | ||
36 | file_suffix = "bc.gz" | |
37 | file_suffix_length = len(file_suffix) | |
38 | ||
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: | |
43 | continue | |
44 | ||
45 | symbol_table_is_out_of_date = True | |
46 | ||
47 | print("Appending symbols from " + bitcode_basename) | |
48 | lines = subprocess.check_output(["nm", "-U", "-j", binary_file]).splitlines() | |
49 | ||
50 | for symbol in lines: | |
51 | if symbol[:2] == "__" and symbol[-3:] != ".eh": | |
52 | symbol_table[symbol] = bitcode_basename[1:] | |
53 | ||
54 | if not symbol_table_is_out_of_date: | |
55 | sys.exit() | |
56 | ||
57 | if os.path.isfile(symbol_table_location): | |
58 | with open(symbol_table_location, 'r') as file: | |
59 | print("Loading symbol table") | |
60 | for line in file: | |
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 | |
65 | ||
66 | symbol_list = symbol_table.items() | |
67 | ||
68 | print("Writing symbol table") | |
69 | ||
70 | with open(symbol_table_location, "w") as file: | |
71 | for symbol, location in symbol_list: | |
72 | file.write("{} {}\n".format(symbol, location)) | |
73 | ||
74 | print("Done") |