From b7d79b5c27fdb54afeaaff50032cf97e3f89bf77 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Tue, 20 Oct 2015 09:58:56 +0000 Subject: [PATCH] [ELF2] Fixed crash when no library is specified for -l llvm-svn: 250811 --- lld/ELF/DriverUtils.cpp | 2 ++ lld/test/elf2/libsearch.s | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp index d26e0cf009a2..5774af67d7da 100644 --- a/lld/ELF/DriverUtils.cpp +++ b/lld/ELF/DriverUtils.cpp @@ -91,6 +91,8 @@ std::string lld::elf2::findFromSearchPaths(StringRef Path) { // Searches a given library from input search paths, which are filled // from -L command line switches. Returns a path to an existent library file. std::string lld::elf2::searchLibrary(StringRef Path) { + if (Path.empty()) + error("No library specified for -l"); std::vector Names; if (Path[0] == ':') { Names.push_back(Path.drop_front()); diff --git a/lld/test/elf2/libsearch.s b/lld/test/elf2/libsearch.s index 30aa4ff66d63..140e48f9d7df 100644 --- a/lld/test/elf2/libsearch.s +++ b/lld/test/elf2/libsearch.s @@ -10,6 +10,11 @@ // RUN: llvm-ar rcs %t.dir/libls.a %tst.o // REQUIRES: x86 +// Should fail if no library specified +// RUN: not ld.lld2 -l 2>&1 \ +// RUN: | FileCheck --check-prefix=NOLIBRARY %s +// NOLIBRARY: No library specified for -l + // Should not link because of undefined symbol _bar // RUN: not ld.lld2 -o %t3 %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=UNDEFINED %s