@@ -471,21 +471,36 @@ def do_emscripten(infile, memfile):
471471  return  outfile 
472472
473473
474+ def  is_ar_file_with_missing_index (archive_file ):
475+   # We parse the archive header outselves because llvm-nm --print-armap is slower and less 
476+   # reliable. 
477+   # See: https://github.com/emscripten-core/emscripten/issues/10195 
478+   archive_header  =  b'!<arch>\n ' 
479+   file_header_size  =  60 
480+ 
481+   with  open (archive_file ) as  f :
482+     header  =  f .read (len (archive_header ))
483+     if  header  !=  archive_header :
484+       # This is not even an ar file 
485+       return  False 
486+     file_header  =  f .read (file_header_size )
487+     if  len (file_header ) !=  file_header_size :
488+       # We don't have any file entires at all so we don't consider the index missing 
489+       return  False 
490+ 
491+   name  =  file_header [:16 ].strip ()
492+   # If '/' is the name of the first file we have an index 
493+   return  name  !=  '/' 
494+ 
495+ 
474496def  ensure_archive_index (archive_file ):
475497  # Fastcomp linking works without archive indexes. 
476498  if  not  shared .Settings .WASM_BACKEND  or  not  shared .Settings .AUTO_ARCHIVE_INDEXES :
477499    return 
478-   # Ignore stderr since llvm-nm prints "no symbols" to stderr for each object that has no symbols 
479-   stdout  =  run_process ([shared .LLVM_NM , '--print-armap' , archive_file ], stdout = PIPE , stderr = PIPE ).stdout 
480-   stdout  =  stdout .strip ()
481-   # Ignore empty archives 
482-   if  not  stdout :
483-     return 
484-   if  stdout .startswith ('Archive map\n ' ) or  stdout .startswith ('Archive index\n ' ):
485-     return 
486-   shared .warning ('%s: archive is missing an index; Use emar when creating libraries to ensure an index is created' , archive_file )
487-   shared .warning ('%s: adding index' , archive_file )
488-   run_process ([shared .LLVM_RANLIB , archive_file ])
500+   if  is_ar_file_with_missing_index (archive_file ):
501+     shared .warning ('%s: archive is missing an index; Use emar when creating libraries to ensure an index is created' , archive_file )
502+     shared .warning ('%s: adding index' , archive_file )
503+     run_process ([shared .LLVM_RANLIB , archive_file ])
489504
490505
491506# 
0 commit comments