[PATCH] D50316: lld-link: Take /SUBSYSTEM into account for automatic /ENTRY detection.

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 7 08:05:25 PDT 2018


thakis added inline comments.


================
Comment at: lld/COFF/Driver.cpp:447
     // need to define an entry point instead of a "main".
     if (findUnderscoreMangle(E[Config->NoDefaultLibAll]))
       return mangle(E[1]);
----------------
ruiu wrote:
> This function seems a bit tricky to me especially where a boolean value is used as 0 or 1 to access an array. Maybe something like this would work:
> 
>   auto Find = [](StringRef X, StringRef Y) {
>     return findUnderscoreMangle(Config->NoDefaultLibAll ? Y : X);
>   };
> 
>   if (Config->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI) {
>     if (find("main", "mainCRTStartup"))
>       return mangle("main");
>     if (find("wmain", "wmainCRTStartup"))
>       return mangle("wmain");
>   }
> 
>   if (find("WinMain", "WinMainCRTStartup"))
>     return mangle("WinMain");
>   if (find("wWinMain", "wWinMainCRTStartup"))
>     return mangle("wWinMain");
>   return "";
I agree the current function is overly clever. Thank you for your suggestion, it much easier tor read. On the other hand it looks a bit repetitive (the entry points each repeat once, and the overall structure is repeated a few times). Since link.exe prints a warning if both main and wmain or both WinMain and wWinMain are present and that's nicer to implement in your version, I went with that (without the lambda, which makes things a bit clever again). Please take another look.


https://reviews.llvm.org/D50316





More information about the llvm-commits mailing list