From 143e37da3154ed7f3dcc33e68cc02d303d6a1482 Mon Sep 17 00:00:00 2001 From: marco trivellato Date: Fri, 7 Apr 2017 08:43:47 +0100 Subject: [PATCH 1/7] fix calls to setThrew --- src/library.js | 4 ++-- src/parseTools.js | 4 ++-- tools/shared.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/library.js b/src/library.js index 91dacc71da2bc..bd754b687dbb0 100644 --- a/src/library.js +++ b/src/library.js @@ -1215,7 +1215,7 @@ LibraryManager.library = { __cxa_end_catch__deps: ['__cxa_free_exception', '$EXCEPTIONS'], __cxa_end_catch: function() { // Clear state flag. - asm['setThrew'](0); + Module['asm']['setThrew'](0); // Call destructor if one is registered then clear it. var ptr = EXCEPTIONS.caught.pop(); #if EXCEPTION_DEBUG @@ -2788,7 +2788,7 @@ LibraryManager.library = { longjmp__deps: ['saveSetjmp', 'testSetjmp'], longjmp: function(env, value) { - asm['setThrew'](env, value || 1); + Module['asm']['setThrew'](env, value || 1); throw 'longjmp'; }, emscripten_longjmp__deps: ['longjmp'], diff --git a/src/parseTools.js b/src/parseTools.js index c7871f5afa5f4..014bfca77a2e6 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1293,7 +1293,7 @@ function makeGetTempRet0() { function makeSetTempRet0(value) { if (WASM_BACKEND == 1) { - return 'asm["setTempRet0"](' + value + ')'; + return 'Module["asm"]["setTempRet0"](' + value + ')'; } else { return RELOCATABLE ? "setTempRet0((" + value + ") | 0)" : ("tempRet0 = " + value); } @@ -1305,7 +1305,7 @@ function makeStructuralReturn(values, inAsm) { i++; if (!inAsm) { if (!RELOCATABLE) { - return 'asm["setTempRet' + i + '"](' + value + ')'; + return 'Module["asm"]["setTempRet' + i + '"](' + value + ')'; } else { return 'Runtime.setTempRet' + i + '(' + value + ')'; } diff --git a/tools/shared.py b/tools/shared.py index 2e5381bf86ecb..91c5e7d197756 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -2153,7 +2153,7 @@ def make_invoke(sig, named=True): %sModule["dynCall_%s"](%s); } catch(e) { if (typeof e !== 'number' && e !== 'longjmp') throw e; - asm["setThrew"](1, 0); + Module['asm']["setThrew"](1, 0); } }''' % ((' invoke_' + sig) if named else '', args, 'return ' if sig[0] != 'v' else '', sig, args) return ret From 42678d6344b4bdab7de590c7f9ecb51699c9d933 Mon Sep 17 00:00:00 2001 From: Marco Trivellato Date: Fri, 26 May 2017 09:50:00 +0200 Subject: [PATCH 2/7] Revert "fix calls to setThrew" This reverts commit 143e37da3154ed7f3dcc33e68cc02d303d6a1482. --- src/library.js | 4 ++-- src/parseTools.js | 4 ++-- tools/shared.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/library.js b/src/library.js index bd754b687dbb0..91dacc71da2bc 100644 --- a/src/library.js +++ b/src/library.js @@ -1215,7 +1215,7 @@ LibraryManager.library = { __cxa_end_catch__deps: ['__cxa_free_exception', '$EXCEPTIONS'], __cxa_end_catch: function() { // Clear state flag. - Module['asm']['setThrew'](0); + asm['setThrew'](0); // Call destructor if one is registered then clear it. var ptr = EXCEPTIONS.caught.pop(); #if EXCEPTION_DEBUG @@ -2788,7 +2788,7 @@ LibraryManager.library = { longjmp__deps: ['saveSetjmp', 'testSetjmp'], longjmp: function(env, value) { - Module['asm']['setThrew'](env, value || 1); + asm['setThrew'](env, value || 1); throw 'longjmp'; }, emscripten_longjmp__deps: ['longjmp'], diff --git a/src/parseTools.js b/src/parseTools.js index 014bfca77a2e6..c7871f5afa5f4 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1293,7 +1293,7 @@ function makeGetTempRet0() { function makeSetTempRet0(value) { if (WASM_BACKEND == 1) { - return 'Module["asm"]["setTempRet0"](' + value + ')'; + return 'asm["setTempRet0"](' + value + ')'; } else { return RELOCATABLE ? "setTempRet0((" + value + ") | 0)" : ("tempRet0 = " + value); } @@ -1305,7 +1305,7 @@ function makeStructuralReturn(values, inAsm) { i++; if (!inAsm) { if (!RELOCATABLE) { - return 'Module["asm"]["setTempRet' + i + '"](' + value + ')'; + return 'asm["setTempRet' + i + '"](' + value + ')'; } else { return 'Runtime.setTempRet' + i + '(' + value + ')'; } diff --git a/tools/shared.py b/tools/shared.py index 91c5e7d197756..2e5381bf86ecb 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -2153,7 +2153,7 @@ def make_invoke(sig, named=True): %sModule["dynCall_%s"](%s); } catch(e) { if (typeof e !== 'number' && e !== 'longjmp') throw e; - Module['asm']["setThrew"](1, 0); + asm["setThrew"](1, 0); } }''' % ((' invoke_' + sig) if named else '', args, 'return ' if sig[0] != 'v' else '', sig, args) return ret From 6df94fe6a9733e590b6071bd222e3154d367a81a Mon Sep 17 00:00:00 2001 From: marco trivellato Date: Mon, 27 Mar 2017 11:39:58 +0100 Subject: [PATCH 3/7] fix STATICTOP so it does not overlap with tempDoublePtr --- emscripten.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emscripten.py b/emscripten.py index 2959cf36d8cfc..99e62145d7997 100755 --- a/emscripten.py +++ b/emscripten.py @@ -330,7 +330,7 @@ def function_tables_and_exports(funcs, metadata, mem_init, glue, forwarded_data, staticbump = metadata['staticBump'] while staticbump % 16 != 0: staticbump += 1 - pre = pre.replace('STATICTOP = STATIC_BASE + 0;', '''STATICTOP = STATIC_BASE + %d;%s + pre = pre.replace('STATICTOP = STATIC_BASE + 0;', '''STATICTOP = Runtime.alignMemory(STATIC_BASE, 16) + %d;%s /* global initializers */ %s __ATINIT__.push(%s); %s''' % (staticbump, 'assert(STATICTOP < SPLIT_MEMORY, "SPLIT_MEMORY size must be big enough so the entire static memory, need " + STATICTOP);' if settings['SPLIT_MEMORY'] else '', From dbf36cd977cec03d7c5ef8b3e1d36691cde12173 Mon Sep 17 00:00:00 2001 From: Marco Trivellato Date: Tue, 13 Jun 2017 08:09:57 +0100 Subject: [PATCH 4/7] fix UnicodeEncodeError when joining list of mixed types strings --- emcc.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/emcc.py b/emcc.py index a4a3b780dca4f..0d84507a07671 100755 --- a/emcc.py +++ b/emcc.py @@ -337,6 +337,15 @@ def uniquename(name): seen_names[name] = str(len(seen_names)) return unsuffixed(name) + '_' + seen_names[name] + (('.' + suffix(name)) if suffix(name) else '') + def asciify(strings_list): + res = '' + for s in strings_list: + if isinstance(s, unicode): + res += s.encode('ascii','ignore') + else: + res += s + return res + # ---------------- End configs ------------- if len(sys.argv) == 1 or sys.argv[1] in ['x', 't']: @@ -2131,7 +2140,7 @@ def do_minify(): # minifies the code. this is also when we do certain optimizati if emit_symbol_map or shared.Settings.CYBERDWARF: cmd += ['--symbolmap=' + target + '.symbols'] cmd += ['-o', wasm_binary_target] - logging.debug('asm2wasm (asm.js => WebAssembly): ' + ' '.join(cmd)) + logging.debug('asm2wasm (asm.js => WebAssembly): ' + ' '.join(asciify(cmd))) TimeLogger.update() subprocess.check_call(cmd) if import_mem_init: @@ -2142,11 +2151,11 @@ def do_minify(): # minifies the code. this is also when we do certain optimizati if shared.Settings.BINARYEN_PASSES: shutil.move(wasm_binary_target, wasm_binary_target + '.pre') cmd = [os.path.join(binaryen_bin, 'wasm-opt'), wasm_binary_target + '.pre', '-o', wasm_binary_target] + map(lambda p: '--' + p, shared.Settings.BINARYEN_PASSES.split(',')) - logging.debug('wasm-opt on BINARYEN_PASSES: ' + ' '.join(cmd)) + logging.debug('wasm-opt on BINARYEN_PASSES: ' + ' '.join(asciify(cmd))) subprocess.check_call(cmd) if 'interpret-s-expr' in shared.Settings.BINARYEN_METHOD: cmd = [os.path.join(binaryen_bin, 'wasm-dis'), wasm_binary_target, '-o', wasm_text_target] - logging.debug('wasm-dis (binary => text): ' + ' '.join(cmd)) + logging.debug('wasm-dis (binary => text): ' + ' '.join(asciify(cmd))) subprocess.check_call(cmd) if shared.Settings.BINARYEN_SCRIPTS: binaryen_scripts = os.path.join(shared.Settings.BINARYEN_ROOT, 'scripts') From 88b5a683868bd64513e7684fbc74ba896021aeea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Wed, 14 Jun 2017 17:48:47 +0300 Subject: [PATCH 5/7] If LLVM opt call fails, heuristically detect if it might have been due to passing natively compiled input files to Emscripten. #5305 --- tools/shared.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/shared.py b/tools/shared.py index 2e5381bf86ecb..2de8c12cfc451 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1633,8 +1633,16 @@ def llvm_opt(filename, opts, out=None): logging.debug('emcc: LLVM opts: ' + ' '.join(opts) + ' [num inputs: ' + str(len(inputs)) + ']') target = out or (filename + '.opt.bc') - output = Popen([LLVM_OPT] + inputs + opts + ['-o', target], stdout=PIPE).communicate()[0] - assert os.path.exists(target), 'Failed to run llvm optimizations: ' + output + proc = Popen([LLVM_OPT] + inputs + opts + ['-o', target], stdout=PIPE) + output = proc.communicate()[0] + if proc.returncode != 0 or not os.path.exists(target): + logging.error('Failed to run llvm optimizations: ' + output) + for i in inputs: + if not os.path.exists(i): + logging.warning('Note: Input file "' + i + '" did not exist.') + elif not Building.is_bitcode(i): + logging.warning('Note: Input file "' + i + '" exists but was not an LLVM bitcode file suitable for Emscripten. Perhaps accidentally mixing native built object files with Emscripten?') + sys.exit(1) if not out: shutil.move(filename + '.opt.bc', filename) return target From d0c69bdb35cf13f0e0fdba471b5f5a9ac9968fcf Mon Sep 17 00:00:00 2001 From: Marco Trivellato Date: Fri, 10 Nov 2017 09:38:15 +0000 Subject: [PATCH 6/7] add fallback to llvm_opt --- tools/shared.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/shared.py b/tools/shared.py index 2de8c12cfc451..75727035308ed 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1642,7 +1642,11 @@ def llvm_opt(filename, opts, out=None): logging.warning('Note: Input file "' + i + '" did not exist.') elif not Building.is_bitcode(i): logging.warning('Note: Input file "' + i + '" exists but was not an LLVM bitcode file suitable for Emscripten. Perhaps accidentally mixing native built object files with Emscripten?') - sys.exit(1) + if len(inputs) == 1 and os.path.exists(filename): + logging.warning('llvm_opt fallback: copy %s to %s', filename, target) + shutil.copyfile(filename, target) + else: + sys.exit(1) if not out: shutil.move(filename + '.opt.bc', filename) return target From 151e82050f4a223c659a61826701c8f94270de0f Mon Sep 17 00:00:00 2001 From: marco trivellato Date: Thu, 16 Nov 2017 15:55:48 +0000 Subject: [PATCH 7/7] Revert "add fallback to llvm_opt" This reverts commit d0c69bdb35cf13f0e0fdba471b5f5a9ac9968fcf. --- tools/shared.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/shared.py b/tools/shared.py index 75727035308ed..2de8c12cfc451 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1642,11 +1642,7 @@ def llvm_opt(filename, opts, out=None): logging.warning('Note: Input file "' + i + '" did not exist.') elif not Building.is_bitcode(i): logging.warning('Note: Input file "' + i + '" exists but was not an LLVM bitcode file suitable for Emscripten. Perhaps accidentally mixing native built object files with Emscripten?') - if len(inputs) == 1 and os.path.exists(filename): - logging.warning('llvm_opt fallback: copy %s to %s', filename, target) - shutil.copyfile(filename, target) - else: - sys.exit(1) + sys.exit(1) if not out: shutil.move(filename + '.opt.bc', filename) return target