Skip to content

[4.1] Revert "reflection: handle LMA != VMA for ELF" #13563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions include/swift/Reflection/Records.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class FieldRecord {
return MangledTypeName;
}

std::string getMangledTypeName(uintptr_t Offset) const {
return MangledTypeName.get() + Offset;
std::string getMangledTypeName() const {
return MangledTypeName.get();
}

std::string getFieldName(uintptr_t Offset) const {
std::string getFieldName() const {
if (FieldName)
return FieldName.get() + Offset;
return FieldName.get();
return "";
}

Expand Down Expand Up @@ -188,16 +188,16 @@ class FieldDescriptor {
return MangledTypeName;
}

std::string getMangledTypeName(uintptr_t Offset) const {
return MangledTypeName.get() + Offset;
std::string getMangledTypeName() const {
return MangledTypeName.get();
}

bool hasSuperclass() const {
return Superclass;
}

std::string getSuperclass(uintptr_t Offset) const {
return Superclass.get() + Offset;
std::string getSuperclass() const {
return Superclass.get();
}
};

Expand Down Expand Up @@ -241,12 +241,12 @@ class AssociatedTypeRecord {
const RelativeDirectPointer<const char> SubstitutedTypeName;

public:
std::string getName(uintptr_t Offset) const {
return Name.get() + Offset;
std::string getName() const {
return Name.get();
}

std::string getMangledSubstitutedTypeName(uintptr_t Offset) const {
return SubstitutedTypeName.get() + Offset;
std::string getMangledSubstitutedTypeName() const {
return SubstitutedTypeName.get();
}
};

Expand Down Expand Up @@ -319,12 +319,12 @@ struct AssociatedTypeDescriptor {
return const_iterator { End, End };
}

std::string getMangledProtocolTypeName(uintptr_t Offset) const {
return ProtocolTypeName.get() + Offset;
std::string getMangledProtocolTypeName() const {
return ProtocolTypeName.get();
}

std::string getMangledConformingTypeName(uintptr_t Offset) const {
return ConformingTypeName.get() + Offset;
std::string getMangledConformingTypeName() const {
return ConformingTypeName.get();
}
};

Expand Down Expand Up @@ -377,8 +377,8 @@ class BuiltinTypeDescriptor {
return TypeName;
}

std::string getMangledTypeName(uintptr_t Offset) const {
return TypeName.get() + Offset;
std::string getMangledTypeName() const {
return TypeName.get();
}
};

Expand Down Expand Up @@ -424,8 +424,8 @@ class CaptureTypeRecord {
return MangledTypeName;
}

std::string getMangledTypeName(uintptr_t Offset) const {
return MangledTypeName.get() + Offset;
std::string getMangledTypeName() const {
return MangledTypeName.get();
}
};

Expand Down Expand Up @@ -470,16 +470,16 @@ class MetadataSourceRecord {
return MangledTypeName;
}

std::string getMangledTypeName(uintptr_t Offset) const {
return MangledTypeName.get() + Offset;
std::string getMangledTypeName() const {
return MangledTypeName.get();
}

bool hasMangledMetadataSource() const {
return MangledMetadataSource;
}

std::string getMangledMetadataSource(uintptr_t Offset) const {
return MangledMetadataSource.get() + Offset;
std::string getMangledMetadataSource() const {
return MangledMetadataSource.get();
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/swift/Reflection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class ReflectionContext
if (CD == nullptr)
return nullptr;

auto Info = getBuilder().getClosureContextInfo(*CD, 0);
auto Info = getBuilder().getClosureContextInfo(*CD);

return getClosureContextInfo(ObjectAddress, Info);
}
Expand Down
45 changes: 9 additions & 36 deletions include/swift/Reflection/TypeRefBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,12 @@ using CaptureSection = ReflectionSection<CaptureDescriptorIterator>;
using GenericSection = ReflectionSection<const void *>;

struct ReflectionInfo {
struct {
FieldSection Metadata;
uintptr_t SectionOffset;
} Field;

struct {
AssociatedTypeSection Metadata;
uintptr_t SectionOffset;
} AssociatedType;

struct {
BuiltinTypeSection Metadata;
uintptr_t SectionOffset;
} Builtin;

struct {
CaptureSection Metadata;
uintptr_t SectionOffset;
} Capture;

struct {
GenericSection Metadata;
uintptr_t SectionOffset;
} TypeReference;

struct {
GenericSection Metadata;
uintptr_t SectionOffset;
} ReflectionString;

FieldSection fieldmd;
AssociatedTypeSection assocty;
BuiltinTypeSection builtin;
CaptureSection capture;
GenericSection typeref;
GenericSection reflstr;
uintptr_t LocalStartAddress;
uintptr_t RemoteStartAddress;
};
Expand Down Expand Up @@ -346,12 +322,10 @@ class TypeRefBuilder {
lookupSuperclass(const TypeRef *TR);

/// Load unsubstituted field types for a nominal type.
std::pair<const FieldDescriptor *, uintptr_t>
getFieldTypeInfo(const TypeRef *TR);
const FieldDescriptor *getFieldTypeInfo(const TypeRef *TR);

/// Get the parsed and substituted field types for a nominal type.
bool getFieldTypeRefs(const TypeRef *TR,
const std::pair<const FieldDescriptor *, uintptr_t> &FD,
bool getFieldTypeRefs(const TypeRef *TR, const FieldDescriptor *FD,
std::vector<FieldTypeInfo> &Fields);

/// Get the primitive type lowering for a builtin type.
Expand All @@ -362,8 +336,7 @@ class TypeRefBuilder {
const CaptureDescriptor *getCaptureDescriptor(uintptr_t RemoteAddress);

/// Get the unsubstituted capture types for a closure context.
ClosureContextInfo getClosureContextInfo(const CaptureDescriptor &CD,
uintptr_t Offset);
ClosureContextInfo getClosureContextInfo(const CaptureDescriptor &CD);

///
/// Dumping typerefs, field declarations, associated types
Expand Down
35 changes: 6 additions & 29 deletions include/swift/SwiftRemoteMirror/SwiftRemoteMirrorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,12 @@ typedef struct swift_reflection_section {
/// \brief Represents the set of Swift reflection sections of an image.
/// Not all sections may be present.
typedef struct swift_reflection_info {
struct {
swift_reflection_section_t section;
uintptr_t offset;
} field;

struct {
swift_reflection_section_t section;
uintptr_t offset;
} associated_types;

struct {
swift_reflection_section_t section;
uintptr_t offset;
} builtin_types;

struct {
swift_reflection_section_t section;
uintptr_t offset;
} capture;

struct {
swift_reflection_section_t section;
uintptr_t offset;
} type_references;

struct {
swift_reflection_section_t section;
uintptr_t offset;
} reflection_strings;
swift_reflection_section_t fieldmd;
swift_reflection_section_t assocty;
swift_reflection_section_t builtin;
swift_reflection_section_t capture;
swift_reflection_section_t typeref;
swift_reflection_section_t reflstr;

// Start address in local and remote address spaces.
uintptr_t LocalStartAddress;
Expand Down
37 changes: 17 additions & 20 deletions stdlib/public/Reflection/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ void TypeInfo::dump(std::ostream &OS, unsigned Indent) const {
}

BuiltinTypeInfo::BuiltinTypeInfo(const BuiltinTypeDescriptor *descriptor)
: TypeInfo(TypeInfoKind::Builtin, descriptor->Size, descriptor->Alignment,
descriptor->Stride, descriptor->NumExtraInhabitants),
Name(descriptor->getMangledTypeName(0)) {}
: TypeInfo(TypeInfoKind::Builtin,
descriptor->Size, descriptor->Alignment,
descriptor->Stride, descriptor->NumExtraInhabitants),
Name(descriptor->getMangledTypeName()) {}

/// Utility class for building values that contain witness tables.
class ExistentialTypeInfoBuilder {
Expand Down Expand Up @@ -236,15 +237,14 @@ class ExistentialTypeInfoBuilder {
}

for (auto *P : Protocols) {
const std::pair<const FieldDescriptor *, uintptr_t> FD =
TC.getBuilder().getFieldTypeInfo(P);
if (FD.first == nullptr) {
const FieldDescriptor *FD = TC.getBuilder().getFieldTypeInfo(P);
if (FD == nullptr) {
DEBUG(std::cerr << "No field descriptor: "; P->dump())
Invalid = true;
continue;
}

switch (FD.first->Kind) {
switch (FD->Kind) {
case FieldDescriptorKind::ObjCProtocol:
// Objective-C protocols do not have any witness tables.
ObjC = true;
Expand Down Expand Up @@ -298,16 +298,16 @@ class ExistentialTypeInfoBuilder {
Invalid = true;
continue;
}
const auto &FD = TC.getBuilder().getFieldTypeInfo(T);
if (FD.first == nullptr) {
auto *FD = TC.getBuilder().getFieldTypeInfo(T);
if (FD == nullptr) {
DEBUG(std::cerr << "No field descriptor: "; T->dump())
Invalid = true;
continue;
}

// We have a valid superclass constraint. It only affects
// lowering by class-constraining the entire existential.
switch (FD.first->Kind) {
switch (FD->Kind) {
case FieldDescriptorKind::Class:
Refcounting = ReferenceCounting::Native;
LLVM_FALLTHROUGH;
Expand Down Expand Up @@ -929,9 +929,7 @@ class EnumTypeInfoBuilder {
: TC(TC), Size(0), Alignment(1), NumExtraInhabitants(0),
Kind(RecordKind::Invalid), Invalid(false) {}

const TypeInfo *
build(const TypeRef *TR,
const std::pair<const FieldDescriptor *, uintptr_t> &FD) {
const TypeInfo *build(const TypeRef *TR, const FieldDescriptor *FD) {
// Sort enum into payload and no-payload cases.
unsigned NoPayloadCases = 0;
std::vector<FieldTypeInfo> PayloadCases;
Expand Down Expand Up @@ -1066,8 +1064,8 @@ class LowerType
}

const TypeInfo *visitAnyNominalTypeRef(const TypeRef *TR) {
const auto &FD = TC.getBuilder().getFieldTypeInfo(TR);
if (FD.first == nullptr) {
auto *FD = TC.getBuilder().getFieldTypeInfo(TR);
if (FD == nullptr) {
// Maybe this type is opaque -- look for a builtin
// descriptor to see if we at least know its size
// and alignment.
Expand All @@ -1079,7 +1077,7 @@ class LowerType
return nullptr;
}

switch (FD.first->Kind) {
switch (FD->Kind) {
case FieldDescriptorKind::Class:
// A value of class type is a single retainable pointer.
return TC.getReferenceTypeInfo(ReferenceKind::Strong,
Expand Down Expand Up @@ -1320,14 +1318,13 @@ const TypeInfo *TypeConverter::getTypeInfo(const TypeRef *TR) {

const TypeInfo *TypeConverter::getClassInstanceTypeInfo(const TypeRef *TR,
unsigned start) {
const std::pair<const FieldDescriptor *, uintptr_t> &FD =
getBuilder().getFieldTypeInfo(TR);
if (FD.first == nullptr) {
const FieldDescriptor *FD = getBuilder().getFieldTypeInfo(TR);
if (FD == nullptr) {
DEBUG(std::cerr << "No field descriptor: "; TR->dump());
return nullptr;
}

switch (FD.first->Kind) {
switch (FD->Kind) {
case FieldDescriptorKind::Class:
case FieldDescriptorKind::ObjCClass: {
// Lower the class's fields using substitutions from the
Expand Down
Loading