https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118136
Bug ID: 118136 Summary: Linking start code built with -flto with application where main signature does not match causes warning Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: azoff at gcc dot gnu.org Target Milestone: --- Linking an application where there are function signatures that does not match should generally generate a warning like: foo.c:8:12: warning: type of 'baz' does not match original declaration [-Wlto-type-mismatch] bar.c:3:5: note: type mismatch in parameter 1 bar.c:3:5: note: type 'void' should match type 'int' bar.c:3:5: note: 'main' was previously declared here But, I think the main symbol is a little bit different. In the C23 spec, the following can be found: > 5.1.2.3.2 Program startup > The function called at program startup is named main. The implementation > declares no prototype > for this function. It shall be defined with a return type of int and with no > > parameters: > int main(void) { /* ... */ } > or with two parameters (referred to here as argc and argv, though any names > may >be used, as they > are local to the function in which they are declared): > int main(int argc, char *argv[]) { /* ... */ } > or equivalent;6) or in some other implementation-defined manner. > (footnote 6 permits some type equivalence for the arguments in the second > case, eg via typedef). This suggest that the call site can use main(int,char**) and the target may be one of: int main() {} int main(int, char **) {} int main(void) {} Based on this, it looks like the warning issued when using -flto for the "main" symbol is bogus. Attached is a small reproducer that I think is generic enough to work on any target. The use case where the startup code is built with -flto comes from embedded where it's common to try to reduce the code size as much as possible, for example using a custom _start routine.