Fix genCmain code to remove ambiguity of &main expression#2540
Fix genCmain code to remove ambiguity of &main expression#2540MartinNowak merged 2 commits intodlang:masterfrom
&main expression#2540Conversation
src/mars.c
Outdated
There was a problem hiding this comment.
This needs to be obj_start(modules[0]->srcfile->toChars());.
If there is a |
|
I don't understand the problem that this pull addresses? |
|
By the #2476 change, // in user module
void main() { ... } // user-defined extern(D) main
extern(C) {
int _d_run_main(int argc, char **argv, void* mainFunc);
int main(int argc, char **argv) { return _d_run_main(argc, argv, &main); } // X
version (Solaris) int _main(int argc, char** argv) { return main(argc, argv); }
}At the line In other words, current entrypoint insertion way is relying on the current incorrect overload resolution behavior. After fixing the bug by #2130, it will cause a problem. This PR fixes the currently hidden issue. |
It was introduced by pull#2476, but the expression `&main` which is implicitly inserted would conflict with two extern(C) and (D) "main" functions in user module. Instead, separate the entry-point code in the hidden module __entrypoint.d Compiler will emit the generated C-main code in the same object file that contains D-main code.
src/mars.c
Outdated
There was a problem hiding this comment.
This crashes when you compile a library, because obj_write_deferred accesses Module::ident which is NULL.
This would work.
Identifier *id = Lexer::idPool("__entrypoint");
Module *m = new Module("__entrypoint.d", id, 0, 0);There was a problem hiding this comment.
Thanks very much! Fixed.
Fix genCmain code to remove ambiguity of `&main` expression
|
Thanks! |
By dlang#2540 , implicitly defined C main has been moved to __entrypoint module. But, the codegen generates ModuleInfo symbol for the module. And vibe.d has its own main function in library. Then, compiling uer progam with vibe.d library will cause the conflict of two ModuleInfo symbols of __entrypoint module. Due to avoid ModuleInfo symbol generation for __entrypoint, I added a special case in Module::genobjfile function. But, I'm not sure that the change won't cause any other problems...
It was introduced by pull #2476, but the expression
&mainwhich is implicitlyinserted would conflict with two extern(C) and (D) "main" functions in
user module.
Instead, separate the entry-point code in the hidden module
__entrypoint.d