aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemcc2
-rw-r--r--src/settings.js10
-rw-r--r--tests/runner.py5
-rw-r--r--tools/shared.py4
4 files changed, 18 insertions, 3 deletions
diff --git a/emcc b/emcc
index 2ad6248c..97ced96e 100755
--- a/emcc
+++ b/emcc
@@ -514,7 +514,7 @@ try:
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), LLVM_INTERNAL_OPT_LEVEL, safe=llvm_opt_level < 2)
else:
# If possible, remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
- if not LEAVE_INPUTS_RAW and not shared.Settings.BUILD_AS_SHARED_LIB:
+ if not LEAVE_INPUTS_RAW and not shared.Settings.BUILD_AS_SHARED_LIB and not shared.Settings.LINKABLE:
if DEBUG: print >> sys.stderr, 'emcc: LLVM dead globals elimination'
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), ['-internalize', '-globaldce'])
diff --git a/src/settings.js b/src/settings.js
index 1d62cbbf..7e900ea9 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -194,6 +194,16 @@ var RUNTIME_LINKED_LIBS = []; // If this is a main file (BUILD_AS_SHARED_LIB ==
// BUILD_AS_SHARED_LIB == 2.
// NOTE: LLVM optimizations run separately on the main file and
// linked libraries can break things.
+var LINKABLE = 0; // If set to 1, this file can be linked with others, either as a shared
+ // library or as the main file that calls a shared library. To enable that,
+ // we will not internalize all symbols and cull the unused ones, in other
+ // words, we will not remove unused functions and globals, which might be
+ // used by another module we are linked with.
+ // BUILD_AS_SHARED_LIB > 0 implies this, so it is only importand to set this to 1
+ // when building the main file, and *if* that main file has symbols that
+ // the library it will open will then access through an extern.
+ // LINKABLE of 0 is very useful in that we can reduce the size of the
+ // generated code very significantly, by removing everything not actually used.
var RUNTIME_TYPE_INFO = 0; // Whether to expose type info to the script at run time. This
// increases the size of the generated script, but allows you
diff --git a/tests/runner.py b/tests/runner.py
index 30f5f62c..eb940000 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2488,6 +2488,9 @@ def process(filename):
def test_runtimelink(self):
if Building.LLVM_OPTS: return self.skip('LLVM opts will optimize printf into puts in the parent, and the child will still look for puts')
+
+ Settings.LINKABLE = 1
+
self.banned_js_engines = [NODE_JS] # node's global scope behaves differently than everything else, needs investigation FIXME
header = r'''
@@ -2689,6 +2692,8 @@ def process(filename):
def test_dlfcn_data_and_fptr(self):
if Building.LLVM_OPTS: return self.skip('LLVM opts will optimize out parent_func')
+ Settings.LINKABLE = 1
+
lib_src = '''
#include <stdio.h>
diff --git a/tools/shared.py b/tools/shared.py
index 718edc75..41221c67 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -560,7 +560,7 @@ class Building:
opts.append('-tbaa')
opts.append('-basicaa') # makes fannkuch slow but primes fast
- if not Settings.BUILD_AS_SHARED_LIB:
+ if not Settings.BUILD_AS_SHARED_LIB and not Settings.LINKABLE:
opts.append('-internalize')
opts.append('-globalopt')
@@ -620,7 +620,7 @@ class Building:
opts.append('-strip-dead-prototypes')
- if not Settings.BUILD_AS_SHARED_LIB:
+ if not Settings.BUILD_AS_SHARED_LIB and not Settings.LINKABLE:
opts.append('-globaldce')
if optimization_level > 1: opts.append('-constmerge')