Skip to content

Commit cb248f8

Browse files
authored
[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 #93309 (turning the crash into a properly handled error; making it do the right thing is handled in #96055).
1 parent 7601ae1 commit cb248f8

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
@@ -413,6 +413,8 @@ void LinkerDriver::parseDirectives(InputFile *file) {
413413
enqueuePath(*path, false, false);
414414
break;
415415
case OPT_entry:
416+
if (!arg->getValue()[0])
417+
fatal("missing entry point symbol name");
416418
ctx.config.entry = addUndefined(mangle(arg->getValue()));
417419
break;
418420
case OPT_failifmismatch:
@@ -2249,6 +2251,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
22492251
{
22502252
llvm::TimeTraceScope timeScope("Entry point");
22512253
if (auto *arg = args.getLastArg(OPT_entry)) {
2254+
if (!arg->getValue()[0])
2255+
fatal("missing entry point symbol name");
22522256
config->entry = addUndefined(mangle(arg->getValue()));
22532257
} else if (!config->entry && !config->noEntry) {
22542258
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)