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