diff options
Diffstat (limited to 'emcc')
-rwxr-xr-x | emcc | 120 |
1 files changed, 92 insertions, 28 deletions
@@ -238,6 +238,9 @@ Options that are modified or new in %s include: (see --llvm-opts), setting this has no effect. + Note that LLVM LTO is not perfectly stable yet, + and can can cause code to behave incorrectly. + --closure <on> 0: No closure compiler (default in -O2 and below) 1: Run closure compiler. This greatly reduces code size and may in some cases increase @@ -717,6 +720,13 @@ else: def in_temp(name): return os.path.join(temp_dir, os.path.basename(name)) +# Parses the essential suffix of a filename, discarding Unix-style version numbers in the name. For example for 'libz.so.1.2.8' returns '.so' +def filename_type_suffix(filename): + for i in reversed(filename.split('.')[1:]): + if not i.isdigit(): + return '.' + i + return '' + try: call = CXX if use_cxx else CC @@ -971,35 +981,45 @@ try: if i > 0: prev = newargs[i-1] - if prev in ['-MT', '-MF', '-MQ', '-D', '-U', '-o', '-x', '-Xpreprocessor', '-include', '-imacros', '-idirafter', '-iprefix', '-iwithprefix', '-iwithprefixbefore', '-isysroot', '-imultilib', '-A', '-isystem', '-iquote', '-install_name', '-I', '-L']: continue # ignore this gcc-style argument + if prev in ['-MT', '-MF', '-MQ', '-D', '-U', '-o', '-x', '-Xpreprocessor', '-include', '-imacros', '-idirafter', '-iprefix', '-iwithprefix', '-iwithprefixbefore', '-isysroot', '-imultilib', '-A', '-isystem', '-iquote', '-install_name', '-compatibility_version', '-current_version', '-I', '-L']: continue # ignore this gcc-style argument if (os.path.islink(arg) and os.path.realpath(arg).endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + ASSEMBLY_SUFFIXES)): arg = os.path.realpath(arg) - if not arg.startswith('-') and (arg.endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + ASSEMBLY_SUFFIXES) or shared.Building.is_ar(arg)): # we already removed -o <target>, so all these should be inputs - newargs[i] = '' - if os.path.exists(arg): - if arg.endswith(SOURCE_SUFFIXES): + if not arg.startswith('-'): + if not os.path.exists(arg): + logging.error(arg + ': No such file or directory') + exit(1) + + arg_suffix = filename_type_suffix(arg) + if arg_suffix.endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + ASSEMBLY_SUFFIXES) or shared.Building.is_ar(arg): # we already removed -o <target>, so all these should be inputs + newargs[i] = '' + if arg_suffix.endswith(SOURCE_SUFFIXES): input_files.append(arg) has_source_inputs = True + elif arg_suffix.endswith(ASSEMBLY_SUFFIXES) or shared.Building.is_bitcode(arg): # this should be bitcode, make sure it is valid + input_files.append(arg) + elif arg_suffix.endswith(STATICLIB_SUFFIXES + DYNAMICLIB_SUFFIXES): + # if it's not, and it's a library, just add it to libs to find later + l = unsuffixed_basename(arg) + for prefix in LIB_PREFIXES: + if not prefix: continue + if l.startswith(prefix): + l = l[len(prefix):] + break + libs.append(l) + newargs[i] = '' else: - # this should be bitcode, make sure it is valid - if arg.endswith(ASSEMBLY_SUFFIXES) or shared.Building.is_bitcode(arg): - input_files.append(arg) - elif arg.endswith(STATICLIB_SUFFIXES + DYNAMICLIB_SUFFIXES): - # if it's not, and it's a library, just add it to libs to find later - l = unsuffixed_basename(arg) - for prefix in LIB_PREFIXES: - if not prefix: continue - if l.startswith(prefix): - l = l[len(prefix):] - break - libs.append(l) - newargs[i] = '' + logging.warning(arg + ' is not valid LLVM bitcode') + elif arg_suffix.endswith(STATICLIB_SUFFIXES): + if not shared.Building.is_ar(arg): + if shared.Building.is_bitcode(arg): + logging.error(arg + ': File has a suffix of a static library ' + str(STATICLIB_SUFFIXES) + ', but instead is an LLVM bitcode file! When linking LLVM bitcode files, use one of the suffixes ' + str(BITCODE_SUFFIXES)) else: - logging.warning(arg + ' is not valid LLVM bitcode') + logging.error(arg + ': Unknown format, not a static library!') + exit(1) else: - logging.error(arg + ': No such file or directory') + logging.error(arg + ": Input file has an unknown suffix, don't know what to do with it!") exit(1) elif arg.startswith('-L'): lib_dirs.append(arg[2:]) @@ -1148,13 +1168,14 @@ try: # First, generate LLVM bitcode. For each input file, we get base.o with bitcode for input_file in input_files: - if input_file.endswith(SOURCE_SUFFIXES): + file_suffix = filename_type_suffix(input_file) + if file_suffix.endswith(SOURCE_SUFFIXES): logging.debug('compiling source file: ' + input_file) input_file = shared.Building.preprocess(input_file, in_temp(uniquename(input_file))) output_file = in_temp(unsuffixed(uniquename(input_file)) + '.o') temp_files.append(output_file) args = newargs + ['-emit-llvm', '-c', input_file, '-o', output_file] - if input_file.endswith(CXX_SUFFIXES): + if file_suffix.endswith(CXX_SUFFIXES): args += shared.EMSDK_CXX_OPTS logging.debug("running: " + call + ' ' + ' '.join(args)) execute([call] + args) # let compiler frontend print directly, so colors are saved (PIPE kills that) @@ -1162,17 +1183,17 @@ try: logging.error('compiler frontend failed to generate LLVM bitcode, halting') sys.exit(1) else: # bitcode - if input_file.endswith(BITCODE_SUFFIXES): + if file_suffix.endswith(BITCODE_SUFFIXES): logging.debug('copying bitcode file: ' + input_file) temp_file = in_temp(unsuffixed(uniquename(input_file)) + '.o') shutil.copyfile(input_file, temp_file) temp_files.append(temp_file) - elif input_file.endswith(DYNAMICLIB_SUFFIXES) or shared.Building.is_ar(input_file): + elif file_suffix.endswith(DYNAMICLIB_SUFFIXES) or shared.Building.is_ar(input_file): logging.debug('copying library file: ' + input_file) temp_file = in_temp(uniquename(input_file)) shutil.copyfile(input_file, temp_file) temp_files.append(temp_file) - else: #.ll + elif file_suffix.endswith(ASSEMBLY_SUFFIXES): if not LEAVE_INPUTS_RAW: # Note that by assembling the .ll file, then disassembling it later, we will # remove annotations which is a good thing for compilation time @@ -1180,6 +1201,9 @@ try: temp_file = in_temp(unsuffixed(uniquename(input_file)) + '.o') shared.Building.llvm_as(input_file, temp_file) temp_files.append(temp_file) + else: + logging.error(input_file + ': Unknown file suffix when compiling to LLVM bitcode!') + sys.exit(1) if not LEAVE_INPUTS_RAW: assert len(temp_files) == len(input_files) @@ -1187,7 +1211,8 @@ try: # Optimize source files if llvm_opts > 0: for i, input_file in enumerate(input_files): - if input_file.endswith(SOURCE_SUFFIXES): + file_suffix = filename_type_suffix(input_file) + if file_suffix.endswith(SOURCE_SUFFIXES): temp_file = temp_files[i] logging.debug('optimizing %s with -O%d' % (input_file, llvm_opts)) shared.Building.llvm_opt(temp_file, llvm_opts) @@ -1279,6 +1304,10 @@ try: os.path.join('libc', 'gen', 'vwarnx.c'), os.path.join('libc', 'stdlib', 'strtod.c'), ] + musl_files = [ + ] + for directory, sources in musl_files: + libc_files += [os.path.join('libc', 'musl', 'src', directory, source) for source in sources] return build_libc('libc.bc', libc_files) def apply_libc(need): @@ -1316,6 +1345,33 @@ try: 'wctrans.c', 'wcwidth.c', ]], + ['locale', [ + 'iconv.c', + 'iswalnum_l.c', + 'iswalpha_l.c', + 'iswblank_l.c', + 'iswcntrl_l.c', + 'iswctype_l.c', + 'iswdigit_l.c', + 'iswgraph_l.c', + 'iswlower_l.c', + 'iswprint_l.c', + 'iswpunct_l.c', + 'iswspace_l.c', + 'iswupper_l.c', + 'iswxdigit_l.c', + 'strfmon.c', + 'strxfrm.c', + 'towctrans_l.c', + 'towlower_l.c', + 'towupper_l.c', + 'wcscoll.c', + 'wcscoll_l.c', + 'wcsxfrm.c', + 'wcsxfrm_l.c', + 'wctrans_l.c', + 'wctype_l.c', + ]], ['multibyte', [ 'btowc.c', 'mblen.c', @@ -1333,6 +1389,14 @@ try: 'wctob.c', 'wctomb.c', ]], + ['stdio', [ + 'fwprintf.c', + 'swprintf.c', + 'vfwprintf.c', + 'vswprintf.c', + 'vwprintf.c', + 'wprintf.c', + ]], ['stdlib', [ 'ecvt.c', 'fcvt.c', @@ -1342,7 +1406,7 @@ try: 'wcpcpy.c', 'wcpncpy.c', 'wcscasecmp.c', - # 'wcscasecmp_l.c', # XXX: alltypes.h issue + 'wcscasecmp_l.c', 'wcscat.c', 'wcschr.c', 'wcscmp.c', @@ -1351,7 +1415,7 @@ try: 'wcsdup.c', 'wcslen.c', 'wcsncasecmp.c', - # 'wcsncasecmp_l.c', # XXX: alltypes.h issue + 'wcsncasecmp_l.c', 'wcsncat.c', 'wcsncmp.c', 'wcsncpy.c', |