Skip to content
Merged
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
28 changes: 0 additions & 28 deletions stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
#include "swift/Runtime/Unreachable.h"
#include "swift/SwiftRemoteMirror/SwiftRemoteMirror.h"

#if defined(__APPLE__) && defined(__MACH__)
#include <mach-o/getsect.h>
#endif

using namespace swift;
using namespace swift::reflection;
using namespace swift::remote;
Expand Down Expand Up @@ -118,36 +114,12 @@ swift_reflection_addReflectionInfo(SwiftReflectionContextRef ContextRef,
Context->addReflectionInfo(*reinterpret_cast<ReflectionInfo *>(&Info));
}

#if defined(__APPLE__) && defined(__MACH__)
#ifndef __LP64__
typedef const struct mach_header MachHeader;
#else
typedef const struct mach_header_64 MachHeader;
#endif

template <typename Section>
static bool findSection(MachHeader *Header, const char *Name,
Section &Sect) {
unsigned long Size;
auto Address = getsectiondata(Header, "__TEXT", Name, &Size);
if (!Address)
return false;

Sect.section.Begin = Address;
auto End = reinterpret_cast<uintptr_t>(Address) + Size;
Sect.section.End = reinterpret_cast<void *>(End);
Sect.offset = 0;

return true;
}

int
swift_reflection_addImage(SwiftReflectionContextRef ContextRef,
swift_addr_t imageStart) {
auto Context = ContextRef->nativeContext;
return Context->addImage(RemoteAddress(imageStart));
}
#endif

int
swift_reflection_readIsaMask(SwiftReflectionContextRef ContextRef,
Expand Down
71 changes: 0 additions & 71 deletions tools/swift-reflection-dump/swift-reflection-dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
// binaries.
//===----------------------------------------------------------------------===//

// FIXME davidino: this needs to be included first to avoid textual
// replacement. It's silly and needs to be fixed.
#include "llvm/Object/MachO.h"

#include "swift/ABI/MetadataValues.h"
#include "swift/Demangling/Demangle.h"
#include "swift/Basic/LLVMInitialize.h"
Expand Down Expand Up @@ -83,73 +79,6 @@ static T unwrap(llvm::Expected<T> value) {
exit(EXIT_FAILURE);
}

static SectionRef getSectionRef(const ObjectFile *objectFile,
ArrayRef<StringRef> anySectionNames) {
for (auto section : objectFile->sections()) {
StringRef sectionName;
section.getName(sectionName);
for (auto desiredName : anySectionNames) {
if (sectionName.equals(desiredName)) {
return section;
}
}
}
return SectionRef();
}

template <typename Section>
static std::pair<Section, uintptr_t>
findReflectionSection(const ObjectFile *objectFile,
ArrayRef<StringRef> anySectionNames) {
auto sectionRef = getSectionRef(objectFile, anySectionNames);

if (sectionRef.getObject() == nullptr)
return {{nullptr, nullptr}, 0};

StringRef sectionContents;
sectionRef.getContents(sectionContents);

uintptr_t Offset = 0;
if (isa<ELFObjectFileBase>(sectionRef.getObject())) {
ELFSectionRef S{sectionRef};
Offset = sectionRef.getAddress() - S.getOffset();
}

return {{reinterpret_cast<const void *>(sectionContents.begin()),
reinterpret_cast<const void *>(sectionContents.end())},
Offset};
}

static ReflectionInfo findReflectionInfo(const ObjectFile *objectFile) {
auto fieldSection = findReflectionSection<FieldSection>(
objectFile, {"__swift5_fieldmd", ".swift5_fieldmd", "swift5_fieldmd"});
auto associatedTypeSection = findReflectionSection<AssociatedTypeSection>(
objectFile, {"__swift5_assocty", ".swift5_assocty", "swift5_assocty"});
auto builtinTypeSection = findReflectionSection<BuiltinTypeSection>(
objectFile, {"__swift5_builtin", ".swift5_builtin", "swift5_builtin"});
auto captureSection = findReflectionSection<CaptureSection>(
objectFile, {"__swift5_capture", ".swift5_capture", "swift5_capture"});
auto typeRefSection = findReflectionSection<GenericSection>(
objectFile, {"__swift5_typeref", ".swift5_typeref", "swift5_typeref"});
auto reflectionStringsSection = findReflectionSection<GenericSection>(
objectFile, {"__swift5_reflstr", ".swift5_reflstr", "swift5_reflstr"});

// The entire object file is mapped into this process's memory, so the
// local/remote mapping is identity.
auto startAddress = (uintptr_t)objectFile->getData().begin();

return {
{fieldSection.first, fieldSection.second},
{associatedTypeSection.first, associatedTypeSection.second},
{builtinTypeSection.first, builtinTypeSection.second},
{captureSection.first, captureSection.second},
{typeRefSection.first, typeRefSection.second},
{reflectionStringsSection.first, reflectionStringsSection.second},
/*LocalStartAddress*/ startAddress,
/*RemoteStartAddress*/ startAddress,
};
}

using NativeReflectionContext
= ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>;

Expand Down