aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2024-06-24 20:02:39 +0300
committerGitHub <noreply@github.com>2024-06-24 20:02:39 +0300
commitcb248f8c2a79fbddfdfed0039390e49512410a80 (patch)
tree8c5c82ee078e5f08b6777194ede793aeefc61752
parent7601ae125de673c5a5f13a1d97f16cdd49e26e29 (diff)
downloadllvm-cb248f8c2a79fbddfdfed0039390e49512410a80.zip
llvm-cb248f8c2a79fbddfdfed0039390e49512410a80.tar.gz
llvm-cb248f8c2a79fbddfdfed0039390e49512410a80.tar.bz2
[LLD] [COFF] Don't crash on an empty -entry: argument (#96058)
We can't pass an empty string to addUndefined(). This fixes the crash that was encountered in https://github.com/llvm/llvm-project/issues/93309 (turning the crash into a properly handled error; making it do the right thing is handled in https://github.com/llvm/llvm-project/pull/96055).
-rw-r--r--lld/COFF/Driver.cpp4
-rw-r--r--lld/test/COFF/invalid-entry.s20
2 files changed, 24 insertions, 0 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 1755017..cef6271 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -413,6 +413,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:
@@ -2249,6 +2251,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 0000000..8973dfb
--- /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:"