Skip to content

Commit c95f251

Browse files
committed
Make main symbol options even in STANDALONE_WASM mode
See:#9640 Fixes: #9635
1 parent ca1023b commit c95f251

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

system/lib/libc/crt1.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
#include <stdio.h>
1717

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

2124
void _start(void) {
2225
/* Fill in the arguments from WASI syscalls. */
@@ -50,7 +53,7 @@ void _start(void) {
5053
__wasm_call_ctors();
5154
}
5255

53-
int r = main(argc, argv);
56+
int r = main ? main(argc, argv) : 0;
5457

5558
/* If main exited successfully, just return, otherwise call _Exit.
5659
* TODO(sbc): switch to _Exit */

tests/test_core.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8213,6 +8213,18 @@ def test_safe_stack_dylink(self):
82138213
}
82148214
''', ['abort(stack overflow)', '__handle_stack_overflow'], assert_returncode=None)
82158215

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

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

0 commit comments

Comments
 (0)