]> git.saurik.com Git - apple/javascriptcore.git/blame - build-symbol-table-index.py
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / build-symbol-table-index.py
CommitLineData
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
26import glob
27import os
28import subprocess
29import sys
ed1e77d3 30from sets import Set
81345200
A
31from operator import itemgetter
32
33
34current_arch = sys.argv[1]
35
36print("Building Index Table")
37
38if current_arch not in ("x86_64", "arm64"):
39 sys.exit()
40
ed1e77d3 41bitcode_file_original_directory = os.path.join(os.getenv("TARGET_TEMP_DIR"), "Objects-" + os.getenv("CURRENT_VARIANT"), current_arch)
81345200 42
ed1e77d3
A
43if 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
47framework_directory = os.path.join(os.getenv("BUILT_PRODUCTS_DIR"), os.getenv("JAVASCRIPTCORE_RESOURCES_DIR"), "Runtime", current_arch)
48
ed1e77d3 49
81345200
A
50symbol_table_location = os.path.join(framework_directory, "Runtime.symtbl")
51
52symbol_table = {}
53
54symbol_table_is_out_of_date = False
55
56symbol_table_modification_time = 0
57
58if os.path.isfile(symbol_table_location):
59 symbol_table_modification_time = os.path.getmtime(symbol_table_location)
60
ed1e77d3 61file_suffix = "bc"
81345200
A
62file_suffix_length = len(file_suffix)
63
ed1e77d3
A
64tested_symbols_location = "./tested-symbols.symlst"
65include_symbol_table_location = os.path.join(os.getenv("SHARED_DERIVED_FILE_DIR"), "JavaScriptCore/InlineRuntimeSymbolTable.h")
66
67tested_symbols = Set([])
68
69if 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
75print ("Original directory: " + bitcode_file_original_directory)
76
81345200
A
77for 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
92if not symbol_table_is_out_of_date:
93 sys.exit()
94
95if 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
104symbol_list = symbol_table.items()
105
ed1e77d3
A
106print("Writing symbol table: " + symbol_table_location)
107print("Writing inline file: " + include_symbol_table_location)
81345200 108
ed1e77d3
A
109with 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 116print("Done")