Skip to content

Avoid setting EXPORTED_FUNCTIONS with MAIN_MODULE=1 #15257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 20 additions & 36 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2720,8 +2720,7 @@ class Bar {

@needs_dylink
def test_dlfcn_qsort(self):
self.set_setting('EXPORTED_FUNCTIONS', ['_get_cmp'])
create_file('liblib.cpp', '''
create_file('liblib.c', '''
int lib_cmp(const void* left, const void* right) {
const int* a = (const int*) left;
const int* b = (const int*) right;
Expand All @@ -2732,14 +2731,13 @@ def test_dlfcn_qsort(self):

typedef int (*CMP_TYPE)(const void*, const void*);

extern "C" CMP_TYPE get_cmp() {
CMP_TYPE get_cmp() {
return lib_cmp;
}
''')
self.build_dlfcn_lib('liblib.cpp')
self.build_dlfcn_lib('liblib.c')

self.prep_dlfcn_main()
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc'])
src = '''
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -2798,7 +2796,7 @@ def test_dlfcn_data_and_fptr(self):
if self.is_wasm():
self.banned_js_engines = [config.V8_ENGINE]

create_file('liblib.cpp', r'''
create_file('liblib.c', r'''
#include <stdio.h>

int theglobal = 42;
Expand All @@ -2818,14 +2816,13 @@ def test_dlfcn_data_and_fptr(self):
p_f();
}

extern "C" void (*func(int x, void(*fptr)()))() {
void (*func(int x, void(*fptr)()))() {
printf("In func: %d\n", x);
fptr();
return lib_fptr;
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_func'])
self.build_dlfcn_lib('liblib.cpp')
self.build_dlfcn_lib('liblib.c')

self.prep_dlfcn_main()
src = r'''
Expand Down Expand Up @@ -2881,29 +2878,27 @@ def test_dlfcn_data_and_fptr(self):
return 0;
}
'''
self.set_setting('EXPORTED_FUNCTIONS', ['_main'])
self.do_run(src, '''\
In func: 13
First calling main_fptr from lib.
Second calling lib_fptr from main.
parent_func called from child
parent_func called from child
Var: 42
''')
''', force_c=True)

@needs_dylink
def test_dlfcn_varargs(self):
# this test is not actually valid - it fails natively. the child should fail
# to be loaded, not load and successfully see the parent print_ints func

create_file('liblib.cpp', r'''
create_file('liblib.c', r'''
void print_ints(int n, ...);
extern "C" void func() {
void func() {
print_ints(2, 13, 42);
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_func'])
self.build_dlfcn_lib('liblib.cpp')
self.build_dlfcn_lib('liblib.c')

self.prep_dlfcn_main()
src = r'''
Expand Down Expand Up @@ -2935,8 +2930,7 @@ def test_dlfcn_varargs(self):
return 0;
}
'''
self.set_setting('EXPORTED_FUNCTIONS', ['_main'])
self.do_run(src, '100\n200\n13\n42\n')
self.do_run(src, '100\n200\n13\n42\n', force_c=True)

@needs_dylink
def test_dlfcn_alignment_and_zeroing(self):
Expand Down Expand Up @@ -3038,7 +3032,6 @@ def test_dlfcn_unique_sig(self):
return 13;
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc'])
self.build_dlfcn_lib('liblib.c')

self.prep_dlfcn_main()
Expand All @@ -3065,7 +3058,6 @@ def test_dlfcn_unique_sig(self):
return 0;
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc'])
self.do_runf('main.c', 'success')

@needs_dylink
Expand All @@ -3077,7 +3069,6 @@ def test_dlfcn_info(self):
return 13;
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc'])
self.build_dlfcn_lib('liblib.c')

self.prep_dlfcn_main()
Expand Down Expand Up @@ -3119,7 +3110,6 @@ def test_dlfcn_info(self):
return 0;
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc'])
self.do_runf('main.c', 'success')

@needs_dylink
Expand All @@ -3139,7 +3129,6 @@ def test_dlfcn_stacks(self):
return strlen(bigstack);
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc'])
self.build_dlfcn_lib('liblib.c')

self.prep_dlfcn_main()
Expand Down Expand Up @@ -3174,7 +3163,6 @@ def test_dlfcn_stacks(self):
return 0;
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_strcmp'])
self.do_runf('main.c', 'success')

@needs_dylink
Expand Down Expand Up @@ -3210,7 +3198,6 @@ def test_dlfcn_funcs(self):
}
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_callvoid', '_callint', '_getvoid', '_getint'])
self.build_dlfcn_lib('liblib.c')

self.prep_dlfcn_main()
Expand Down Expand Up @@ -3261,7 +3248,6 @@ def test_dlfcn_funcs(self):
return 0;
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc'])
self.do_runf('main.c', '''go
void_main.
int_main 201
Expand All @@ -3286,11 +3272,9 @@ def test_dlfcn_mallocs(self):
void *mallocproxy(int n) { return malloc(n); }
void freeproxy(void *p) { free(p); }
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_mallocproxy', '_freeproxy'])
self.build_dlfcn_lib('liblib.c')

self.prep_dlfcn_main()
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free'])
self.do_runf(test_file('dlmalloc_proxy.c'), '*294,153*')

@needs_dylink
Expand Down Expand Up @@ -3338,7 +3322,6 @@ def test_dlfcn_longjmp(self):
return 0;
}
''')
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free'])
self.do_runf('main.c', '''go!
pre 1
pre 2
Expand Down Expand Up @@ -3410,7 +3393,6 @@ def zzztest_dlfcn_exceptions(self):
return 0;
}
'''
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free'])
self.do_run(src, '''go!
ok: 65
int 123
Expand All @@ -3428,8 +3410,9 @@ def indir(name):
create_file('a.cpp', r'''
#include <stdio.h>

static struct a {
a() {
static class A {
public:
A() {
puts("a: loaded");
}
} _;
Expand All @@ -3438,8 +3421,9 @@ def indir(name):
create_file('b.cpp', r'''
#include <stdio.h>

static struct b {
b() {
static class B {
public:
B() {
puts("b: loaded");
}
} _;
Expand Down Expand Up @@ -3488,12 +3472,12 @@ def indir(name):
def test_dlfcn_feature_in_lib(self):
self.emcc_args.append('-mnontrapping-fptoint')

create_file('liblib.cpp', r'''
extern "C" int magic(float x) {
create_file('liblib.c', r'''
int magic(float x) {
return __builtin_wasm_trunc_saturate_s_i32_f32(x);
}
''')
self.build_dlfcn_lib('liblib.cpp')
self.build_dlfcn_lib('liblib.c')

self.prep_dlfcn_main()
src = r'''
Expand Down