Enable the functionality to rewrite the signature of "int main(void)" functions to "int main(int argc, char *argv[])", so that they can be called by the C startup code, since WebAssembly requires caller and callee signatures to match.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
I tried to enable this by default recently but had to revert: https://reviews.llvm.org/D54117.
I'm fine for this to land in the mean time but you might want to be aware of this issue.
The patch here avoids the envp issue by limiting the transformation to the (standard-approved) int main(void) case, and not arbitrary signatures. So if it sees int main(int argc, char *argv[], char *envp[]), it won't do anything.
In that case can you just remove the TemporaryWorkarounds flag and always do this transform? That is the behaviour we want and I only reverted my change because of the envp issue.
It needs to align with what crt1.o does though, which is specific to the OS. For WASI's crt1.o, my current working theory is to just support the two standard-required cases and not the envp case. But for the unknown OS, we don't know what people might want to link to.
But we already decided we wanted this behaviour and my change only got reverted because it was demoting the 3-arg form to the 2-arg form. Musl's crt0 currently expects the 2-arg form so this would align exactly with what you have done here: promote the 0-arg to 2-arg form but leave the 3-arg form (and all other forms) alone.
- Remove the target constraint, allowing the main rewrite logic to work on all wasm32 targets.
- Remove the now-unneeded "wasm-temporary-workarounds" flag altogether.
- This uncovered some bugs with wrappers for main when main is only a declaration; fix those as well.
But we already decided we wanted this behaviour and my change only got reverted because it was demoting the 3-arg form to the 2-arg form. Musl's crt0 currently expects the 2-arg form so this would align exactly with what you have done here: promote the 0-arg to 2-arg form but leave the 3-arg form (and all other forms) alone.
Ok, that works for me. And this way we can get rid of the wasm-temporary-workarounds flag completely, which is a nice bonus. Patch updated.
test/CodeGen/WebAssembly/main-three-args.ll | ||
---|---|---|
4 ↗ | (On Diff #183988) | Drop the WASI |