[llvm] [Support] Resolve symlinks in `getMainExecutable()` on Windows (PR #76304)

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 23 16:21:47 PST 2023


https://github.com/aganea created https://github.com/llvm/llvm-project/pull/76304

This makes the Windows implementation for `getMainExecutable()` behave the same as its Linux counterpart, in regards to symlinks. Previously, when using `cmake ... -DLLVM_USE_SYMLINKS=ON`, calling this function wouldn't resolve to the "real", non-symlinked path.

>From 51d89243cdc1239e79a2829d2735c3ebdade0fed Mon Sep 17 00:00:00 2001
From: Alexandre Ganea <alex_toresh at yahoo.fr>
Date: Sat, 23 Dec 2023 19:03:09 -0500
Subject: [PATCH] [Support] Resolve symlinks in `getMainExecutable()`.

This makes the Windows implementation for `getMainExecutable()` behave the same as its Linux counterpart, in regards to symlinks. Previously, when using `cmake ... -DLLVM_USE_SYMLINKS=ON`, calling this function wouldn't resolve to the "real", non-symlinked path.
---
 llvm/lib/Support/Windows/Path.inc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 168a63bb2d969d..6b50309be94d77 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -154,7 +154,10 @@ std::string getMainExecutable(const char *argv0, void *MainExecAddr) {
     return "";
 
   llvm::sys::path::make_preferred(PathNameUTF8);
-  return std::string(PathNameUTF8.data());
+
+  SmallString<256> RealPath;
+  sys::fs::real_path(PathNameUTF8, RealPath);
+  return (std::string)RealPath;
 }
 
 UniqueID file_status::getUniqueID() const {



More information about the llvm-commits mailing list