From 862711616d310dba71be3825d95d0b68d33f8091 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Fri, 20 Jul 2018 11:32:46 -0700 Subject: [PATCH 1/2] [swift-reflection-dump] Garbage collect dead code. Now that the API is fully transparent and works both with ELF and MachO, clients don't need to worry about object format details anymore. --- .../swift-reflection-dump.cpp | 71 ------------------- 1 file changed, 71 deletions(-) diff --git a/tools/swift-reflection-dump/swift-reflection-dump.cpp b/tools/swift-reflection-dump/swift-reflection-dump.cpp index 65077fc27d256..d8e8eb1f50987 100644 --- a/tools/swift-reflection-dump/swift-reflection-dump.cpp +++ b/tools/swift-reflection-dump/swift-reflection-dump.cpp @@ -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" @@ -83,73 +79,6 @@ static T unwrap(llvm::Expected value) { exit(EXIT_FAILURE); } -static SectionRef getSectionRef(const ObjectFile *objectFile, - ArrayRef anySectionNames) { - for (auto section : objectFile->sections()) { - StringRef sectionName; - section.getName(sectionName); - for (auto desiredName : anySectionNames) { - if (sectionName.equals(desiredName)) { - return section; - } - } - } - return SectionRef(); -} - -template -static std::pair -findReflectionSection(const ObjectFile *objectFile, - ArrayRef 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(sectionRef.getObject())) { - ELFSectionRef S{sectionRef}; - Offset = sectionRef.getAddress() - S.getOffset(); - } - - return {{reinterpret_cast(sectionContents.begin()), - reinterpret_cast(sectionContents.end())}, - Offset}; -} - -static ReflectionInfo findReflectionInfo(const ObjectFile *objectFile) { - auto fieldSection = findReflectionSection( - objectFile, {"__swift5_fieldmd", ".swift5_fieldmd", "swift5_fieldmd"}); - auto associatedTypeSection = findReflectionSection( - objectFile, {"__swift5_assocty", ".swift5_assocty", "swift5_assocty"}); - auto builtinTypeSection = findReflectionSection( - objectFile, {"__swift5_builtin", ".swift5_builtin", "swift5_builtin"}); - auto captureSection = findReflectionSection( - objectFile, {"__swift5_capture", ".swift5_capture", "swift5_capture"}); - auto typeRefSection = findReflectionSection( - objectFile, {"__swift5_typeref", ".swift5_typeref", "swift5_typeref"}); - auto reflectionStringsSection = findReflectionSection( - 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>>; From 0e5fa49b5329ed73eb6675b038a9c056525e6590 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Fri, 20 Jul 2018 12:49:16 -0700 Subject: [PATCH 2/2] [stdlib] Remove dead code in SwiftRemoteMirror. --- .../SwiftRemoteMirror/SwiftRemoteMirror.cpp | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp b/stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp index afe8ff9effff7..441736e080dea 100644 --- a/stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp +++ b/stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp @@ -16,10 +16,6 @@ #include "swift/Runtime/Unreachable.h" #include "swift/SwiftRemoteMirror/SwiftRemoteMirror.h" -#if defined(__APPLE__) && defined(__MACH__) -#include -#endif - using namespace swift; using namespace swift::reflection; using namespace swift::remote; @@ -118,36 +114,12 @@ swift_reflection_addReflectionInfo(SwiftReflectionContextRef ContextRef, Context->addReflectionInfo(*reinterpret_cast(&Info)); } -#if defined(__APPLE__) && defined(__MACH__) -#ifndef __LP64__ -typedef const struct mach_header MachHeader; -#else -typedef const struct mach_header_64 MachHeader; -#endif - -template -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(Address) + Size; - Sect.section.End = reinterpret_cast(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,