mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #22899 from drodriguez/reflection-context-fix-2
Reflection: try holding 32/64 address offset in target machine pointers.
This commit is contained in:
@@ -62,7 +62,6 @@ template <> struct ELFTraits<llvm::ELF::ELFCLASS32> {
|
||||
using Section = const struct llvm::ELF::Elf32_Shdr;
|
||||
using Offset = llvm::ELF::Elf32_Off;
|
||||
using Size = llvm::ELF::Elf32_Word;
|
||||
using Address = llvm::ELF::Elf32_Addr;
|
||||
static constexpr unsigned char ELFClass = llvm::ELF::ELFCLASS32;
|
||||
};
|
||||
|
||||
@@ -71,7 +70,6 @@ template <> struct ELFTraits<llvm::ELF::ELFCLASS64> {
|
||||
using Section = const struct llvm::ELF::Elf64_Shdr;
|
||||
using Offset = llvm::ELF::Elf64_Off;
|
||||
using Size = llvm::ELF::Elf64_Xword;
|
||||
using Address = llvm::ELF::Elf64_Addr;
|
||||
static constexpr unsigned char ELFClass = llvm::ELF::ELFCLASS64;
|
||||
};
|
||||
|
||||
@@ -204,7 +202,7 @@ public:
|
||||
RangeEnd - RangeStart);
|
||||
|
||||
auto findMachOSectionByName = [&](std::string Name)
|
||||
-> std::pair<std::pair<const char *, const char *>, uint32_t> {
|
||||
-> std::pair<std::pair<const char *, const char *>, uint64_t> {
|
||||
for (unsigned I = 0; I < NumSect; ++I) {
|
||||
auto S = reinterpret_cast<typename T::Section *>(
|
||||
SectionsBuf + (I * sizeof(typename T::Section)));
|
||||
@@ -235,8 +233,8 @@ public:
|
||||
ReflStrMdSec.first.first == nullptr)
|
||||
return false;
|
||||
|
||||
auto LocalStartAddress = reinterpret_cast<uintptr_t>(SectBuf.get());
|
||||
auto RemoteStartAddress = static_cast<uintptr_t>(RangeStart);
|
||||
auto LocalStartAddress = reinterpret_cast<uint64_t>(SectBuf.get());
|
||||
auto RemoteStartAddress = static_cast<uint64_t>(RangeStart);
|
||||
|
||||
ReflectionInfo info = {
|
||||
{{FieldMdSec.first.first, FieldMdSec.first.second}, 0},
|
||||
@@ -428,7 +426,7 @@ public:
|
||||
auto StrTab = reinterpret_cast<const char *>(StrTabBuf.get());
|
||||
|
||||
auto findELFSectionByName = [&](std::string Name)
|
||||
-> std::pair<std::pair<const char *, const char *>, typename T::Address> {
|
||||
-> std::pair<std::pair<const char *, const char *>, uint64_t> {
|
||||
// Now for all the sections, find their name.
|
||||
for (const typename T::Section *Hdr : SecHdrVec) {
|
||||
uint32_t Offset = Hdr->sh_name;
|
||||
@@ -463,9 +461,9 @@ public:
|
||||
ReflStrMdSec.first.first == nullptr)
|
||||
return false;
|
||||
|
||||
auto LocalStartAddress = reinterpret_cast<uintptr_t>(Buf.get());
|
||||
auto LocalStartAddress = reinterpret_cast<uint64_t>(Buf.get());
|
||||
auto RemoteStartAddress =
|
||||
static_cast<uintptr_t>(ImageStart.getAddressData());
|
||||
static_cast<uint64_t>(ImageStart.getAddressData());
|
||||
|
||||
ReflectionInfo info = {
|
||||
{{FieldMdSec.first.first, FieldMdSec.first.second}, FieldMdSec.second},
|
||||
|
||||
@@ -82,36 +82,36 @@ using GenericSection = ReflectionSection<const void *>;
|
||||
struct ReflectionInfo {
|
||||
struct {
|
||||
FieldSection Metadata;
|
||||
uintptr_t SectionOffset;
|
||||
uint64_t SectionOffset;
|
||||
} Field;
|
||||
|
||||
struct {
|
||||
AssociatedTypeSection Metadata;
|
||||
uintptr_t SectionOffset;
|
||||
uint64_t SectionOffset;
|
||||
} AssociatedType;
|
||||
|
||||
struct {
|
||||
BuiltinTypeSection Metadata;
|
||||
uintptr_t SectionOffset;
|
||||
uint64_t SectionOffset;
|
||||
} Builtin;
|
||||
|
||||
struct {
|
||||
CaptureSection Metadata;
|
||||
uintptr_t SectionOffset;
|
||||
uint64_t SectionOffset;
|
||||
} Capture;
|
||||
|
||||
struct {
|
||||
GenericSection Metadata;
|
||||
uintptr_t SectionOffset;
|
||||
uint64_t SectionOffset;
|
||||
} TypeReference;
|
||||
|
||||
struct {
|
||||
GenericSection Metadata;
|
||||
uintptr_t SectionOffset;
|
||||
uint64_t SectionOffset;
|
||||
} ReflectionString;
|
||||
|
||||
uintptr_t LocalStartAddress;
|
||||
uintptr_t RemoteStartAddress;
|
||||
uint64_t LocalStartAddress;
|
||||
uint64_t RemoteStartAddress;
|
||||
};
|
||||
|
||||
struct ClosureContextInfo {
|
||||
@@ -506,11 +506,11 @@ public:
|
||||
|
||||
/// Get the raw capture descriptor for a remote capture descriptor
|
||||
/// address.
|
||||
const CaptureDescriptor *getCaptureDescriptor(uintptr_t RemoteAddress);
|
||||
const CaptureDescriptor *getCaptureDescriptor(uint64_t RemoteAddress);
|
||||
|
||||
/// Get the unsubstituted capture types for a closure context.
|
||||
ClosureContextInfo getClosureContextInfo(const CaptureDescriptor &CD,
|
||||
uintptr_t Offset);
|
||||
uint64_t Offset);
|
||||
|
||||
///
|
||||
/// Dumping typerefs, field declarations, associated types
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uintptr_t swift_typeref_t;
|
||||
typedef uint64_t swift_typeref_t;
|
||||
|
||||
/// Represents one of the Swift reflection sections of an image.
|
||||
typedef struct swift_reflection_section {
|
||||
@@ -37,37 +37,37 @@ typedef struct swift_reflection_section {
|
||||
typedef struct swift_reflection_info {
|
||||
struct {
|
||||
swift_reflection_section_t section;
|
||||
uintptr_t offset;
|
||||
uint64_t offset;
|
||||
} field;
|
||||
|
||||
struct {
|
||||
swift_reflection_section_t section;
|
||||
uintptr_t offset;
|
||||
uint64_t offset;
|
||||
} associated_types;
|
||||
|
||||
struct {
|
||||
swift_reflection_section_t section;
|
||||
uintptr_t offset;
|
||||
uint64_t offset;
|
||||
} builtin_types;
|
||||
|
||||
struct {
|
||||
swift_reflection_section_t section;
|
||||
uintptr_t offset;
|
||||
uint64_t offset;
|
||||
} capture;
|
||||
|
||||
struct {
|
||||
swift_reflection_section_t section;
|
||||
uintptr_t offset;
|
||||
uint64_t offset;
|
||||
} type_references;
|
||||
|
||||
struct {
|
||||
swift_reflection_section_t section;
|
||||
uintptr_t offset;
|
||||
uint64_t offset;
|
||||
} reflection_strings;
|
||||
|
||||
// Start address in local and remote address spaces.
|
||||
uintptr_t LocalStartAddress;
|
||||
uintptr_t RemoteStartAddress;
|
||||
uint64_t LocalStartAddress;
|
||||
uint64_t RemoteStartAddress;
|
||||
} swift_reflection_info_t;
|
||||
|
||||
/// The layout kind of a Swift type.
|
||||
|
||||
@@ -31,9 +31,9 @@ TypeRefBuilder::getRemoteAddrOfTypeRefPointer(const void *pointer) {
|
||||
// Find what type ref section the pointer resides in, if any.
|
||||
const ReflectionInfo *containingInfo = nullptr;
|
||||
for (auto &info : ReflectionInfos) {
|
||||
auto start = (uintptr_t)info.TypeReference.Metadata.startAddress();
|
||||
auto size = (uintptr_t)info.TypeReference.Metadata.size();
|
||||
if (start <= (uintptr_t)pointer && (uintptr_t)pointer < start + size) {
|
||||
auto start = (uint64_t)info.TypeReference.Metadata.startAddress();
|
||||
auto size = (uint64_t)info.TypeReference.Metadata.size();
|
||||
if (start <= (uint64_t)pointer && (uint64_t)pointer < start + size) {
|
||||
containingInfo = &info;
|
||||
break;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ TypeRefBuilder::getRemoteAddrOfTypeRefPointer(const void *pointer) {
|
||||
if (!containingInfo)
|
||||
return 0;
|
||||
|
||||
return (uintptr_t)pointer
|
||||
return (uint64_t)pointer
|
||||
+ containingInfo->RemoteStartAddress
|
||||
- containingInfo->LocalStartAddress
|
||||
+ containingInfo->TypeReference.SectionOffset;
|
||||
@@ -86,9 +86,9 @@ lookupTypeWitness(const std::string &MangledTypeName,
|
||||
// Cache missed - we need to look through all of the assocty sections
|
||||
// for all images that we've been notified about.
|
||||
for (auto &Info : ReflectionInfos) {
|
||||
uintptr_t TypeRefOffset = Info.AssociatedType.SectionOffset
|
||||
uint64_t TypeRefOffset = Info.AssociatedType.SectionOffset
|
||||
- Info.TypeReference.SectionOffset;
|
||||
uintptr_t NameOffset = Info.AssociatedType.SectionOffset
|
||||
uint64_t NameOffset = Info.AssociatedType.SectionOffset
|
||||
- Info.ReflectionString.SectionOffset;
|
||||
for (const auto &AssocTyDescriptor : Info.AssociatedType.Metadata) {
|
||||
if (!reflectionNameMatches(Dem,
|
||||
@@ -158,7 +158,7 @@ TypeRefBuilder::getFieldTypeInfo(const TypeRef *TR) {
|
||||
// On failure, fill out the cache with everything we know about.
|
||||
std::vector<std::pair<std::string, const TypeRef *>> Fields;
|
||||
for (auto &Info : ReflectionInfos) {
|
||||
uintptr_t TypeRefOffset = Info.Field.SectionOffset
|
||||
uint64_t TypeRefOffset = Info.Field.SectionOffset
|
||||
- Info.TypeReference.SectionOffset;
|
||||
for (auto &FD : Info.Field.Metadata) {
|
||||
if (!FD.hasMangledTypeName())
|
||||
@@ -232,7 +232,7 @@ TypeRefBuilder::getBuiltinTypeInfo(const TypeRef *TR) {
|
||||
return nullptr;
|
||||
|
||||
for (auto Info : ReflectionInfos) {
|
||||
uintptr_t TypeRefOffset = Info.Builtin.SectionOffset
|
||||
uint64_t TypeRefOffset = Info.Builtin.SectionOffset
|
||||
- Info.TypeReference.SectionOffset;
|
||||
for (auto &BuiltinTypeDescriptor : Info.Builtin.Metadata) {
|
||||
assert(BuiltinTypeDescriptor.Size > 0);
|
||||
@@ -252,10 +252,10 @@ TypeRefBuilder::getBuiltinTypeInfo(const TypeRef *TR) {
|
||||
}
|
||||
|
||||
const CaptureDescriptor *
|
||||
TypeRefBuilder::getCaptureDescriptor(uintptr_t RemoteAddress) {
|
||||
TypeRefBuilder::getCaptureDescriptor(uint64_t RemoteAddress) {
|
||||
for (auto Info : ReflectionInfos) {
|
||||
for (auto &CD : Info.Capture.Metadata) {
|
||||
auto OtherAddr = (reinterpret_cast<uintptr_t>(&CD) -
|
||||
auto OtherAddr = (reinterpret_cast<uint64_t>(&CD) -
|
||||
Info.LocalStartAddress + Info.RemoteStartAddress);
|
||||
if (OtherAddr == RemoteAddress)
|
||||
return &CD;
|
||||
@@ -268,7 +268,7 @@ TypeRefBuilder::getCaptureDescriptor(uintptr_t RemoteAddress) {
|
||||
/// Get the unsubstituted capture types for a closure context.
|
||||
ClosureContextInfo
|
||||
TypeRefBuilder::getClosureContextInfo(const CaptureDescriptor &CD,
|
||||
uintptr_t TypeRefOffset) {
|
||||
uint64_t TypeRefOffset) {
|
||||
ClosureContextInfo Info;
|
||||
|
||||
for (auto i = CD.capture_begin(), e = CD.capture_end(); i != e; ++i) {
|
||||
@@ -326,9 +326,9 @@ TypeRefBuilder::dumpTypeRef(StringRef MangledName,
|
||||
|
||||
void TypeRefBuilder::dumpFieldSection(std::ostream &OS) {
|
||||
for (const auto §ions : ReflectionInfos) {
|
||||
uintptr_t TypeRefOffset = sections.Field.SectionOffset
|
||||
uint64_t TypeRefOffset = sections.Field.SectionOffset
|
||||
- sections.TypeReference.SectionOffset;
|
||||
uintptr_t NameOffset = sections.Field.SectionOffset
|
||||
uint64_t NameOffset = sections.Field.SectionOffset
|
||||
- sections.ReflectionString.SectionOffset;
|
||||
for (const auto &descriptor : sections.Field.Metadata) {
|
||||
auto TypeDemangling = Dem.demangleType(
|
||||
@@ -354,9 +354,9 @@ void TypeRefBuilder::dumpFieldSection(std::ostream &OS) {
|
||||
|
||||
void TypeRefBuilder::dumpAssociatedTypeSection(std::ostream &OS) {
|
||||
for (const auto §ions : ReflectionInfos) {
|
||||
uintptr_t TypeRefOffset = sections.AssociatedType.SectionOffset
|
||||
uint64_t TypeRefOffset = sections.AssociatedType.SectionOffset
|
||||
- sections.TypeReference.SectionOffset;
|
||||
uintptr_t NameOffset = sections.AssociatedType.SectionOffset
|
||||
uint64_t NameOffset = sections.AssociatedType.SectionOffset
|
||||
- sections.ReflectionString.SectionOffset;
|
||||
for (const auto &descriptor : sections.AssociatedType.Metadata) {
|
||||
auto conformingTypeNode = Dem.demangleType(
|
||||
@@ -381,7 +381,7 @@ void TypeRefBuilder::dumpAssociatedTypeSection(std::ostream &OS) {
|
||||
|
||||
void TypeRefBuilder::dumpBuiltinTypeSection(std::ostream &OS) {
|
||||
for (const auto §ions : ReflectionInfos) {
|
||||
uintptr_t TypeRefOffset = sections.Builtin.SectionOffset
|
||||
uint64_t TypeRefOffset = sections.Builtin.SectionOffset
|
||||
- sections.TypeReference.SectionOffset;
|
||||
for (const auto &descriptor : sections.Builtin.Metadata) {
|
||||
auto typeName =
|
||||
@@ -426,7 +426,7 @@ void ClosureContextInfo::dump(std::ostream &OS) const {
|
||||
|
||||
void TypeRefBuilder::dumpCaptureSection(std::ostream &OS) {
|
||||
for (const auto §ions : ReflectionInfos) {
|
||||
uintptr_t TypeRefOffset = sections.Capture.SectionOffset
|
||||
uint64_t TypeRefOffset = sections.Capture.SectionOffset
|
||||
- sections.TypeReference.SectionOffset;
|
||||
for (const auto &descriptor : sections.Capture.Metadata) {
|
||||
auto info = getClosureContextInfo(descriptor, TypeRefOffset);
|
||||
|
||||
Reference in New Issue
Block a user