]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | #!/usr/bin/python |
2 | ||
ed1e77d3 A |
3 | # Copyright (C) 2014 Apple Inc. All rights reserved. |
4 | # | |
5 | # Redistribution and use in source and binary forms, with or without | |
6 | # modification, are permitted provided that the following conditions | |
7 | # are met: | |
8 | # 1. Redistributions of source code must retain the above copyright | |
9 | # notice, this list of conditions and the following disclaimer. | |
10 | # 2. Redistributions in binary form must reproduce the above copyright | |
11 | # notice, this list of conditions and the following disclaimer in the | |
12 | # documentation and/or other materials provided with the distribution. | |
13 | # | |
14 | # THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
15 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
17 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | |
18 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
19 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
20 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
21 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
22 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
24 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 | ||
81345200 A |
26 | import glob |
27 | import os | |
28 | import subprocess | |
29 | import sys | |
ed1e77d3 | 30 | from sets import Set |
81345200 A |
31 | from operator import itemgetter |
32 | ||
33 | ||
34 | current_arch = sys.argv[1] | |
35 | ||
36 | print("Building Index Table") | |
37 | ||
38 | if current_arch not in ("x86_64", "arm64"): | |
39 | sys.exit() | |
40 | ||
ed1e77d3 | 41 | bitcode_file_original_directory = os.path.join(os.getenv("TARGET_TEMP_DIR"), "Objects-" + os.getenv("CURRENT_VARIANT"), current_arch) |
81345200 | 42 | |
ed1e77d3 A |
43 | if not os.path.isdir(bitcode_file_original_directory): |
44 | print("Failed to build index table at " + bitcode_file_original_directory) | |
81345200 A |
45 | sys.exit() |
46 | ||
47 | framework_directory = os.path.join(os.getenv("BUILT_PRODUCTS_DIR"), os.getenv("JAVASCRIPTCORE_RESOURCES_DIR"), "Runtime", current_arch) | |
48 | ||
ed1e77d3 | 49 | |
81345200 A |
50 | symbol_table_location = os.path.join(framework_directory, "Runtime.symtbl") |
51 | ||
52 | symbol_table = {} | |
53 | ||
54 | symbol_table_is_out_of_date = False | |
55 | ||
56 | symbol_table_modification_time = 0 | |
57 | ||
58 | if os.path.isfile(symbol_table_location): | |
59 | symbol_table_modification_time = os.path.getmtime(symbol_table_location) | |
60 | ||
ed1e77d3 | 61 | file_suffix = "bc" |
81345200 A |
62 | file_suffix_length = len(file_suffix) |
63 | ||
ed1e77d3 A |
64 | tested_symbols_location = "./tested-symbols.symlst" |
65 | include_symbol_table_location = os.path.join(os.getenv("SHARED_DERIVED_FILE_DIR"), "JavaScriptCore/InlineRuntimeSymbolTable.h") | |
66 | ||
67 | tested_symbols = Set([]) | |
68 | ||
69 | if os.path.isfile(tested_symbols_location): | |
70 | with open(tested_symbols_location, 'r') as file: | |
71 | print("Loading tested symbols") | |
72 | for line in file: | |
73 | tested_symbols.add(line[:-1]) | |
74 | ||
75 | print ("Original directory: " + bitcode_file_original_directory) | |
76 | ||
81345200 A |
77 | for bitcode_file in glob.iglob(os.path.join(framework_directory, "*." + file_suffix)): |
78 | bitcode_basename = os.path.basename(bitcode_file) | |
ed1e77d3 A |
79 | bitcode_file_original = os.path.join(bitcode_file_original_directory, bitcode_basename[:-file_suffix_length] + "o") |
80 | if os.path.getmtime(bitcode_file_original) < symbol_table_modification_time: | |
81345200 A |
81 | continue |
82 | ||
83 | symbol_table_is_out_of_date = True | |
84 | ||
85 | print("Appending symbols from " + bitcode_basename) | |
ed1e77d3 | 86 | lines = subprocess.check_output(["nm", "-U", "-j", bitcode_file]).splitlines() |
81345200 A |
87 | |
88 | for symbol in lines: | |
ed1e77d3 A |
89 | if symbol[:2] == "__" and symbol[-3:] != ".eh" and symbol in tested_symbols: |
90 | symbol_table[symbol[1:]] = bitcode_basename | |
81345200 A |
91 | |
92 | if not symbol_table_is_out_of_date: | |
93 | sys.exit() | |
94 | ||
95 | if os.path.isfile(symbol_table_location): | |
96 | with open(symbol_table_location, 'r') as file: | |
97 | print("Loading symbol table") | |
98 | for line in file: | |
99 | symbol, _, location = line[:-1].partition(" ") | |
100 | # don't overwrite new symbols with old locations | |
101 | if not symbol in symbol_table: | |
102 | symbol_table[symbol] = location | |
103 | ||
104 | symbol_list = symbol_table.items() | |
105 | ||
ed1e77d3 A |
106 | print("Writing symbol table: " + symbol_table_location) |
107 | print("Writing inline file: " + include_symbol_table_location) | |
81345200 | 108 | |
ed1e77d3 A |
109 | with open(symbol_table_location, "w") as symbol_file: |
110 | with open(include_symbol_table_location, "w") as include_file: | |
111 | include_file.write("#define FOR_EACH_LIBRARY_SYMBOL(macro)") | |
112 | for symbol, location in symbol_list: | |
113 | symbol_file.write("{} {}\n".format(symbol, location)) | |
114 | include_file.write(" \\\nmacro(\"{}\", \"{}\")".format(symbol, location)) | |
115 | include_file.write("\n") | |
81345200 | 116 | print("Done") |