[llvm] 693a5ca - [llvm-driver] Just use argv[0]'s filename for finding tool

Alex Brachet via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 13 09:02:04 PST 2022


Author: Alex Brachet
Date: 2022-12-13T17:01:07Z
New Revision: 693a5ca69e679da6eb22f3c9aff1ada4f8c7f6c0

URL: https://github.com/llvm/llvm-project/commit/693a5ca69e679da6eb22f3c9aff1ada4f8c7f6c0
DIFF: https://github.com/llvm/llvm-project/commit/693a5ca69e679da6eb22f3c9aff1ada4f8c7f6c0.diff

LOG: [llvm-driver] Just use argv[0]'s filename for finding tool

Usually we want the stem of argv[0] so something like clang-15
will correctly be identified as clang. For lld however, ld.lld
or ld-link would have a stem of just ld, so we also want to
use the full filename. The bug previously was that we were using
all of argv[0] so if you use a full path that happens to include a tool
name then that could be found first. This was the case in 2 stage
build where the binaries are stored in "tools/clang/stage2-bins/"
so some tools would end up as clang and not their intended tool.

Added: 
    

Modified: 
    llvm/tools/llvm-driver/llvm-driver.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-driver/llvm-driver.cpp b/llvm/tools/llvm-driver/llvm-driver.cpp
index 33b5e32a2a570..a373dafb158f0 100644
--- a/llvm/tools/llvm-driver/llvm-driver.cpp
+++ b/llvm/tools/llvm-driver/llvm-driver.cpp
@@ -54,7 +54,7 @@ static int findTool(int Argc, char **Argv) {
       return I != StringRef::npos && (I + Tool.size() == Stem.size() ||
                                       !llvm::isAlnum(Stem[I + Tool.size()]));
     };
-    for (StringRef S : {Stem, ToolName})
+    for (StringRef S : {Stem, sys::path::filename(ToolName)})
       if (IsImpl(S))
         return true;
     return false;


        


More information about the llvm-commits mailing list