39
39
multiprocessing_pool = None
40
40
binaryen_checked = False
41
41
42
- # internal caches
43
- internal_nm_cache = {}
44
42
# cache results of nm - it can be slow to run
45
- uninternal_nm_cache = {}
43
+ nm_cache = {}
46
44
# Stores the object files contained in different archive files passed as input
47
45
ar_contents = {}
48
46
_is_ar_cache = {}
@@ -150,12 +148,11 @@ def check(value):
150
148
return list (filter (check , values ))
151
149
152
150
153
- # clear internal caches. this is not normally needed, except if the clang/LLVM
151
+ # clear caches. this is not normally needed, except if the clang/LLVM
154
152
# used changes inside this invocation of Building, which can happen in the benchmarker
155
153
# when it compares different builds.
156
154
def clear ():
157
- internal_nm_cache .clear ()
158
- uninternal_nm_cache .clear ()
155
+ nm_cache .clear ()
159
156
ar_contents .clear ()
160
157
_is_ar_cache .clear ()
161
158
@@ -372,7 +369,7 @@ def make_paths_absolute(f):
372
369
373
370
374
371
# Runs llvm-nm in parallel for the given list of files.
375
- # The results are populated in uninternal_nm_cache
372
+ # The results are populated in nm_cache
376
373
# multiprocessing_pool: An existing multiprocessing pool to reuse for the operation, or None
377
374
# to have the function allocate its own.
378
375
def parallel_llvm_nm (files ):
@@ -383,7 +380,7 @@ def parallel_llvm_nm(files):
383
380
for i , file in enumerate (files ):
384
381
if object_contents [i ].returncode != 0 :
385
382
logger .debug ('llvm-nm failed on file ' + file + ': return code ' + str (object_contents [i ].returncode ) + ', error: ' + object_contents [i ].output )
386
- uninternal_nm_cache [file ] = object_contents [i ]
383
+ nm_cache [file ] = object_contents [i ]
387
384
return object_contents
388
385
389
386
@@ -398,7 +395,7 @@ def read_link_inputs(files):
398
395
399
396
if absolute_path_f not in ar_contents and is_ar (absolute_path_f ):
400
397
archive_names .append (absolute_path_f )
401
- elif absolute_path_f not in uninternal_nm_cache and is_bitcode (absolute_path_f ):
398
+ elif absolute_path_f not in nm_cache and is_bitcode (absolute_path_f ):
402
399
object_names .append (absolute_path_f )
403
400
404
401
# Archives contain objects, so process all archives first in parallel to obtain the object files in them.
@@ -419,7 +416,7 @@ def clean_at_exit():
419
416
420
417
for o in object_names_in_archives :
421
418
for f in o ['files' ]:
422
- if f not in uninternal_nm_cache :
419
+ if f not in nm_cache :
423
420
object_names .append (f )
424
421
425
422
# Next, extract symbols from all object files (either standalone or inside archives we just extracted)
@@ -730,7 +727,7 @@ def get_command_with_possible_response_file(cmd):
730
727
return new_cmd
731
728
732
729
733
- def parse_symbols (output , include_internal = False ):
730
+ def parse_symbols (output ):
734
731
defs = []
735
732
undefs = []
736
733
commons = []
@@ -753,42 +750,37 @@ def parse_symbols(output, include_internal=False):
753
750
undefs .append (symbol )
754
751
elif status == 'C' :
755
752
commons .append (symbol )
756
- elif (not include_internal and status == status .upper ()) or \
757
- (include_internal and status in ['W' , 't' , 'T' , 'd' , 'D' ]):
753
+ elif status == status .upper ():
758
754
# FIXME: using WTD in the previous line fails due to llvm-nm behavior on macOS,
759
755
# so for now we assume all uppercase are normally defined external symbols
760
756
defs .append (symbol )
761
757
return ObjectFileInfo (0 , None , set (defs ), set (undefs ), set (commons ))
762
758
763
759
764
- def llvm_nm_uncached (filename , stdout = PIPE , stderr = PIPE , include_internal = False ):
760
+ def llvm_nm_uncached (filename , stdout = PIPE , stderr = PIPE ):
765
761
# LLVM binary ==> list of symbols
766
762
proc = run_process ([LLVM_NM , filename ], stdout = stdout , stderr = stderr , check = False )
767
763
if proc .returncode == 0 :
768
- return parse_symbols (proc .stdout , include_internal )
764
+ return parse_symbols (proc .stdout )
769
765
else :
770
766
return ObjectFileInfo (proc .returncode , str (proc .stdout ) + str (proc .stderr ))
771
767
772
768
773
- def llvm_nm (filename , stdout = PIPE , stderr = PIPE , include_internal = False ):
769
+ def llvm_nm (filename , stdout = PIPE , stderr = PIPE ):
774
770
# Always use absolute paths to maximize cache usage
775
771
filename = os .path .abspath (filename )
776
772
777
- if include_internal and filename in internal_nm_cache :
778
- return internal_nm_cache [filename ]
779
- elif not include_internal and filename in uninternal_nm_cache :
780
- return uninternal_nm_cache [filename ]
773
+ if filename in nm_cache :
774
+ return nm_cache [filename ]
781
775
782
- ret = llvm_nm_uncached (filename , stdout , stderr , include_internal )
776
+ ret = llvm_nm_uncached (filename , stdout , stderr )
783
777
784
778
if ret .returncode != 0 :
785
779
logger .debug ('llvm-nm failed on file ' + filename + ': return code ' + str (ret .returncode ) + ', error: ' + ret .output )
786
780
787
- # Even if we fail, write the results to the NM cache so that we don't keep trying to llvm-nm the failing file again later.
788
- if include_internal :
789
- internal_nm_cache [filename ] = ret
790
- else :
791
- uninternal_nm_cache [filename ] = ret
781
+ # Even if we fail, write the results to the NM cache so that we don't keep trying to llvm-nm the
782
+ # failing file again later.
783
+ nm_cache [filename ] = ret
792
784
793
785
return ret
794
786
0 commit comments