[PATCH][lld][PECOFF] Add Support for entry point symbol name

Jesús Serrano dagonoweda at gmail.com
Tue Aug 20 13:07:01 PDT 2013


> I've attached a new patch with this changes. Now the windows driver 
> sets the entry symbol name according to the corresponding options. 
> However, this won't work in all cases. Depending onwhether the crt is 
> compiled as multibyte or unicode, the entry point symbol name changes 
> from "mainCRTStartup" to "wmainCRTStartup", and the same for the 
> windows subsystem. The problem with this is that the use of unicode is 
> unknown at link time (or at least I don't know how to retrieve this 
> option from object files). One possible solution would be to have two 
> entry point names in the linking context, and find a symbol mathing 
> any of them, but I don't like it so much. Any ideas on this?

I've looking into this, and seems that LINK.EXE behavior for executable 
images is to "select" the CRT entry point depending on the symbols 
defined in the object files.
  If neither the subsystem nor the entry point are defined in command 
line arguments, the linker searches for the symbols "_main", "_wmain", 
"_WinMain" and "_wWinMain". Depending on the found symbols, the linker 
chooses the subsystem and the CRT entry point, having "_main" the 
highest priority and "_wWinMain" the lesser. This is, if "_main" is 
defined, the subsystem will be CONSOLE and the CRT entry point 
"_mainCRTStartup", and so on. If several of these entry point symbols 
for the same subsystem are defined, the linker chooses the symbol of 
higher priority and prints a warning.
If the subsystem is defined in the command line, then the linker 
searches only for the corresponding entry point symbols to choose 
between the unicode and the multibyte CRT entry point.
If the entry point symbol is defined in the command line, but not the 
subsystem, the linker forces to choose one and throws an error.

If we want to follow this behavior, it has no sense to let the driver to 
choose the entry point symbol name. This could be handled by the linking 
context after the file parsing or the by writer, what do you think about 
that?



More information about the llvm-commits mailing list