[Lldb-commits] [lldb] [lldb] Resolve symlinks when transferring files to remote devices (PR #189177)

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Sat Mar 28 09:41:06 PDT 2026


https://github.com/medismailben created https://github.com/llvm/llvm-project/pull/189177

Platform::Install treated symlinks by reading the link target with Readlink and creating a symlink on the remote device via CreateSymlink. This fails because the symlink target is a local path that doesn't exist on the device. Platform::PutFile also explicitly set DontFollowSymlinks when opening symlinked source files, causing "Too many levels of symbolic links" errors.

This meant shared libraries built as symlinks (common with framework builds using @executable_path install names) were silently never transferred, causing dyld "Library not loaded" failures on launch.

Fix both symlink cases in Platform::Install to resolve the link with Readlink and transfer the actual file content via PutFile instead of creating a remote symlink. Fix PutFile to resolve symlinks before opening the source file.

rdar://173566256

>From 0f988f00b5413486e55f29e6ce469842f5a74ffc Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani <ismail at bennani.ma>
Date: Sat, 28 Mar 2026 09:36:34 -0700
Subject: [PATCH] [lldb] Resolve symlinks when transferring files to remote
 devices

Platform::Install treated symlinks by reading the link target with
Readlink and creating a symlink on the remote device via CreateSymlink.
This fails because the symlink target is a local path that doesn't
exist on the device. Platform::PutFile also explicitly set
DontFollowSymlinks when opening symlinked source files, causing
"Too many levels of symbolic links" errors.

This meant shared libraries built as symlinks (common with framework
builds using @executable_path install names) were silently never
transferred, causing dyld "Library not loaded" failures on launch.

Fix both symlink cases in Platform::Install to resolve the link with
Readlink and transfer the actual file content via PutFile instead of
creating a remote symlink. Fix PutFile to resolve symlinks before
opening the source file.

rdar://173566256

Signed-off-by: Med Ismail Bennani <ismail at bennani.ma>
---
 lldb/source/Target/Platform.cpp | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 51ef8d7259d9a..bd23f2b0116fa 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -497,23 +497,21 @@ RecurseCopy_Callback(void *baton, llvm::sys::fs::file_type ft,
   } break;
 
   case fs::file_type::symlink_file: {
-    // copy the file and keep going
+    // Resolve the symlink and transfer the actual file content. The symlink
+    // target may be a local absolute path that won't exist on the device.
     FileSpec dst_file = rc_baton->dst;
     if (!dst_file.GetFilename())
       dst_file.SetFilename(src.GetFilename());
 
     FileSpec src_resolved;
-
     rc_baton->error = FileSystem::Instance().Readlink(src, src_resolved);
-
     if (rc_baton->error.Fail())
-      return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
+      return FileSystem::eEnumerateDirectoryResultQuit;
 
     rc_baton->error =
-        rc_baton->platform_ptr->CreateSymlink(dst_file, src_resolved);
-
+        rc_baton->platform_ptr->PutFile(src_resolved, dst_file);
     if (rc_baton->error.Fail())
-      return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
+      return FileSystem::eEnumerateDirectoryResultQuit;
 
     return FileSystem::eEnumerateDirectoryResultNext;
   } break;
@@ -630,11 +628,13 @@ Status Platform::Install(const FileSpec &src, const FileSpec &dst) {
       break;
 
     case fs::file_type::symlink_file: {
+      // Resolve the symlink and transfer the actual file content. The symlink
+      // target may be a local absolute path that won't exist on the device.
       llvm::sys::fs::remove(fixed_dst.GetPath());
       FileSpec src_resolved;
       error = FileSystem::Instance().Readlink(src, src_resolved);
       if (error.Success())
-        error = CreateSymlink(dst, src_resolved);
+        error = PutFile(src_resolved, fixed_dst);
     } break;
     case fs::file_type::fifo_file:
       error = Status::FromErrorString("platform install doesn't handle pipes");
@@ -1185,14 +1185,15 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination,
   Log *log = GetLog(LLDBLog::Platform);
   LLDB_LOGF(log, "[PutFile] Using block by block transfer....\n");
 
+  // Resolve symlinks so we transfer the actual file content.
+  FileSpec resolved_source(source);
+  FileSystem::Instance().Resolve(resolved_source);
+
   auto source_open_options =
       File::eOpenOptionReadOnly | File::eOpenOptionCloseOnExec;
-  namespace fs = llvm::sys::fs;
-  if (fs::is_symlink_file(source.GetPath()))
-    source_open_options |= File::eOpenOptionDontFollowSymlinks;
 
-  auto source_file = FileSystem::Instance().Open(source, source_open_options,
-                                                 lldb::eFilePermissionsUserRW);
+  auto source_file = FileSystem::Instance().Open(
+      resolved_source, source_open_options, lldb::eFilePermissionsUserRW);
   if (!source_file)
     return Status::FromError(source_file.takeError());
   Status error;



More information about the lldb-commits mailing list