summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--llvm/test/tools/llvm-ar/tool-name.test15
-rw-r--r--llvm/test/tools/llvm-dlltool/tool-name.test13
-rw-r--r--llvm/test/tools/llvm-lib/tool-name.test14
-rw-r--r--llvm/test/tools/llvm-ranlib/tool-name.test13
-rw-r--r--llvm/tools/llvm-ar/llvm-ar.cpp24
5 files changed, 72 insertions, 7 deletions
diff --git a/llvm/test/tools/llvm-ar/tool-name.test b/llvm/test/tools/llvm-ar/tool-name.test
new file mode 100644
index 00000000000..cb656d3b47f
--- /dev/null
+++ b/llvm/test/tools/llvm-ar/tool-name.test
@@ -0,0 +1,15 @@
+## Don't make symlinks on Windows.
+# UNSUPPORTED: system-windows
+
+# RUN: rm -rf %t
+# RUN: mkdir %t
+# RUN: ln -s llvm-ar %t/llvm-ar-9
+# RUN: ln -s llvm-ar %t/ar.exe
+# RUN: ln -s llvm-ar %t/arm-pokymllib32-linux-gnueabi-llvm-ar-9
+
+# RUN: llvm-ar h | FileCheck %s
+# RUN: %t/llvm-ar-9 h | FileCheck %s
+# RUN: %t/ar.exe h | FileCheck %s
+# RUN: %t/arm-pokymllib32-linux-gnueabi-llvm-ar-9 h | FileCheck %s
+
+# CHECK: USAGE: llvm-ar
diff --git a/llvm/test/tools/llvm-dlltool/tool-name.test b/llvm/test/tools/llvm-dlltool/tool-name.test
new file mode 100644
index 00000000000..e9d8680322d
--- /dev/null
+++ b/llvm/test/tools/llvm-dlltool/tool-name.test
@@ -0,0 +1,13 @@
+## Don't make symlinks on Windows.
+# UNSUPPORTED: system-windows
+
+# RUN: rm -rf %t
+# RUN: mkdir %t
+# RUN: ln -s llvm-dlltool %t/dlltool.exe
+# RUN: ln -s llvm-dlltool %t/dlltool-10
+
+# RUN: not llvm-dlltool 2>&1 | FileCheck %s
+# RUN: not %t/dlltool.exe 2>&1 | FileCheck %s
+# RUN: not %t/dlltool-10 2>&1 | FileCheck %s
+
+# CHECK: USAGE: llvm-dlltool
diff --git a/llvm/test/tools/llvm-lib/tool-name.test b/llvm/test/tools/llvm-lib/tool-name.test
new file mode 100644
index 00000000000..9c0f7b5de73
--- /dev/null
+++ b/llvm/test/tools/llvm-lib/tool-name.test
@@ -0,0 +1,14 @@
+## Don't make symlinks on Windows.
+# UNSUPPORTED: system-windows
+
+# RUN: rm -rf %t
+# RUN: mkdir %t
+## See D44808, MSBuild runs Lib.exe
+# RUN: ln -s llvm-lib %t/Lib.exe
+# RUN: ln -s llvm-lib %t/llvm-lib-10
+
+# RUN: llvm-lib '/?' | FileCheck %s
+# RUN: %t/Lib.exe '/?' | FileCheck %s
+# RUN: %t/llvm-lib-10 '/?' | FileCheck %s
+
+# CHECK: USAGE: llvm-lib
diff --git a/llvm/test/tools/llvm-ranlib/tool-name.test b/llvm/test/tools/llvm-ranlib/tool-name.test
new file mode 100644
index 00000000000..bd2b4965331
--- /dev/null
+++ b/llvm/test/tools/llvm-ranlib/tool-name.test
@@ -0,0 +1,13 @@
+## Don't make symlinks on Windows.
+# UNSUPPORTED: system-windows
+
+# RUN: rm -rf %t
+# RUN: mkdir %t
+# RUN: ln -s llvm-ranlib %t/llvm-ranlib-9
+# RUN: ln -s llvm-ranlib %t/ranlib.exe
+
+# RUN: llvm-ranlib -h | FileCheck %s
+# RUN: %t/llvm-ranlib-9 -h | FileCheck %s
+# RUN: %t/ranlib.exe -h | FileCheck %s
+
+# CHECK: USAGE: llvm-ranlib
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