-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLD] [MinGW] Interpret an empty -entry option as no entry point #96055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-lld @llvm/pr-subscribers-lld-coff Author: Martin Storsjö (mstorsjo) ChangesThis fixes #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. Full diff: https://github.com/llvm/llvm-project/pull/96055.diff 2 Files Affected:
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
|
We can't pass an empty string to addUndefined(). This fixes the crash that was encountered in llvm#93309 (turning the crash into a properly handled error; making it do the right thing is handled in llvm#96055).
Not sure if this is necessary or correct. Wouldn't this break the default entry points (e.g. |
There's indeed no strict need for this part of the change, I just chose to include it for completeness (as I remember noticing this behaviour in GNU ld before). And yes, you're right that it would change the behaviour of default entry points. However the default entry point behaviour never really comes into play in mingw configurations; as long as you drive the linking via GCC/Clang, it always passes one If you feel it's nice to keep the lld style autodetection here, we could of course do that, but practically it makes not much difference either way. |
Does it...? When I run |
Oh, you're absolutely right, it isn't - I clearly misremembered, and didn't check correctly. Indeed, we shouldn't be touching this aspect of it - the default behaviour in GNU ld is also more nuanced than this. |
71693ac
to
95b091f
Compare
This fixes llvm#93309, and seems to match how GNU ld handles this case.
95b091f
to
373469f
Compare
Pushed an update to remove this part of the change now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM.
…m#96055) This fixes llvm#93309, and seems to match how GNU ld handles this case.
We can't pass an empty string to addUndefined(). This fixes the crash that was encountered in llvm#93309 (turning the crash into a properly handled error; making it do the right thing is handled in llvm#96055).
This fixes #93309, and seems to match how GNU ld handles this case.