Merge pull request #85195 from augusto2112/remote-mirr-indirect-addr-6.2

[RemoteMirrors] Add hook for resolving indirect addresses
This commit is contained in:
Adrian Prantl
2025-10-31 13:58:10 -07:00
committed by GitHub
2 changed files with 23 additions and 5 deletions

View File

@@ -121,6 +121,20 @@ public:
return ReadObjResult<T>(reinterpret_cast<const T *>(ptr), deleter);
}
/// Resolves an indirect address at the given relative offset.
///
/// \param address The base address which contains the relative offset.
/// \param offset The offset read.
/// \param directnessEncodedInOffset Whether the relative offset encodes the
/// directness as the last bit. Note that this is not the offset passed in as
/// a parameter, but whether the offset read at address would have the last
/// bit set.
virtual RemoteAddress
resolveIndirectAddressAtOffset(RemoteAddress address, uint64_t offset,
bool directnessEncodedInOffset) {
return address + offset;
}
/// Attempts to read 'size' bytes from the given address in the remote process.
///
/// Returns a pointer to the requested data and a function that must be called to

View File

@@ -461,18 +461,20 @@ public:
swift::Demangle::NodePointer {
// Resolve the reference to a remote address.
auto offsetInMangledName =
(const char *)base - mangledName.getLocalBuffer();
auto remoteAddress =
mangledName.getRemoteAddress() + offsetInMangledName + offset;
(const char *)base - mangledName.getLocalBuffer();
auto offsetAddress = mangledName.getRemoteAddress() + offsetInMangledName;
RemoteAbsolutePointer resolved;
if (directness == Directness::Indirect) {
auto remoteAddress = Reader->resolveIndirectAddressAtOffset(
offsetAddress, offset, /*directnessEncodedInOffset=*/false);
if (auto indirectAddress = readPointer(remoteAddress)) {
resolved = stripSignedPointer(*indirectAddress);
} else {
return nullptr;
}
} else {
auto remoteAddress = offsetAddress + offset;
resolved = Reader->getSymbol(remoteAddress);
}
@@ -2078,17 +2080,19 @@ protected:
using SignedPointer = typename std::make_signed<StoredPointer>::type;
RemoteAddress resultAddress = getAddress(fieldRef) + (SignedPointer)offset;
// Low bit set in the offset indicates that the offset leads to the absolute
// address in memory.
if (indirect) {
RemoteAddress resultAddress = Reader->resolveIndirectAddressAtOffset(
getAddress(fieldRef), (SignedPointer)offset,
/*directnessEncodedInOffset=*/true);
if (auto ptr = readPointer(resultAddress)) {
return stripSignedPointer(*ptr);
}
return std::nullopt;
}
RemoteAddress resultAddress = getAddress(fieldRef) + (SignedPointer)offset;
return RemoteAbsolutePointer(resultAddress);
}