Skip to content

Commit ab01f91

Browse files
authored
Fix unexported main warning for main functions that take arguments (#21011)
Prior to this change the warning would only show up for `main` functions with no arguments.
1 parent 85cfaa0 commit ab01f91

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

test/test_other.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7923,14 +7923,18 @@ def test(contents, expected, args=[], assert_returncode=0): # noqa
79237923
# test backwards compatibility
79247924
test("Module['print']('print'); Module['printErr']('err'); ", 'print\nerr', ['-sEXPORTED_RUNTIME_METHODS=print,printErr', '-Wno-js-compiler'])
79257925

7926+
@parameterized({
7927+
'': ('hello_world.c',),
7928+
'argv': ('hello_world_argv.c',),
7929+
})
79267930
@parameterized({
79277931
'': ([],),
79287932
'O2': (['-O2'],),
79297933
})
7930-
def test_warn_unexported_main(self, args):
7934+
def test_warn_unexported_main(self, args, filename):
79317935
warning = 'emcc: warning: `main` is defined in the input files, but `_main` is not in `EXPORTED_FUNCTIONS`. Add it to this list if you want `main` to run. [-Wunused-main]'
79327936

7933-
proc = self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=[]'] + args, stderr=PIPE)
7937+
proc = self.run_process([EMCC, test_file(filename), '-sEXPORTED_FUNCTIONS=[]'] + args, stderr=PIPE)
79347938
# This warning only shows up when ASSERTIONS are enabled.
79357939
# We run both ways those to ensure that main doesn't get run in either case.
79367940
if '-O2' in args:

tools/emscripten.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,10 @@ def finalize_wasm(infile, outfile, js_syms):
577577
if not settings.STANDALONE_WASM and '_main' in unexpected_exports:
578578
diagnostics.warning('unused-main', '`main` is defined in the input files, but `_main` is not in `EXPORTED_FUNCTIONS`. Add it to this list if you want `main` to run.')
579579
unexpected_exports.remove('_main')
580-
metadata.all_exports.remove('main')
580+
if 'main' in metadata.all_exports:
581+
metadata.all_exports.remove('main')
582+
else:
583+
metadata.all_exports.remove('__main_argc_argv')
581584

582585
building.user_requested_exports.update(unexpected_exports)
583586
settings.EXPORTED_FUNCTIONS.extend(unexpected_exports)

tools/link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def phase_linker_setup(options, state, newargs):
847847
# See other.test_warn_unexported_main.
848848
# This is not needed in STANDALONE_WASM mode since we export _start
849849
# (unconditionally) rather than main.
850-
settings.EXPORT_IF_DEFINED.append('main')
850+
settings.EXPORT_IF_DEFINED += ['main', '__main_argc_argv']
851851

852852
if settings.ASSERTIONS:
853853
# Exceptions are thrown with a stack trace by default when ASSERTIONS is

0 commit comments

Comments
 (0)