[lld] r250811 - [ELF2] Fixed crash when no library is specified for -l

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 20 02:58:56 PDT 2015


Author: grimar
Date: Tue Oct 20 04:58:56 2015
New Revision: 250811

URL: http://llvm.org/viewvc/llvm-project?rev=250811&view=rev
Log:
[ELF2] Fixed crash when no library is specified for -l

Modified:
    lld/trunk/ELF/DriverUtils.cpp
    lld/trunk/test/elf2/libsearch.s

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=250811&r1=250810&r2=250811&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Tue Oct 20 04:58:56 2015
@@ -91,6 +91,8 @@ std::string lld::elf2::findFromSearchPat
 // 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<std::string> Names;
   if (Path[0] == ':') {
     Names.push_back(Path.drop_front());

Modified: lld/trunk/test/elf2/libsearch.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/libsearch.s?rev=250811&r1=250810&r2=250811&view=diff
==============================================================================
--- lld/trunk/test/elf2/libsearch.s (original)
+++ lld/trunk/test/elf2/libsearch.s Tue Oct 20 04:58:56 2015
@@ -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




More information about the llvm-commits mailing list