aboutsummaryrefslogtreecommitdiff
path: root/emcc
diff options
context:
space:
mode:
Diffstat (limited to 'emcc')
-rwxr-xr-xemcc96
1 files changed, 66 insertions, 30 deletions
diff --git a/emcc b/emcc
index 6f38b32b..0e7fc1ea 100755
--- a/emcc
+++ b/emcc
@@ -1,4 +1,5 @@
#!/usr/bin/env python2
+# -*- Mode: python -*-
'''
emcc - compiler helper script
@@ -90,7 +91,10 @@ LLVM_OPT_LEVEL = {
3: 3,
}
-DEBUG = int(os.environ.get('EMCC_DEBUG') or 0)
+DEBUG = os.environ.get('EMCC_DEBUG')
+if DEBUG == "0":
+ DEBUG = None
+
TEMP_DIR = os.environ.get('EMCC_TEMP_DIR')
LEAVE_INPUTS_RAW = os.environ.get('EMCC_LEAVE_INPUTS_RAW') # Do not compile .ll files into .bc, just compile them with emscripten directly
# Not recommended, this is mainly for the test runner, or if you have some other
@@ -118,6 +122,28 @@ if len(sys.argv) == 1:
print 'emcc: no input files'
exit(1)
+# read response files very early on
+response_file = True
+while response_file:
+ response_file = None
+ for index in range(1, len(sys.argv)):
+ if sys.argv[index][0] == '@':
+ # found one, loop again next time
+ print >>sys.stderr, 'emcc: using response file: %s' % response_file
+ response_file = sys.argv[index][1:]
+ if not os.path.exists(response_file):
+ print >>sys.stderr, 'emcc: error: Response file not found: %s' % response_file
+ exit(1)
+
+ response_fd = open(response_file, 'r')
+ extra_args = shlex.split(response_fd.read())
+ response_fd.close()
+
+ # slice in extra_args in place of the response file arg
+ sys.argv[index:index+1] = extra_args
+ #if DEBUG: print >>sys.stderr, "Expanded response file: " + " | ".join(sys.argv)
+ break
+
if sys.argv[1] == '--version':
revision = '(unknown revision)'
here = os.getcwd()
@@ -629,7 +655,8 @@ try:
ignore_dynamic_linking = False
shell_path = shared.path_from_root('src', 'shell.html')
js_libraries = []
- keep_debug = False
+ keep_llvm_debug = False
+ keep_js_debug = False
bind = False
jcache = False
if use_cxx:
@@ -645,7 +672,8 @@ try:
for i in range(len(newargs)):
newargs[i] = newargs[i].strip() # On Windows Vista (and possibly others), excessive spaces in the command line leak into the items in this array, so trim e.g. 'foo.cpp ' -> 'foo.cpp'
if newargs[i].startswith('-O'):
- requested_level = newargs[i][2]
+ # Let -O default to -O2, which is what gcc does.
+ requested_level = newargs[i][2:] or '2'
if requested_level == 's':
print >> sys.stderr, 'emcc: warning: -Os is ignored (use -O0, -O1, -O2)'
else:
@@ -696,7 +724,8 @@ try:
newargs[i] = ''
newargs[i+1] = ''
elif newargs[i] == '-g':
- keep_debug = True
+ keep_llvm_debug = True
+ keep_js_debug = True
elif newargs[i] == '--bind':
bind = True
newargs[i] = ''
@@ -767,7 +796,8 @@ try:
if llvm_opts is None: llvm_opts = LLVM_OPT_LEVEL[opt_level]
if llvm_lto is None: llvm_lto = llvm_opts > 0
- if opt_level <= 0: keep_debug = True # always keep debug in -O0
+ if opt_level <= 0: keep_llvm_debug = keep_js_debug = True # always keep debug in -O0
+ if opt_level > 0: keep_llvm_debug = False # JS optimizer wipes out llvm debug info from being visible
if closure is None and opt_level == 3: closure = True
if DEBUG: start_time = time.time() # done after parsing arguments, which might affect debug state
@@ -908,9 +938,9 @@ try:
shared.Settings.CORRECT_OVERFLOWS = 1
if shared.Settings.CORRECT_SIGNS >= 2 or shared.Settings.CORRECT_OVERFLOWS >= 2 or shared.Settings.CORRECT_ROUNDINGS >= 2:
- keep_debug = True # must keep debug info to do line-by-line operations
+ keep_llvm_debug = True # must keep debug info to do line-by-line operations
- if keep_debug and closure:
+ if (keep_llvm_debug or keep_js_debug) and closure:
print >> sys.stderr, 'emcc: warning: disabling closure because debug info was requested'
closure = False
@@ -1017,7 +1047,7 @@ try:
def create_libcxx():
if DEBUG: print >> sys.stderr, 'emcc: building libcxx for cache'
os = []
- for src in ['algorithm.cpp', 'condition_variable.cpp', 'future.cpp', 'iostream.cpp', 'memory.cpp', 'random.cpp', 'stdexcept.cpp', 'system_error.cpp', 'utility.cpp', 'bind.cpp', 'debug.cpp', 'hash.cpp', 'mutex.cpp', 'string.cpp', 'thread.cpp', 'valarray.cpp', 'chrono.cpp', 'exception.cpp', 'ios.cpp', 'locale.cpp', 'regex.cpp', 'strstream.cpp', 'typeinfo.cpp']:
+ for src in ['algorithm.cpp', 'condition_variable.cpp', 'future.cpp', 'iostream.cpp', 'memory.cpp', 'random.cpp', 'stdexcept.cpp', 'system_error.cpp', 'utility.cpp', 'bind.cpp', 'debug.cpp', 'hash.cpp', 'mutex.cpp', 'string.cpp', 'thread.cpp', 'valarray.cpp', 'chrono.cpp', 'exception.cpp', 'ios.cpp', 'locale.cpp', 'regex.cpp', 'strstream.cpp']:
o = in_temp(src + '.o')
execute([shared.PYTHON, shared.EMXX, shared.path_from_root('system', 'lib', 'libcxx', src), '-o', o], stdout=stdout, stderr=stderr)
os.append(o)
@@ -1036,7 +1066,7 @@ try:
def create_libcxxabi():
if DEBUG: print >> sys.stderr, 'emcc: building libcxxabi for cache'
os = []
- for src in ['private_typeinfo.cpp']:
+ for src in ['private_typeinfo.cpp', 'typeinfo.cpp']:
o = in_temp(src + '.o')
execute([shared.PYTHON, shared.EMXX, shared.path_from_root('system', 'lib', 'libcxxabi', 'src', src), '-o', o], stdout=stdout, stderr=stderr)
os.append(o)
@@ -1050,29 +1080,32 @@ try:
libcxxabi_symbols = filter(lambda symbol: symbol not in libc_symbols, libcxxabi_symbols)
libcxxabi_symbols = set(libcxxabi_symbols)
- force = False # If we have libcxx, we must force inclusion of libc, since libcxx uses new internally. Note: this is kind of hacky
-
+ # If we have libcxx, we must force inclusion of libc, since libcxx uses new internally. Note: this is kind of hacky
+ # Settings this in the environment will avoid checking dependencies and make building big projects a little faster
+ force = os.environ.get('EMCC_FORCE_STDLIBS')
+ has = need = None
for name, create, fix, library_symbols in [('libcxx', create_libcxx, fix_libcxx, libcxx_symbols),
('libcxxabi', create_libcxxabi, fix_libcxxabi, libcxxabi_symbols),
('libc', create_libc, fix_libc, libc_symbols)]:
- need = set()
- has = set()
- for temp_file in temp_files:
- symbols = shared.Building.llvm_nm(temp_file)
- for library_symbol in library_symbols:
- if library_symbol in symbols.undefs:
- need.add(library_symbol)
- if library_symbol in symbols.defs:
- has.add(library_symbol)
- for haz in has: # remove symbols that are supplied by another of the inputs
- if haz in need:
- need.remove(haz)
- if DEBUG: print >> sys.stderr, 'emcc: considering including %s: we need %s and have %s' % (name, str(need), str(has))
+ if not force:
+ need = set()
+ has = set()
+ for temp_file in temp_files:
+ symbols = shared.Building.llvm_nm(temp_file)
+ for library_symbol in library_symbols:
+ if library_symbol in symbols.undefs:
+ need.add(library_symbol)
+ if library_symbol in symbols.defs:
+ has.add(library_symbol)
+ for haz in has: # remove symbols that are supplied by another of the inputs
+ if haz in need:
+ need.remove(haz)
+ if DEBUG: print >> sys.stderr, 'emcc: considering including %s: we need %s and have %s' % (name, str(need), str(has))
if force or len(need) > 0:
# We need to build and link the library in
if DEBUG: print >> sys.stderr, 'emcc: including %s' % name
libfile = shared.Cache.get(name, create)
- if len(has) > 0:
+ if has and len(has) > 0:
# remove the symbols we do not need
fixed = in_temp(uniquename(libfile)) + '.bc'
shutil.copyfile(libfile, fixed)
@@ -1082,7 +1115,7 @@ try:
libfile = fixed
extra_files_to_link.append(libfile)
force = True
- if fix:
+ 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
@@ -1090,7 +1123,10 @@ try:
(not LEAVE_INPUTS_RAW and not (suffix(temp_files[0]) in BITCODE_SUFFIXES or suffix(temp_files[0]) in DYNAMICLIB_SUFFIXES) and shared.Building.is_ar(temp_files[0])):
linker_inputs = temp_files + extra_files_to_link
if DEBUG: print >> sys.stderr, 'emcc: linking: ', linker_inputs
+ t0 = time.time()
shared.Building.link(linker_inputs, in_temp(target_basename + '.bc'))
+ t1 = time.time()
+ if DEBUG: print >> sys.stderr, 'emcc: linking took %.2f seconds' % (t1 - t0)
final = in_temp(target_basename + '.bc')
else:
if not LEAVE_INPUTS_RAW:
@@ -1117,7 +1153,7 @@ try:
# Optimize, if asked to
if not LEAVE_INPUTS_RAW:
- link_opts = [] if keep_debug and opt_level == 0 else ['-strip-debug'] # remove LLVM debug info in -O1+, since the optimizer removes it anyhow
+ link_opts = [] if keep_llvm_debug else ['-strip-debug'] # remove LLVM debug info in -O1+, since the optimizer removes it anyhow
if llvm_opts > 0:
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), llvm_opts)
if DEBUG: save_intermediate('opt', 'bc')
@@ -1208,7 +1244,7 @@ try:
def flush_js_optimizer_queue():
global final, js_optimizer_queue
if len(js_optimizer_queue) > 0 and not(len(js_optimizer_queue) == 1 and js_optimizer_queue[0] == 'last'):
- if DEBUG < 2:
+ if DEBUG != '2':
if shared.Settings.ASM_JS:
js_optimizer_queue = ['asm'] + js_optimizer_queue
if DEBUG: print >> sys.stderr, 'emcc: applying js optimization passes:', js_optimizer_queue
@@ -1227,7 +1263,7 @@ try:
if opt_level >= 1:
if DEBUG: print >> sys.stderr, 'emcc: running pre-closure post-opts'
- if DEBUG >= 2:
+ if DEBUG == '2':
# Clean up the syntax a bit
final = shared.Building.js_optimizer(final, [], jcache)
if DEBUG: save_intermediate('pretty')
@@ -1249,7 +1285,7 @@ try:
if DEBUG: print >> sys.stderr, 'emcc: running closure'
final = shared.Building.closure_compiler(final)
if DEBUG: save_intermediate('closure')
- elif shared.Settings.RELOOP and not closure and not keep_debug:
+ elif shared.Settings.RELOOP and not closure 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']