[lld] [LLD] [MinGW] Interpret an empty -entry option as no entry point (PR #96055)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 19 03:59:25 PDT 2024


https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/96055

This fixes https://github.com/llvm/llvm-project/issues/93309, and seems to match how GNU ld handles this case.

Also treat a missing -entry argument as no entry point; this also is what GNU ld does in this case.

>From 71693acb2a8f72dc36dbacc93954ba4a22da1a53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Wed, 19 Jun 2024 13:55:59 +0300
Subject: [PATCH] [LLD] [MinGW] Interpret an empty -entry option as no entry
 point

This fixes https://github.com/llvm/llvm-project/issues/93309,
and seems to match how GNU ld handles this case.

Also treat a missing -entry argument as no entry point; this
also is what GNU ld does in this case.
---
 lld/MinGW/Driver.cpp       | 6 +++++-
 lld/test/MinGW/driver.test | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index 0d55d5b3672a4..0527839ba6f02 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -223,8 +223,12 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
     StringRef s = a->getValue();
     if (args.getLastArgValue(OPT_m) == "i386pe" && s.starts_with("_"))
       add("-entry:" + s.substr(1));
-    else
+    else if (!s.empty())
       add("-entry:" + s);
+    else
+      add("-noentry");
+  } else {
+    add("-noentry");
   }
 
   if (args.hasArg(OPT_major_os_version, OPT_minor_os_version,
diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test
index 619fee8dee7c1..ef5fc8b4aa905 100644
--- a/lld/test/MinGW/driver.test
+++ b/lld/test/MinGW/driver.test
@@ -60,6 +60,9 @@ RUN: ld.lld -### foo.o -m i386pep --entry bar 2>&1 | FileCheck -check-prefix=ENT
 RUN: ld.lld -### foo.o -m i386pep -entry=bar 2>&1 | FileCheck -check-prefix=ENTRY %s
 RUN: ld.lld -### foo.o -m i386pep --entry=bar 2>&1 | FileCheck -check-prefix=ENTRY %s
 ENTRY: -entry:bar
+RUN: ld.lld -### foo.o -m i386pep -e bar -entry= 2>&1 | FileCheck -check-prefix=NOENTRY --implicit-check-not=-entry %s
+RUN: ld.lld -### foo.o -m i386pep 2>&1 | FileCheck -check-prefix=NOENTRY %s
+NOENTRY: -noentry
 
 RUN: ld.lld -### foo.o -m i386pep -mllvm bar -mllvm baz 2>&1 | FileCheck -check-prefix=MLLVM %s
 MLLVM: -mllvm:bar -mllvm:baz



More information about the llvm-commits mailing list