summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2018-03-01 23:11:30 +0000
committerRui Ueyama <ruiu@google.com>2018-03-01 23:11:30 +0000
commitcdd5fb5087c91b45626c699e5357ae46b0f7d8a9 (patch)
treef72236b8f6642bf911aaa6afde7d4999a9cf7138
parent036ed36f0a45d2ae90fb488302a706c35d27ce57 (diff)
downloadbcm5719-llvm-cdd5fb5087c91b45626c699e5357ae46b0f7d8a9.tar.gz
bcm5719-llvm-cdd5fb5087c91b45626c699e5357ae46b0f7d8a9.zip
Report an error if you try to link against .dll instead of .lib.
It is a usage error to feed a .dll file instead of a .dll to COFF linker. Previously, lld failed with a mysterious error message. Now we reject it at the driver. Fixes https://bugs.llvm.org/show_bug.cgi?id=36440 Differential Revision: https://reviews.llvm.org/D43964 llvm-svn: 326507
-rw-r--r--lld/COFF/Driver.cpp29
-rw-r--r--lld/test/COFF/driver.test5
2 files changed, 23 insertions, 11 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 3abe0249484..e493bdea59b 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -124,39 +124,46 @@ MemoryBufferRef LinkerDriver::takeBuffer(std::unique_ptr<MemoryBuffer> MB) {
void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> MB,
bool WholeArchive) {
+ StringRef Filename = MB->getBufferIdentifier();
+
MemoryBufferRef MBRef = takeBuffer(std::move(MB));
- FilePaths.push_back(MBRef.getBufferIdentifier());
+ FilePaths.push_back(Filename);
// File type is detected by contents, not by file extension.
switch (identify_magic(MBRef.getBuffer())) {
case file_magic::windows_resource:
Resources.push_back(MBRef);
break;
-
case file_magic::archive:
if (WholeArchive) {
std::unique_ptr<Archive> File =
- CHECK(Archive::create(MBRef),
- MBRef.getBufferIdentifier() + ": failed to parse archive");
+ CHECK(Archive::create(MBRef), Filename + ": failed to parse archive");
for (MemoryBufferRef M : getArchiveMembers(File.get()))
- addArchiveBuffer(M, "<whole-archive>", MBRef.getBufferIdentifier());
+ addArchiveBuffer(M, "<whole-archive>", Filename);
return;
}
Symtab->addFile(make<ArchiveFile>(MBRef));
break;
-
case file_magic::bitcode:
Symtab->addFile(make<BitcodeFile>(MBRef));
break;
-
+ case file_magic::coff_object:
+ case file_magic::coff_import_library:
+ Symtab->addFile(make<ObjFile>(MBRef));
+ break;
case file_magic::coff_cl_gl_object:
- error(MBRef.getBufferIdentifier() + ": is not a native COFF file. "
- "Recompile without /GL");
+ error(Filename + ": is not a native COFF file. Recompile without /GL");
break;
-
+ case file_magic::pecoff_executable:
+ if (Filename.endswith_lower(".dll")) {
+ error(Filename + ": bad file type. Did you specify a DLL instead of an "
+ "import library?");
+ break;
+ }
+ LLVM_FALLTHROUGH;
default:
- Symtab->addFile(make<ObjFile>(MBRef));
+ error(MBRef.getBufferIdentifier() + ": unknown file type");
break;
}
}
diff --git a/lld/test/COFF/driver.test b/lld/test/COFF/driver.test
index 36de6c200cb..5f503f25f1f 100644
--- a/lld/test/COFF/driver.test
+++ b/lld/test/COFF/driver.test
@@ -4,3 +4,8 @@ MISSING: nosuchfile.obj: {{[Nn]}}o such file or directory
# RUN: lld-link --version | FileCheck -check-prefix=VERSION %s
VERSION: {{LLD [0-9]+\.[0-9]+}}
+
+# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
+# RUN: lld-link /out:%t.dll /dll %t.obj
+# RUN: not lld-link /out:%t.exe %t.dll 2>&1 | FileCheck -check-prefix=BADFILE %s
+BADFILE: bad file type. Did you specify a DLL instead of an import library?
OpenPOWER on IntegriCloud