[PECOFF] Treat .imp as an import library file.
Some Clang build uses .imp not .lib file extension for an import library file, so we need to treat such file as a library file. Ideally we should not rely on file extensions to detect file type. Instead we should use magic bytes at beginning of a file. The GNU-compatible driver actually does that but it made writing unit tests hard, so I chose an ad-hoc approach for now. llvm-svn: 205283
This commit is contained in:
parent
2e1e0491b7
commit
1e7d0721ae
|
@ -24,6 +24,8 @@
|
|||
|
||||
namespace lld {
|
||||
|
||||
extern bool isCOFFLibraryFileExtension(StringRef path);
|
||||
|
||||
/// \brief Represents a PECOFF File
|
||||
class PECOFFFileNode : public FileNode {
|
||||
public:
|
||||
|
|
|
@ -1172,7 +1172,7 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
|
|||
// Prepare objects to add them to input graph.
|
||||
for (StringRef path : inputFiles) {
|
||||
path = ctx.allocate(path);
|
||||
if (path.endswith_lower(".lib")) {
|
||||
if (isCOFFLibraryFileExtension(path)) {
|
||||
libraries.push_back(std::unique_ptr<FileNode>(new PECOFFLibraryNode(ctx, path)));
|
||||
} else {
|
||||
files.push_back(std::unique_ptr<FileNode>(new PECOFFFileNode(ctx, path)));
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
|
||||
namespace lld {
|
||||
|
||||
bool isCOFFLibraryFileExtension(StringRef path) {
|
||||
return path.endswith_lower(".lib") || path.endswith_lower(".imp");
|
||||
}
|
||||
|
||||
/// \brief Parse the input file to lld::File.
|
||||
error_code PECOFFFileNode::parse(const LinkingContext &ctx,
|
||||
raw_ostream &diagnostics) {
|
||||
|
@ -38,7 +42,7 @@ ErrorOr<File &> PECOFFFileNode::getNextFile() {
|
|||
}
|
||||
|
||||
ErrorOr<StringRef> PECOFFFileNode::getPath(const LinkingContext &) const {
|
||||
if (_path.endswith_lower(".lib"))
|
||||
if (isCOFFLibraryFileExtension(_path))
|
||||
return _ctx.searchLibraryFile(_path);
|
||||
if (llvm::sys::path::extension(_path).empty())
|
||||
return _ctx.allocate(_path.str() + ".obj");
|
||||
|
@ -46,7 +50,7 @@ ErrorOr<StringRef> PECOFFFileNode::getPath(const LinkingContext &) const {
|
|||
}
|
||||
|
||||
ErrorOr<StringRef> PECOFFLibraryNode::getPath(const LinkingContext &) const {
|
||||
if (_path.endswith_lower(".lib"))
|
||||
if (isCOFFLibraryFileExtension(_path))
|
||||
return _ctx.searchLibraryFile(_path);
|
||||
return _ctx.searchLibraryFile(_ctx.allocate(_path.str() + ".lib"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue