Skip to content

Commit 7f1fdbe

Browse files
committed
be careful with internalize in llvm LTO, and mark needed symbols for relooper
1 parent 34b1532 commit 7f1fdbe

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

emcc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,17 +1055,19 @@ try:
10551055
if DEBUG: save_intermediate('opt', 'bc')
10561056
# Do LTO in a separate pass to work around LLVM bug XXX (see failure e.g. in cubescript)
10571057
if shared.Building.can_build_standalone():
1058-
if llvm_lto and shared.Building.can_use_unsafe_opts():
1059-
if not shared.Building.can_inline(): link_opts.append('-disable-inlining')
1060-
link_opts.append('-std-link-opts')
1061-
else:
1062-
# At least remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
1063-
exports = ','.join(map(lambda exp: exp[1:], shared.Settings.EXPORTED_FUNCTIONS))
1064-
link_opts += ['-internalize', '-internalize-public-api-list=' + exports, '-globaldce']
1065-
if link_opts:
1058+
# At minimum remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
1059+
exports = ','.join(map(lambda exp: exp[1:], shared.Settings.EXPORTED_FUNCTIONS))
1060+
# internalize carefully, llvm 3.2 will remove even main if not told not to
1061+
link_opts += ['-internalize', '-internalize-public-api-list=' + exports, '-globaldce']
10661062
if DEBUG: print >> sys.stderr, 'emcc: LLVM linktime:', link_opts
10671063
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), link_opts)
1068-
if DEBUG: save_intermediate('linktime', 'bc')
1064+
if DEBUG: save_intermediate('dce', 'bc')
1065+
if llvm_lto and shared.Building.can_use_unsafe_opts():
1066+
if not shared.Building.can_inline(): link_opts.append('-disable-inlining')
1067+
link_opts = ['-std-link-opts', '-disable-internalize']
1068+
if DEBUG: print >> sys.stderr, 'emcc: LLVM linktime:', link_opts
1069+
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), link_opts)
1070+
if DEBUG: save_intermediate('linktime', 'bc')
10691071

10701072
# Prepare .ll for Emscripten
10711073
if not LEAVE_INPUTS_RAW:

tools/shared.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,12 @@ def ensure_relooper():
11161116

11171117
def make(opt_level):
11181118
raw = RELOOPER + '.raw.js'
1119-
Building.emcc(os.path.join('relooper', 'Relooper.cpp'), ['-I' + os.path.join('relooper'), '--post-js', os.path.join('relooper', 'emscripten', 'glue.js'), '-s', 'TOTAL_MEMORY=52428800', '-s', 'DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=["memcpy", "memset", "malloc", "free", "puts"]', '-O' + str(opt_level), '--closure', '0'], raw)
1119+
Building.emcc(os.path.join('relooper', 'Relooper.cpp'), ['-I' + os.path.join('relooper'), '--post-js',
1120+
os.path.join('relooper', 'emscripten', 'glue.js'),
1121+
'-s', 'TOTAL_MEMORY=52428800',
1122+
'-s', 'EXPORTED_FUNCTIONS=["_rl_set_output_buffer","_rl_make_output_buffer","_rl_new_block","_rl_delete_block","_rl_block_add_branch_to","_rl_new_relooper","_rl_delete_relooper","_rl_relooper_add_block","_rl_relooper_calculate","_rl_relooper_render"]',
1123+
'-s', 'DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=["memcpy", "memset", "malloc", "free", "puts"]',
1124+
'-O' + str(opt_level), '--closure', '0'], raw)
11201125
f = open(RELOOPER, 'w')
11211126
f.write("// Relooper, (C) 2012 Alon Zakai, MIT license, https://github.com/kripken/Relooper\n")
11221127
f.write("var Relooper = (function() {\n");

0 commit comments

Comments
 (0)