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.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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.
35 from operator
import itemgetter
37 print("Building Index Table")
39 RUNTIME_INSTALL_DIR
= sys
.argv
[1]
41 DERIVED_SOURCES_DIR
= sys
.argv
[3]
42 LLVM_BINS
= sys
.argv
[4]
45 os
.mkdir(os
.path
.join(RUNTIME_INSTALL_DIR
, "runtime"))
49 symbol_table_location
= os
.path
.join(RUNTIME_INSTALL_DIR
, "runtime", "Runtime.symtbl")
53 symbol_table_is_out_of_date
= False
55 symbol_table_modification_time
= 0
57 if os
.path
.isfile(symbol_table_location
):
58 symbol_table_modification_time
= os
.path
.getmtime(symbol_table_location
)
61 file_suffix_length
= len(file_suffix
)
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")
66 tested_symbols
= Set([])
68 if os
.path
.isfile(tested_symbols_location
):
69 with open(tested_symbols_location
, 'r') as file:
70 print("Loading tested symbols")
72 tested_symbols
.add(line
[:-1])
74 for bitcode_file
in glob
.iglob(os
.path
.join(RUNTIME_INSTALL_DIR
, "runtime", "*." + file_suffix
)):
75 bitcode_basename
= os
.path
.basename(bitcode_file
)
77 print("Appending symbols from " + bitcode_basename
)
78 lines
= subprocess
.check_output([os
.path
.join(LLVM_BINS
, "llvm-nm"), "--defined-only", bitcode_file
]).splitlines()
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
85 if os
.path
.isfile(symbol_table_location
):
86 with open(symbol_table_location
, 'r') as file:
87 print("Loading symbol table")
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
94 symbol_list
= symbol_table
.items()
96 print("Writing symbol table: " + symbol_table_location
)
97 print("Writing inline file: " + include_symbol_table_location
)
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")