Skip to content

Commit 94af17a

Browse files
authored
Remove handling of legacy main mangling. (#17170)
Now that https://reviews.llvm.org/D75277 as landed in llvm we can depend on the `__main_void` alias and the `__main_argv_argc` mangling. This only effects STANDALONE_WASM mode.
1 parent 4881eaf commit 94af17a

File tree

6 files changed

+22
-55
lines changed

6 files changed

+22
-55
lines changed

src/jsifier.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ function ${name}(${args}) {
204204
return;
205205
}
206206
if (!isDefined(ident)) {
207-
let msg = 'undefined symbol: ' + ident;
207+
let undefinedSym = ident;
208+
if (ident === '__main_argc_argv') {
209+
undefinedSym = 'main';
210+
}
211+
let msg = 'undefined symbol: ' + undefinedSym;
208212
if (dependent) msg += ` (referenced by ${dependent})`;
209213
if (ERROR_ON_UNDEFINED_SYMBOLS) {
210214
error(msg);
@@ -216,7 +220,7 @@ function ${name}(${args}) {
216220
} else if (VERBOSE || WARN_ON_UNDEFINED_SYMBOLS) {
217221
warn(msg);
218222
}
219-
if (ident === 'main' && STANDALONE_WASM) {
223+
if (undefinedSym === 'main' && STANDALONE_WASM) {
220224
warn('To build in STANDALONE_WASM mode without a main(), use emcc --no-entry');
221225
}
222226
}

system/lib/libc/crt1.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
* found in the LICENSE file.
66
*/
77

8-
// Much of this code comes from:
9-
// https://github.com/CraneStation/wasi-libc/blob/master/libc-bottom-half/crt/crt1.c
10-
// Converted malloc() calls to alloca() to avoid including malloc in all programs.
11-
128
#include <stdlib.h>
139
#include <wasi/api.h>
1410

1511
__attribute__((__weak__)) void __wasm_call_ctors(void);
1612

17-
int __original_main(void);
13+
int __main_void(void);
1814

1915
void _start(void) {
2016
if (__wasm_call_ctors) {
@@ -26,7 +22,7 @@ void _start(void) {
2622
* or our __original_main fallback in __original_main.c which handles
2723
* populating argv.
2824
*/
29-
int r = __original_main();
25+
int r = __main_void();
3026

3127
exit(r);
3228
}

system/lib/standalone/__main_argc_argv.c

Lines changed: 0 additions & 17 deletions
This file was deleted.

system/lib/standalone/__main_void.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@
99
#include <wasi/api.h>
1010
#include <sysexits.h>
1111

12+
// Much of this code comes from:
13+
// https://github.com/CraneStation/wasi-libc/blob/master/libc-bottom-half/crt/crt1.c
14+
// Converted malloc() calls to alloca() to avoid including malloc in all programs.
15+
1216
int __main_argc_argv(int argc, char *argv[]);
1317

14-
// If main() uses argc/argv, then no __original_main is emitted, and then
15-
// this definition is used, which loads those values and sends them to main.
16-
// If main() does not use argc/argv, then the compiler emits __original_main
17-
// and this definition is not necessary, which avoids the wasi calls for
18-
// getting the args.
19-
// If there is no main() at all, we don't need this definition, but it will get
20-
// linked in. However, _start checks for main()'s existence and only calls
21-
// __original_main() if it does, so this will not be called, which allows
22-
// LLVM LTO or the Binaryen optimizer to remove it.
18+
// If the application's `main` does not uses argc/argv, then it will be defined
19+
// (by llvm) with an __main_void alias, and therefore this function will not
20+
// be included, and `_start` will call the application's `__main_void` directly.
21+
//
22+
// If the application's `main` does use argc/argv, then _start will call this
23+
// function which which loads argv valud values and sends them to to the
24+
// application's `main` which gets mangled to `__main_argc_argv` by llvm.
2325
__attribute__((weak))
2426
int __main_void(void) {
2527
/* Fill in the arguments from WASI syscalls. */

system/lib/standalone/__original_main.c

Lines changed: 0 additions & 19 deletions
This file was deleted.

tools/system_libs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,8 +1653,9 @@ def get_default_variation(cls, **kwargs):
16531653
def get_files(self):
16541654
files = files_in_path(
16551655
path='system/lib/standalone',
1656-
filenames=['standalone.c', 'standalone_wasm_stdio.c', '__original_main.c',
1657-
'__main_void.c', '__main_argc_argv.c'])
1656+
filenames=['standalone.c',
1657+
'standalone_wasm_stdio.c',
1658+
'__main_void.c'])
16581659
files += files_in_path(
16591660
path='system/lib/libc',
16601661
filenames=['emscripten_memcpy.c'])

0 commit comments

Comments
 (0)