Skip to content

[LLD] [COFF] Don't crash on an empty -entry: argument #96058

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

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

mstorsjo
Copy link
Member

We can't pass an empty string to addUndefined().

This fixes the crash that was encountered in
#93309 (turning the crash into a properly handled error; making it do the right thing is handled in #96055).

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).
@llvmbot
Copy link
Member

llvmbot commented Jun 19, 2024

@llvm/pr-subscribers-lld
@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-lld-coff

Author: Martin Storsjö (mstorsjo)

Changes

We can't pass an empty string to addUndefined().

This fixes the crash that was encountered in
#93309 (turning the crash into a properly handled error; making it do the right thing is handled in #96055).


Full diff: https://github.com/llvm/llvm-project/pull/96058.diff

2 Files Affected:

  • (modified) lld/COFF/Driver.cpp (+4)
  • (added) lld/test/COFF/invalid-entry.s (+20)
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 6c7f70a0b2aff..8e9d8a600a262 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -412,6 +412,8 @@ void LinkerDriver::parseDirectives(InputFile *file) {
         enqueuePath(*path, false, false);
       break;
     case OPT_entry:
+      if (!arg->getValue()[0])
+        fatal("missing entry point symbol name");
       ctx.config.entry = addUndefined(mangle(arg->getValue()));
       break;
     case OPT_failifmismatch:
@@ -2248,6 +2250,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
   {
     llvm::TimeTraceScope timeScope("Entry point");
     if (auto *arg = args.getLastArg(OPT_entry)) {
+      if (!arg->getValue()[0])
+        fatal("missing entry point symbol name");
       config->entry = addUndefined(mangle(arg->getValue()));
     } else if (!config->entry && !config->noEntry) {
       if (args.hasArg(OPT_dll)) {
diff --git a/lld/test/COFF/invalid-entry.s b/lld/test/COFF/invalid-entry.s
new file mode 100644
index 0000000000000..8973dfba3b9f8
--- /dev/null
+++ b/lld/test/COFF/invalid-entry.s
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+# RUN: split-file %s %t.dir && cd %t.dir
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-windows test.s -o test.obj
+# RUN: llvm-mc -filetype=obj -triple=x86_64-windows drectve.s -o drectve.obj
+
+# RUN: env LLD_IN_TEST=1 not lld-link -out:out.dll test.obj -dll -entry: 2>&1 | FileCheck %s
+# RUN: env LLD_IN_TEST=1 not lld-link -out:out.dll test.obj -dll drectve.obj 2>&1 | FileCheck %s
+
+# CHECK: error: missing entry point symbol name
+
+#--- test.s
+        .text
+        .globl func
+func:
+        ret
+
+#--- drectve.s
+        .section .drectve, "yn"
+        .ascii " -entry:"

@mstorsjo
Copy link
Member Author

Ping

@mstorsjo mstorsjo merged commit cb248f8 into llvm:main Jun 24, 2024
11 checks passed
@mstorsjo mstorsjo deleted the lld-empty-entry branch June 24, 2024 17:02
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants