10
10
import re
11
11
12
12
13
- def get_llvm_bin_path ():
14
- if "LLVM_BIN_PATH" in os .environ :
15
- return os .environ ["LLVM_BIN_PATH" ]
16
- return ""
17
-
18
-
19
13
def match_symbol (sym_binding , sym_type , sym_section ):
20
14
if sym_binding is None or sym_type is None or sym_section is None :
21
15
return False
@@ -65,7 +59,7 @@ def parse_readobj_output(output):
65
59
return parsed_symbols
66
60
67
61
68
- def dump_symbols (target_path , output ):
62
+ def dump_symbols (target_path , output , llvm_bin_path ):
69
63
with open (output , "w" ) as out :
70
64
out .write (
71
65
"################################################################################"
@@ -93,7 +87,7 @@ def dump_symbols(target_path, output):
93
87
readobj_opts = "--coff-exports" if os .name == "nt" else "--syms"
94
88
readobj_out = subprocess .check_output (
95
89
[
96
- os .path .join (get_llvm_bin_path () , "llvm-readobj" ),
90
+ os .path .join (llvm_bin_path , "llvm-readobj" ),
97
91
readobj_opts ,
98
92
target_path ,
99
93
]
@@ -113,7 +107,7 @@ def compare_results(ref_records, records):
113
107
114
108
# Dumps symbols from from binary at target_path and compares with a snapshot
115
109
# stored at ref_path. Reports new and absent symbols (if there are any).
116
- def check_symbols (ref_path , target_path ):
110
+ def check_symbols (ref_path , target_path , llvm_bin_path ):
117
111
with open (ref_path , "r" ) as ref :
118
112
ref_symbols = []
119
113
for line in ref :
@@ -123,7 +117,7 @@ def check_symbols(ref_path, target_path):
123
117
readobj_opts = "--coff-exports" if os .name == "nt" else "--syms"
124
118
readobj_out = subprocess .check_output (
125
119
[
126
- os .path .join (get_llvm_bin_path () , "llvm-readobj" ),
120
+ os .path .join (llvm_bin_path , "llvm-readobj" ),
127
121
readobj_opts ,
128
122
target_path ,
129
123
]
@@ -171,20 +165,27 @@ def main():
171
165
)
172
166
parser .add_argument ("--reference" , type = str , help = "Reference ABI dump" )
173
167
parser .add_argument ("--output" , type = str , help = "Output for dump modes" )
168
+ parser .add_argument (
169
+ "--llvm-bin-path" ,
170
+ type = str ,
171
+ default = os .getenv ("LLVM_BIN_PATH" , "" ),
172
+ help =
173
+ "Path to LLVM binaries. Can be overridden by LLVM_BIN_PATH environment variable."
174
+ )
174
175
parser .add_argument ("target_library" , type = str )
175
176
176
177
args = parser .parse_args ()
177
178
178
179
if args .mode == "check_symbols" :
179
180
if args .reference is None :
180
- print ("Please specify --reference option. Quiting ." )
181
+ print ("Please specify --reference option. Quitting ." )
181
182
sys .exit (- 2 )
182
- check_symbols (args .reference , args .target_library )
183
+ check_symbols (args .reference , args .target_library , args . llvm_bin_path )
183
184
elif args .mode == "dump_symbols" :
184
185
if args .output is None :
185
- print ("Please specify --output option. Quiting ." )
186
+ print ("Please specify --output option. Quitting ." )
186
187
sys .exit (- 2 )
187
- dump_symbols (args .target_library , args .output )
188
+ dump_symbols (args .target_library , args .output , args . llvm_bin_path )
188
189
189
190
190
191
if __name__ == "__main__" :
0 commit comments