Skip to content

Make main symbol optional even in STANDALONE_WASM mode #9641

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 2 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion system/lib/libc/crt1.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@
#include <stdio.h>

extern void __wasm_call_ctors(void) __attribute__((weak));
extern int main(int argc, char** argv);

// TODO(sbc): We shouldn't even link this file if there is no main:
// https://github.com/emscripten-core/emscripten/issues/9640
extern int main(int argc, char** argv) __attribute__((weak));

void _start(void) {
if (!main) {
if (__wasm_call_ctors) {
__wasm_call_ctors();
}
return;
}

/* Fill in the arguments from WASI syscalls. */
size_t argc;
char **argv;
Expand Down
12 changes: 12 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8213,6 +8213,18 @@ def test_safe_stack_dylink(self):
}
''', ['abort(stack overflow)', '__handle_stack_overflow'], assert_returncode=None)

@also_with_standalone_wasm
def test_undefined_main(self):
# By default in emscripten we allow main to be undefined. Its used when
# building library code that has no main.
# TODO(sbc): Simplify the code by making this an opt-in feature.
# https://github.com/emscripten-core/emscripten/issues/9640
src = '''
#include <emscripten.h>
EMSCRIPTEN_KEEPALIVE void foo() {}
'''
self.build(src, self.get_dir(), 'test.c')


# Generate tests for everything
def make_run(name, emcc_args, settings=None, env=None):
Expand Down