[PATCH] D52931: [LLD] [COFF] Don't warn about both main and wmain in MinGW configurations

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 5 04:30:47 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: thakis, rnk, ruiu.

In MinGW setups, the entry point is always mainCRTStartup or WinMainCRTStartup, even for unicode builds. A CRT startup object is injected by the compiler, and a different startup object file is chosen depending on whether the -municode flag is set. Both narrow and wide versions of this CRT startup object define both mainCRTStartup and WinMainCRTStartup and call either main or wmain. The libmingw32.a static library contains object files with fallback main/wmain functions which reroute them to WinMain/wWinMain, in case there were no other instance of main/wmain functions in the link. This makes findUnderscoreMangle always find them as Lazy symbols.

The default case, of preferring mainCRTStartup or WinMainCRTStartup in case both narrow and wide symbols are available, is correct for MinGW, but no warning should be printed.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D52931

Files:
  COFF/Driver.cpp
  test/COFF/entry-inference5.s


Index: test/COFF/entry-inference5.s
===================================================================
--- /dev/null
+++ test/COFF/entry-inference5.s
@@ -0,0 +1,22 @@
+# REQUIRES: x86
+# RUN: echo -e ".text\n.globl otherfunc\notherfunc:\nret" > %t-lib1.s
+# RUN: echo -e ".text\n.globl wmain\nwmain:\nret" > %t-lib2.s
+# RUN: llvm-mc -triple=x86_64-windows-gnu %s -filetype=obj -o %t.o
+# RUN: llvm-mc -triple=x86_64-windows-gnu %t-lib1.s -filetype=obj -o %t-lib1.o
+# RUN: llvm-mc -triple=x86_64-windows-gnu %t-lib2.s -filetype=obj -o %t-lib2.o
+# RUN: llvm-ar crs %t-lib.a %t-lib1.o %t-lib2.o
+
+# RUN: lld-link -lldmingw %t.o %t-lib.a -out:%t.exe 2>&1 | FileCheck -allow-empty %s
+
+# Check that this doesn't print any warnings.
+# CHECK-NOT: found both wmain and main
+
+        .text
+        .globl main
+        .globl mainCRTStartup
+main:
+        call otherfunc
+        ret
+mainCRTStartup:
+        call main
+        ret
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -434,14 +434,16 @@
     if (findUnderscoreMangle("wWinMain")) {
       if (!findUnderscoreMangle("WinMain"))
         return mangle("wWinMainCRTStartup");
-      warn("found both wWinMain and WinMain; using latter");
+      if (!Config->MinGW)
+        warn("found both wWinMain and WinMain; using latter");
     }
     return mangle("WinMainCRTStartup");
   }
   if (findUnderscoreMangle("wmain")) {
     if (!findUnderscoreMangle("main"))
       return mangle("wmainCRTStartup");
-    warn("found both wmain and main; using latter");
+    if (!Config->MinGW)
+      warn("found both wmain and main; using latter");
   }
   return mangle("mainCRTStartup");
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52931.168454.patch
Type: text/x-patch
Size: 1730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181005/08b7e10c/attachment.bin>


More information about the llvm-commits mailing list