Index: lld/COFF/Driver.cpp =================================================================== --- lld/COFF/Driver.cpp +++ lld/COFF/Driver.cpp @@ -124,39 +124,46 @@ void LinkerDriver::addBuffer(std::unique_ptr 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 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, "", MBRef.getBufferIdentifier()); + addArchiveBuffer(M, "", Filename); return; } Symtab->addFile(make(MBRef)); break; - case file_magic::bitcode: Symtab->addFile(make(MBRef)); break; - + case file_magic::coff_object: + case file_magic::coff_import_library: + Symtab->addFile(make(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 file" + " instead of an import file?"); + break; + } + LLVM_FALLTHROUGH; default: - Symtab->addFile(make(MBRef)); + error(MBRef.getBufferIdentifier() + ": unknown file type"); break; } } Index: lld/test/COFF/driver.test =================================================================== --- lld/test/COFF/driver.test +++ lld/test/COFF/driver.test @@ -4,3 +4,8 @@ # 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 file instead of an import file?