3 # Copyright (C) 2014 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
31 from operator
import itemgetter
34 current_arch
= sys
.argv
[1]
36 print("Building Index Table")
38 if current_arch
not in ("x86_64", "arm64"):
41 bitcode_file_original_directory
= os
.path
.join(os
.getenv("TARGET_TEMP_DIR"), "Objects-" + os
.getenv("CURRENT_VARIANT"), current_arch
)
43 if not os
.path
.isdir(bitcode_file_original_directory
):
44 print("Failed to build index table at " + bitcode_file_original_directory
)
47 framework_directory
= os
.path
.join(os
.getenv("BUILT_PRODUCTS_DIR"), os
.getenv("JAVASCRIPTCORE_RESOURCES_DIR"), "Runtime", current_arch
)
50 symbol_table_location
= os
.path
.join(framework_directory
, "Runtime.symtbl")
54 symbol_table_is_out_of_date
= False
56 symbol_table_modification_time
= 0
58 if os
.path
.isfile(symbol_table_location
):
59 symbol_table_modification_time
= os
.path
.getmtime(symbol_table_location
)
62 file_suffix_length
= len(file_suffix
)
64 tested_symbols_location
= "./tested-symbols.symlst"
65 include_symbol_table_location
= os
.path
.join(os
.getenv("SHARED_DERIVED_FILE_DIR"), "JavaScriptCore/InlineRuntimeSymbolTable.h")
67 tested_symbols
= Set([])
69 if os
.path
.isfile(tested_symbols_location
):
70 with open(tested_symbols_location
, 'r') as file:
71 print("Loading tested symbols")
73 tested_symbols
.add(line
[:-1])
75 print ("Original directory: " + bitcode_file_original_directory
)
77 for bitcode_file
in glob
.iglob(os
.path
.join(framework_directory
, "*." + file_suffix
)):
78 bitcode_basename
= os
.path
.basename(bitcode_file
)
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
:
83 symbol_table_is_out_of_date
= True
85 print("Appending symbols from " + bitcode_basename
)
86 lines
= subprocess
.check_output(["nm", "-U", "-j", bitcode_file
]).splitlines()
89 if symbol
[:2] == "__" and symbol
[-3:] != ".eh" and symbol
in tested_symbols
:
90 symbol_table
[symbol
[1:]] = bitcode_basename
92 if not symbol_table_is_out_of_date
:
95 if os
.path
.isfile(symbol_table_location
):
96 with open(symbol_table_location
, 'r') as file:
97 print("Loading symbol table")
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
104 symbol_list
= symbol_table
.items()
106 print("Writing symbol table: " + symbol_table_location
)
107 print("Writing inline file: " + include_symbol_table_location
)
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")