diff options
Diffstat (limited to 'emcc')
-rwxr-xr-x | emcc | 75 |
1 files changed, 52 insertions, 23 deletions
@@ -163,10 +163,14 @@ Options that are modified or new in %s include: EMCC_OPTIMIZE_NORMALLY=1 (not recommended unless you know what you are doing!) -O2 As -O1, plus the relooper (loop recreation), - plus LLVM -O2 optimizations + LLVM -O2 optimizations, and + + -s ALIASING_FUNCTION_POINTERS=1 + -O3 As -O2, plus dangerous optimizations that may break the generated code! This adds + -s FORCE_ALIGNED_MEMORY=1 -s DOUBLE_MODE=0 -s PRECISE_I64_MATH=0 --closure 1 @@ -174,7 +178,8 @@ Options that are modified or new in %s include: This is not recommended at all. A better idea is to try each of these separately on top of - -O2 to see what works. See the wiki for more + -O2 to see what works. See the wiki and + src/settings.js (for the -s options) for more information. -s OPTION=VALUE JavaScript code generation option passed @@ -241,6 +246,11 @@ Options that are modified or new in %s include: may require some changes to the code. This is run by default in -O3. + In asm.js mode, closure will only be used on the + 'shell' code around the compiled code (the + compiled code will be processed by the custom + asm.js minifier). + Note: If closure compiler hits an out-of-memory, try adjusting JAVA_HEAP_SIZE in the environment (for example, to 4096m for 4GB). @@ -1019,9 +1029,6 @@ try: if bind: shared.Settings.ASM_JS = 0 logging.warning('disabling asm.js because it is not compatible with embind yet') - if closure: - logging.warning('disabling closure because it is not compatible with asm.js code generation') - closure = False if shared.Settings.CORRECT_SIGNS != 1: logging.warning('setting CORRECT_SIGNS to 1 for asm.js code generation') shared.Settings.CORRECT_SIGNS = 1 @@ -1030,6 +1037,9 @@ try: shared.Settings.CORRECT_OVERFLOWS = 1 assert not shared.Settings.PGO, 'cannot run PGO in ASM_JS mode' + if shared.Settings.ASSERTIONS and shared.Settings.ALIASING_FUNCTION_POINTERS: + logging.warning('ALIASING_FUNCTION_POINTERS is on, function pointer comparisons may be invalid across types') + if shared.Settings.CORRECT_SIGNS >= 2 or shared.Settings.CORRECT_OVERFLOWS >= 2 or shared.Settings.CORRECT_ROUNDINGS >= 2: keep_llvm_debug = True # must keep debug info to do line-by-line operations @@ -1141,6 +1151,7 @@ try: # XXX We also need to add libc symbols that use malloc, for example strdup. It's very rare to use just them and not # a normal malloc symbol (like free, after calling strdup), so we haven't hit this yet, but it is possible. libc_symbols = read_symbols(shared.path_from_root('system', 'lib', 'libc.symbols')) + sdl_symbols = read_symbols(shared.path_from_root('system', 'lib', 'sdl.symbols')) libcextra_symbols = read_symbols(shared.path_from_root('system', 'lib', 'libcextra.symbols')) libcxx_symbols = read_symbols(shared.path_from_root('system', 'lib', 'libcxx', 'symbols'), exclude=libc_symbols) libcxxabi_symbols = read_symbols(shared.path_from_root('system', 'lib', 'libcxxabi', 'symbols'), exclude=libc_symbols) @@ -1187,7 +1198,7 @@ try: ]; return build_libc('libc.bc', libc_files) - def fix_libc(need): + def apply_libc(need): # libc needs some sign correction. # If we are in mode 0, switch to 2. We will add our lines try: if shared.Settings.CORRECT_SIGNS == 0: raise Exception('we need to change to 2') @@ -1197,6 +1208,7 @@ try: shared.Settings.CORRECT_SIGNS_LINES = [shared.path_from_root('src', 'dlmalloc.c') + ':' + str(i+4) for i in [4816, 4191, 4246, 4199, 4205, 4235, 4227]] # If we are in mode 1, we are correcting everything anyhow. If we are in mode 3, we will be corrected # so all is well anyhow too. + return True # libcextra def create_libcextra(): @@ -1274,9 +1286,6 @@ try: libcextra_files += [os.path.join('libc', 'musl', 'src', directory, source) for source in sources] return build_libc('libcextra.bc', libcextra_files) - def fix_libcextra(need): - pass - # libcxx def create_libcxx(): logging.debug('building libcxx for cache') @@ -1306,11 +1315,12 @@ try: ] return build_libcxx(os.path.join('system', 'lib', 'libcxx'), 'libcxx.bc', libcxx_files) - def fix_libcxx(need): + def apply_libcxx(need): assert shared.Settings.QUANTUM_SIZE == 4, 'We do not support libc++ with QUANTUM_SIZE == 1' # libcxx might need corrections, so turn them all on. TODO: check which are actually needed shared.Settings.CORRECT_SIGNS = shared.Settings.CORRECT_OVERFLOWS = shared.Settings.CORRECT_ROUNDINGS = 1 #logging.info('using libcxx turns on CORRECT_* options') + return True # libcxxabi - just for dynamic_cast for now def create_libcxxabi(): @@ -1321,25 +1331,43 @@ try: ] return build_libcxx(os.path.join('system', 'lib', 'libcxxabi', 'src'), 'libcxxabi.bc', libcxxabi_files) - def fix_libcxxabi(need): + def apply_libcxxabi(need): assert shared.Settings.QUANTUM_SIZE == 4, 'We do not support libc++abi with QUANTUM_SIZE == 1' #logging.info('using libcxxabi, this may need CORRECT_* options') #shared.Settings.CORRECT_SIGNS = shared.Settings.CORRECT_OVERFLOWS = shared.Settings.CORRECT_ROUNDINGS = 1 + return True + + # SDL. We include code that demands malloc/free if not already required, so we have proper malloc/free from JS SDL code. + # Note that the Force instance here can be optimized out, but we still export malloc/free, so they will be kept alive. + def create_sdl(): + return build_libcxx(os.path.join('system', 'lib'), 'sdl.bc', ['sdl.cpp']) + + def apply_sdl(need): + return 'SDL_Init' in all_needed and ('malloc' not in all_needed or 'free' not in all_needed) # Settings this in the environment will avoid checking dependencies and make building big projects a little faster force = os.environ.get('EMCC_FORCE_STDLIBS') + # Scan symbols + all_needed = set() + symbolses = map(lambda temp_file: shared.Building.llvm_nm(temp_file), temp_files) + for symbols in symbolses: + all_needed.update(symbols.undefs) + for symbols in symbolses: + all_needed.difference_update(symbols.defs) + + # Go over libraries to figure out which we must include # If we have libcxx, we must force inclusion of libc, since libcxx uses new internally. Note: this is kind of hacky. has = need = None - for name, create, fix, library_symbols in [('libcxx', create_libcxx, fix_libcxx, libcxx_symbols), - ('libcextra', create_libcextra, fix_libcextra, libcextra_symbols), - ('libcxxabi', create_libcxxabi, fix_libcxxabi, libcxxabi_symbols), - ('libc', create_libc, fix_libc, libc_symbols)]: + for name, create, apply_, library_symbols in [('libcxx', create_libcxx, apply_libcxx, libcxx_symbols), + ('libcextra', create_libcextra, lambda x: True, libcextra_symbols), + ('libcxxabi', create_libcxxabi, apply_libcxxabi, libcxxabi_symbols), + ('sdl', create_sdl, apply_sdl, sdl_symbols), + ('libc', create_libc, apply_libc, libc_symbols)]: if not force: need = set() has = set() - for temp_file in temp_files: - symbols = shared.Building.llvm_nm(temp_file) + for symbols in symbolses: for library_symbol in library_symbols: if library_symbol in symbols.undefs: need.add(library_symbol) @@ -1349,14 +1377,12 @@ try: if haz in need: need.remove(haz) logging.debug('considering %s: we need %s and have %s' % (name, str(need), str(has))) - if force or len(need) > 0: + if (force or len(need) > 0) and apply_(need): # We need to build and link the library in logging.debug('including %s' % name) libfile = shared.Cache.get(name, create) extra_files_to_link.append(libfile) force = True - if fix and need: - fix(need) # First, combine the bitcode files if there are several. We must also link if we have a singleton .a if len(input_files) + len(extra_files_to_link) > 1 or \ @@ -1525,7 +1551,7 @@ try: if shared.Settings.RELOOP and not shared.Settings.ASM_JS: js_optimizer_queue += ['optimizeShiftsAggressive', get_eliminate()] # aggressive shifts optimization requires loops, it breaks on switches - if closure: + if closure and not shared.Settings.ASM_JS: flush_js_optimizer_queue() logging.debug('running closure') @@ -1536,13 +1562,16 @@ try: logging.debug('running post-closure post-opts') js_optimizer_queue += ['simplifyExpressionsPost'] - if not closure and shared.Settings.RELOOP and not keep_js_debug: + if (not closure or shared.Settings.ASM_JS) and shared.Settings.RELOOP and not keep_js_debug: # do this if closure is not enabled (it gives similar speedups), and we do not need to keep debug info around js_optimizer_queue += ['registerize'] if minify_whitespace: js_optimizer_queue += ['compress'] + if closure and shared.Settings.ASM_JS: + js_optimizer_queue += ['closure'] + js_optimizer_queue += ['last'] flush_js_optimizer_queue() @@ -1570,7 +1599,7 @@ try: if os.path.abspath(memfile) != os.path.abspath(memfile): shutil.copyfile(memfile, temp_memfile) return 'loadMemoryInitializer("%s");' % os.path.basename(memfile) - src = re.sub('/\* memory initializer \*/ allocate\(([\d,\.concat\(\)\[\]\\n ]+)"i8", ALLOC_NONE, TOTAL_STACK\)', repl, src, count=1) + src = re.sub('/\* memory initializer \*/ allocate\(([\d,\.concat\(\)\[\]\\n ]+)"i8", ALLOC_NONE, Runtime\.GLOBAL_BASE\)', repl, src, count=1) open(final + '.mem.js', 'w').write(src) final += '.mem.js' if DEBUG: |