@@ -991,20 +991,32 @@ try:
991991 for name , create , fix , library_symbols in [('libcxx' , create_libcxx , fix_libcxx , libcxx_symbols ),
992992 ('libcxxabi' , create_libcxxabi , fix_libcxxabi , libcxxabi_symbols ),
993993 ('dlmalloc' , create_dlmalloc , fix_dlmalloc , dlmalloc_symbols )]:
994- need = []
995- has = []
994+ need = set ()
995+ has = set ()
996996 for temp_file in temp_files :
997997 symbols = shared .Building .llvm_nm (temp_file )
998998 for library_symbol in library_symbols :
999999 if library_symbol in symbols .undefs :
1000- need .append (library_symbol )
1000+ need .add (library_symbol )
10011001 if library_symbol in symbols .defs :
1002- has .append (library_symbol )
1003- if DEBUG : print >> sys .stderr , 'emcc: considering including %s: we need |%s| and have |%s|' % (name , str (need ), str (has ))
1004- if force or (need and not has ):
1002+ has .add (library_symbol )
1003+ for haz in has : # remove symbols that are supplied by another of the inputs
1004+ if haz in need :
1005+ need .remove (haz )
1006+ if DEBUG : print >> sys .stderr , 'emcc: considering including %s: we need %s and have %s' % (name , str (need ), str (has ))
1007+ if force or len (need ) > 0 :
10051008 # We need to build and link the library in
10061009 if DEBUG : print >> sys .stderr , 'emcc: including %s' % name
1007- extra_files_to_link .append (shared .Cache .get (name , create ))
1010+ libfile = shared .Cache .get (name , create )
1011+ if len (has ) > 0 :
1012+ # remove the symbols we do not need
1013+ fixed = in_temp (uniquename (libfile )) + '.bc'
1014+ shutil .copyfile (libfile , fixed )
1015+ for haz in has :
1016+ if DEBUG : print >> sys .stderr , 'emcc: including: removing symbol "%s" that we have' % haz
1017+ shared .Building .remove_symbol (fixed , haz )
1018+ libfile = fixed
1019+ extra_files_to_link .append (libfile )
10081020 force = True
10091021 if fix :
10101022 fix ()
0 commit comments