Skip to content

Commit 97d649f

Browse files
committed
[LLD] [COFF] Don't crash on an empty -entry: argument
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).
1 parent fe9aef0 commit 97d649f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lld/COFF/Driver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ void LinkerDriver::parseDirectives(InputFile *file) {
412412
enqueuePath(*path, false, false);
413413
break;
414414
case OPT_entry:
415+
if (!arg->getValue()[0])
416+
fatal("missing entry point symbol name");
415417
ctx.config.entry = addUndefined(mangle(arg->getValue()));
416418
break;
417419
case OPT_failifmismatch:
@@ -2248,6 +2250,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
22482250
{
22492251
llvm::TimeTraceScope timeScope("Entry point");
22502252
if (auto *arg = args.getLastArg(OPT_entry)) {
2253+
if (!arg->getValue()[0])
2254+
fatal("missing entry point symbol name");
22512255
config->entry = addUndefined(mangle(arg->getValue()));
22522256
} else if (!config->entry && !config->noEntry) {
22532257
if (args.hasArg(OPT_dll)) {

lld/test/COFF/invalid-entry.s

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# REQUIRES: x86
2+
# RUN: split-file %s %t.dir && cd %t.dir
3+
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64-windows test.s -o test.obj
5+
# RUN: llvm-mc -filetype=obj -triple=x86_64-windows drectve.s -o drectve.obj
6+
7+
# RUN: env LLD_IN_TEST=1 not lld-link -out:out.dll test.obj -dll -entry: 2>&1 | FileCheck %s
8+
# RUN: env LLD_IN_TEST=1 not lld-link -out:out.dll test.obj -dll drectve.obj 2>&1 | FileCheck %s
9+
10+
# CHECK: error: missing entry point symbol name
11+
12+
#--- test.s
13+
.text
14+
.globl func
15+
func:
16+
ret
17+
18+
#--- drectve.s
19+
.section .drectve, "yn"
20+
.ascii " -entry:"

0 commit comments

Comments
 (0)