This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Mangle the argc/argv `main` as `__main_argc_argv`
ClosedPublic

Authored by sunfish on Nov 25 2019, 3:40 PM.

Details

Summary

WebAssembly enforces a rule that caller and callee signatures must
match. This means that the traditional technique of passing main
argc and argv even when it doesn't need them doesn't work.

Currently the backend renames main to __original_main, however this
doesn't interact well with LTO'ing libc, and the name isn't intuitive.
This patch allows us to transition to __main_argc_argv instead.

This is currently being discussed in https://github.com/WebAssembly/tool-conventions/pull/134.

Diff Detail

Event Timeline

sunfish created this revision.Nov 25 2019, 3:40 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 25 2019, 3:40 PM
sunfish updated this revision to Diff 234426.Dec 17 2019, 5:23 PM
sunfish added reviewers: sbc100, dschuff, aheejin.

This updates the main vs __main_argc_argv patch so that it doesn't apply to Emscripten targets, following the discussion in https://github.com/WebAssembly/tool-conventions/pull/134.

sunfish updated this revision to Diff 234942.Dec 20 2019, 12:05 PM

To support a transition to the new system, temporarily define a __main_void alias for no-argument main. This allows libc to detect whether it's calling old-style or new-style main and do the right thing.

wasm_argc_argv -> main_argc_argv in the title?

sunfish retitled this revision from [WebAssembly] Mangle the argc/argv `main` as `__wasm_argc_argv` to [WebAssembly] Mangle the argc/argv `main` as `__main_argc_argv`.Jan 13 2020, 9:49 AM

@sbc100 Friendly ping :-).

sbc100 accepted this revision.Jan 15 2020, 3:13 PM
sbc100 added inline comments.
clang/lib/CodeGen/CodeGenModule.cpp
5589 ↗(On Diff #234942)

Add a TODO to remove this once we remove the __original_main thing?

This revision is now accepted and ready to land.Jan 15 2020, 3:13 PM

Would you mind re-basing? I'd like to download and try this but it seems to have conflicts right now. (i'll do my best to resolve them you might do better).

This revision was automatically updated to reflect the committed changes.