[PATCH] D78328: [lld] Infer the driver mode from the target.
Dan Albert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 14:31:35 PDT 2020
danalbert created this revision.
danalbert added reviewers: srhines, MaskRay.
danalbert added a project: lld.
Herald added a project: LLVM.
MaskRay added inline comments.
================
Comment at: lld/tools/lld/lld.cpp:134
+ // Deduce the flavor from the target.
+ if (targetMatches(v, [](StringRef s) {
+ return s.contains("linux") || s.contains("elf");
----------------
This checks `-m` for lld-link, wasm-ld and ld64 which not be great.
We can place the check inside:
```
#if __APPLE__
// Use Darwin driver for "ld" on Darwin.
if (progname == "ld")
return Darwin;
#endif
```
This is a largely untested work in progress as an alternative to
https://reviews.llvm.org/D76452. If we decide to go this route I'll
add the missing tests :)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D78328
Files:
lld/tools/lld/lld.cpp
Index: lld/tools/lld/lld.cpp
===================================================================
--- lld/tools/lld/lld.cpp
+++ lld/tools/lld/lld.cpp
@@ -77,11 +77,12 @@
return s == "i386pe" || s == "i386pep" || s == "thumb2pe" || s == "arm64pe";
}
-static bool isPETarget(std::vector<const char *> &v) {
+static bool targetMatches(std::vector<const char *> &v,
+ std::function<bool(StringRef)> targetFilter) {
for (auto it = v.begin(); it + 1 != v.end(); ++it) {
if (StringRef(*it) != "-m")
continue;
- return isPETargetName(*(it + 1));
+ return targetFilter(*(it + 1));
}
// Expand response files (arguments in the form of @<filename>)
// to allow detecting the -m argument from arguments in them.
@@ -90,7 +91,7 @@
for (auto it = expandedArgs.begin(); it + 1 != expandedArgs.end(); ++it) {
if (StringRef(*it) != "-m")
continue;
- return isPETargetName(*(it + 1));
+ return targetFilter(*(it + 1));
}
return false;
}
@@ -129,6 +130,13 @@
return f;
}
+ // Deduce the flavor from the target.
+ if (targetMatches(v, [](StringRef s) {
+ return s.contains("linux") || s.contains("elf");
+ })) {
+ return Gnu;
+ }
+
// Deduct the flavor from argv[0].
StringRef arg0 = path::filename(v[0]);
if (arg0.endswith_lower(".exe"))
@@ -152,7 +160,7 @@
std::vector<const char *> args(argv, argv + argc);
switch (parseFlavor(args)) {
case Gnu:
- if (isPETarget(args))
+ if (targetMatches(args, isPETargetName))
return !mingw::link(args, canExitEarly(), llvm::outs(), llvm::errs());
return !elf::link(args, canExitEarly(), llvm::outs(), llvm::errs());
case WinLink:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78328.258167.patch
Type: text/x-patch
Size: 1705 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200416/b44840f9/attachment.bin>
More information about the llvm-commits
mailing list