Skip to content

Commit 4615da6

Browse files
committed
Don't allow EXPORTED_FUNCTIONS with MAIN_MODULE=1/SIDE_MODULE=1
This doesn't make sense since these imply all functionm are to be exported.
1 parent 5dba39c commit 4615da6

File tree

3 files changed

+16
-32
lines changed

3 files changed

+16
-32
lines changed

emcc.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,17 +1158,23 @@ def check(input_file):
11581158
options.memory_init_file = False # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen)
11591159

11601160
if shared.Settings.MAIN_MODULE or shared.Settings.SIDE_MODULE:
1161-
assert shared.Settings.ASM_JS, 'module linking requires asm.js output (-s ASM_JS=1)'
1161+
if not shared.Settings.ASM_JS:
1162+
exit_with_error('module linking requires asm.js output (-s ASM_JS=1)')
11621163
if shared.Settings.MAIN_MODULE != 2 and shared.Settings.SIDE_MODULE != 2:
11631164
shared.Settings.LINKABLE = 1
11641165
shared.Settings.RELOCATABLE = 1
1165-
assert not options.use_closure_compiler, 'cannot use closure compiler on shared modules'
1166+
if options.use_closure_compiler:
1167+
exit_with_error('cannot use closure compiler on shared modules')
11661168
# shared modules need memory utilities to allocate their memory
11671169
shared.Settings.EXPORTED_RUNTIME_METHODS += [
11681170
'allocate',
11691171
'getMemory',
11701172
]
11711173

1174+
if shared.Settings.LINKABLE and shared.Settings.USER_EXPORTED_FUNCTIONS:
1175+
shared.warning('EXPORTED_FUNCTIONS is not valid with LINKABLE set (normally due to SIDE_MODULE=1/MAIN_MODULE=1) '
1176+
'since all functions are exported. To export only a subset use SIDE_MODULE=2/MAIN_MODULE=2')
1177+
11721178
if shared.Settings.RELOCATABLE:
11731179
shared.Settings.ALLOW_TABLE_GROWTH = 1
11741180

tests/test_core.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,6 @@ class Bar {
26322632
@needs_dlfcn
26332633
def test_dlfcn_i64(self):
26342634
self.prep_dlfcn_lib()
2635-
self.set_setting('EXPORTED_FUNCTIONS', ['_foo'])
26362635
lib_src = '''
26372636
int foo(int x) {
26382637
return (long long)x / (long long)1234;
@@ -2643,7 +2642,6 @@ def test_dlfcn_i64(self):
26432642
self.build_dlfcn_lib(lib_src, dirname, filename)
26442643

26452644
self.prep_dlfcn_main()
2646-
self.clear_setting('EXPORTED_FUNCTIONS')
26472645
src = r'''
26482646
#include <stdio.h>
26492647
#include <stdlib.h>
@@ -2713,7 +2711,6 @@ class Bar {
27132711
@needs_dlfcn
27142712
def test_dlfcn_qsort(self):
27152713
self.prep_dlfcn_lib()
2716-
self.set_setting('EXPORTED_FUNCTIONS', ['_get_cmp'])
27172714
lib_src = '''
27182715
int lib_cmp(const void* left, const void* right) {
27192716
const int* a = (const int*) left;
@@ -2734,7 +2731,6 @@ def test_dlfcn_qsort(self):
27342731
self.build_dlfcn_lib(lib_src, dirname, filename)
27352732

27362733
self.prep_dlfcn_main()
2737-
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc'])
27382734
src = '''
27392735
#include <stdio.h>
27402736
#include <stdlib.h>
@@ -2827,7 +2823,6 @@ def test_dlfcn_data_and_fptr(self):
28272823
'''
28282824
dirname = self.get_dir()
28292825
filename = os.path.join(dirname, 'liblib.cpp')
2830-
self.set_setting('EXPORTED_FUNCTIONS', ['_func'])
28312826
self.build_dlfcn_lib(lib_src, dirname, filename)
28322827

28332828
self.prep_dlfcn_main()
@@ -2884,7 +2879,6 @@ def test_dlfcn_data_and_fptr(self):
28842879
return 0;
28852880
}
28862881
'''
2887-
self.set_setting('EXPORTED_FUNCTIONS', ['_main'])
28882882
self.do_run(src, '''\
28892883
In func: 13
28902884
First calling main_fptr from lib.
@@ -2908,7 +2902,6 @@ def test_dlfcn_varargs(self):
29082902
'''
29092903
dirname = self.get_dir()
29102904
filename = os.path.join(dirname, 'liblib.cpp')
2911-
self.set_setting('EXPORTED_FUNCTIONS', ['_func'])
29122905
self.build_dlfcn_lib(lib_src, dirname, filename)
29132906

29142907
self.prep_dlfcn_main()
@@ -2941,7 +2934,6 @@ def test_dlfcn_varargs(self):
29412934
return 0;
29422935
}
29432936
'''
2944-
self.set_setting('EXPORTED_FUNCTIONS', ['_main'])
29452937
self.do_run(src, '100\n200\n13\n42\n')
29462938

29472939
@needs_dlfcn
@@ -3057,7 +3049,6 @@ def test_dlfcn_unique_sig(self):
30573049
return 13;
30583050
}
30593051
'''
3060-
self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc'])
30613052
dirname = self.get_dir()
30623053
filename = os.path.join(dirname, 'liblib.c')
30633054
self.build_dlfcn_lib(lib_src, dirname, filename)
@@ -3086,7 +3077,6 @@ def test_dlfcn_unique_sig(self):
30863077
return 0;
30873078
}
30883079
'''
3089-
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc'])
30903080
self.do_run(src, 'success', force_c=True)
30913081

30923082
@needs_dlfcn
@@ -3100,7 +3090,6 @@ def test_dlfcn_info(self):
31003090
return 13;
31013091
}
31023092
'''
3103-
self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc'])
31043093
dirname = self.get_dir()
31053094
filename = os.path.join(dirname, 'liblib.c')
31063095
self.build_dlfcn_lib(lib_src, dirname, filename)
@@ -3144,7 +3133,6 @@ def test_dlfcn_info(self):
31443133
return 0;
31453134
}
31463135
'''
3147-
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc'])
31483136
self.do_run(src, 'success', force_c=True)
31493137

31503138
@needs_dlfcn
@@ -3165,7 +3153,6 @@ def test_dlfcn_stacks(self):
31653153
return strlen(bigstack);
31663154
}
31673155
'''
3168-
self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc'])
31693156
dirname = self.get_dir()
31703157
filename = os.path.join(dirname, 'liblib.c')
31713158
self.build_dlfcn_lib(lib_src, dirname, filename)
@@ -3202,7 +3189,6 @@ def test_dlfcn_stacks(self):
32023189
return 0;
32033190
}
32043191
'''
3205-
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_strcmp'])
32063192
self.do_run(src, 'success', force_c=True)
32073193

32083194
@needs_dlfcn
@@ -3239,7 +3225,6 @@ def test_dlfcn_funcs(self):
32393225
}
32403226
}
32413227
'''
3242-
self.set_setting('EXPORTED_FUNCTIONS', ['_callvoid', '_callint', '_getvoid', '_getint'])
32433228
dirname = self.get_dir()
32443229
self.build_dlfcn_lib(lib_src, dirname, os.path.join(dirname, 'liblib.c'))
32453230

