Skip to content

Commit 363723e

Browse files
committed
[lldb/PlatformDarwin] Always delete destination file first in PutFile
Summary: The default behavior of Platform::PutFile is to open the file and truncate it if it already exists. This works fine and is a sensible default, but it interacts badly with code-signing on iOS, as doing so invalidates the signature of the file (even if the new content has a valid code signature). We have a couple tests which on purpose reload a different binary with the same name. Those tests are currently broken because of the above interaction. This patch simply makes the Darwin platform unconditionally delete the destination file before sending the new one to work around this issue. Reviewers: jasonmolenda Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D76450 (cherry picked from commit b6ae893)
1 parent 3b80523 commit 363723e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ PlatformDarwin::PlatformDarwin(bool is_host)
5858
/// inherited from by the plug-in instance.
5959
PlatformDarwin::~PlatformDarwin() {}
6060

61+
lldb_private::Status
62+
PlatformDarwin::PutFile(const lldb_private::FileSpec &source,
63+
const lldb_private::FileSpec &destination, uint32_t uid,
64+
uint32_t gid) {
65+
// Unconditionally unlink the destination. If it is an executable,
66+
// simply opening it and truncating its contents would invalidate
67+
// its cached code signature.
68+
Unlink(destination);
69+
return PlatformPOSIX::PutFile(source, destination, uid, gid);
70+
}
71+
6172
FileSpecList PlatformDarwin::LocateExecutableScriptingResources(
6273
Target *target, Module &module, Stream *feedback_stream) {
6374
FileSpecList file_list;

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class PlatformDarwin : public PlatformPOSIX {
2626

2727
~PlatformDarwin() override;
2828

29+
lldb_private::Status PutFile(const lldb_private::FileSpec &source,
30+
const lldb_private::FileSpec &destination,
31+
uint32_t uid = UINT32_MAX,
32+
uint32_t gid = UINT32_MAX) override;
33+
2934
// lldb_private::Platform functions
3035
lldb_private::Status
3136
ResolveSymbolFile(lldb_private::Target &target,

0 commit comments

Comments
 (0)