summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-ar/llvm-ar.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-12-10 13:45:02 -0800
committerFangrui Song <maskray@google.com>2019-12-10 17:32:50 -0800
commit4d53b99c5df2c83172d23521d1b1ab8361d6de92 (patch)
treed848c045cd9aeac3e8e9bf7ff874415c8bcf9635 /llvm/tools/llvm-ar/llvm-ar.cpp
parent935d41e4bd6347155af10e50f8b24e86a5d626f7 (diff)
downloadbcm5719-llvm-4d53b99c5df2c83172d23521d1b1ab8361d6de92.tar.gz
bcm5719-llvm-4d53b99c5df2c83172d23521d1b1ab8361d6de92.zip
[llvm-ar] Improve tool selection heuristic
If llvm-ar is installed at arm-pokymllib32-linux-gnueabi-llvm-ar, it may think it is llvm-lib due to the "lib" substring. Improve the heuristic to make all the following work as intended: llvm-ar-9 (llvm-9 package on Debian) llvm-ranlib.exe Lib.exe (reported by D44808) arm-pokymllib32-linux-gnueabi-llvm-ar (reported by D71030) Reviewed By: raj.khem, rupprecht Differential Revision: https://reviews.llvm.org/D71302
Diffstat (limited to 'llvm/tools/llvm-ar/llvm-ar.cpp')
-rw-r--r--llvm/tools/llvm-ar/llvm-ar.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index 1fdc433047f..d1830c0762c 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/LLVMContext.h"
@@ -1179,16 +1180,25 @@ int main(int argc, char **argv) {
llvm::InitializeAllAsmParsers();
Stem = sys::path::stem(ToolName);
- if (Stem.contains_lower("dlltool"))
+ auto Is = [](StringRef Tool) {
+ // We need to recognize the following filenames.
+ //
+ // Lib.exe -> lib (see D44808, MSBuild runs Lib.exe)
+ // dlltool.exe -> dlltool
+ // arm-pokymllib32-linux-gnueabi-llvm-ar-10 -> ar
+ auto I = Stem.rfind_lower(Tool);
+ return I != StringRef::npos &&
+ (I + Tool.size() == Stem.size() || !isAlnum(Stem[I + Tool.size()]));
+ };
+
+ if (Is("dlltool"))
return dlltoolDriverMain(makeArrayRef(argv, argc));
-
- if (Stem.contains_lower("ranlib"))
+ if (Is("ranlib"))
return ranlib_main(argc, argv);
-
- if (Stem.contains_lower("lib"))
+ if (Is("lib"))
return libDriverMain(makeArrayRef(argv, argc));
-
- if (Stem.contains_lower("ar"))
+ if (Is("ar"))
return ar_main(argc, argv);
+
fail("not ranlib, ar, lib or dlltool");
}
OpenPOWER on IntegriCloud