@@ -3291,7 +3276,6 @@ def test_dlfcn_funcs(self):
32913276
return 0;
32923277
}
32933278
'''
3294-
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc'])
32953279
self.do_run(src, '''go
32963280
void_main.
32973281
int_main 201
@@ -3317,14 +3301,12 @@ def test_dlfcn_mallocs(self):
33173301
void *mallocproxy(int n) { return malloc(n); }
33183302
void freeproxy(void *p) { free(p); }
33193303
'''
3320-
self.set_setting('EXPORTED_FUNCTIONS', ['_mallocproxy', '_freeproxy'])
33213304
dirname = self.get_dir()
33223305
filename = os.path.join(dirname, 'liblib.c')
33233306
self.build_dlfcn_lib(lib_src, dirname, filename)
33243307

33253308
self.prep_dlfcn_main()
33263309
src = open(path_from_root('tests', 'dlmalloc_proxy.c')).read()
3327-
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free'])
33283310
self.do_run(src, '''*294,153*''', force_c=True)
33293311

33303312
@needs_dlfcn
@@ -3341,7 +3323,6 @@ def test_dlfcn_longjmp(self):
33413323
printf("pre %d\n", i);
33423324
}
33433325
'''
3344-
self.set_setting('EXPORTED_FUNCTIONS', ['_jumpy'])
33453326
dirname = self.get_dir()
33463327
filename = os.path.join(dirname, 'liblib.c')
33473328
self.build_dlfcn_lib(lib_src, dirname, filename)
@@ -3376,7 +3357,6 @@ def test_dlfcn_longjmp(self):
33763357
return 0;
33773358
}
33783359
'''
3379-
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free'])
33803360
self.do_run(src, '''go!
33813361
pre 1
33823362
pre 2
@@ -3405,7 +3385,6 @@ def zzztest_dlfcn_exceptions(self): # TODO: make this work. need to forward temp
34053385
}
34063386
}
34073387
'''
3408-
self.set_setting('EXPORTED_FUNCTIONS', ['_ok', '_fail'])
34093388
dirname = self.get_dir()
34103389
filename = os.path.join(dirname, 'liblib.cpp')
34113390
self.build_dlfcn_lib(lib_src, dirname, filename)
@@ -3450,7 +3429,6 @@ def zzztest_dlfcn_exceptions(self): # TODO: make this work. need to forward temp
34503429
return 0;
34513430
}
34523431
'''
3453-
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free'])
34543432
self.do_run(src, '''go!
34553433
ok: 65
34563434
int 123
@@ -4104,7 +4082,7 @@ def test_dylink_global_var_jslib(self):
41044082
void call_side() {
41054083
printf("side: jslib_x is %d.\n", jslib_x);
41064084
}
4107-
''', expected=['main: jslib_x is 148.\nside: jslib_x is 148.\n'], main_emcc_args=['--js-library', 'lib.js', '-s', 'EXPORTED_FUNCTIONS=["_main", "_jslib_x"]'])
4085+
''', expected=['main: jslib_x is 148.\nside: jslib_x is 148.\n'], main_emcc_args=['--js-library', 'lib.js'])
41084086

41094087
@needs_dlfcn
41104088
def test_dylink_many_postsets(self):

tools/shared.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,15 +1929,15 @@ def link_lld(args, target, opts=[], lto_level=0):
19291929

19301930
if Settings.LINKABLE:
19311931
cmd.append('--export-all')
1932+
else:
1933+
# in standalone mode, crt1 will call the constructors from inside the wasm
1934+
if not Settings.STANDALONE_WASM:
1935+
cmd += ['--export', '__wasm_call_ctors']
19321936

1933-
# in standalone mode, crt1 will call the constructors from inside the wasm
1934-
if not Settings.STANDALONE_WASM:
1935-
cmd += ['--export', '__wasm_call_ctors']
1936-
1937-
cmd += ['--export', '__data_end']
1937+
cmd += ['--export', '__data_end']
19381938

1939-
for export in Settings.EXPORTED_FUNCTIONS:
1940-
cmd += ['--export', export[1:]] # Strip the leading underscore
1939+
for export in Settings.EXPORTED_FUNCTIONS:
1940+
cmd += ['--export', export[1:]] # Strip the leading underscore
19411941

19421942
if Settings.RELOCATABLE:
19431943
if Settings.SIDE_MODULE:

0 commit comments

Comments
 (0)