-
-
Save spevans/17d01a687c0648a8adc5021029b6d648 to your computer and use it in GitHub Desktop.
Example change to support static conformance and metatype data sections (rough patch with excess debug)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/stdlib/public/runtime/MetadataLookup.cpp b/stdlib/public/runtime/MetadataLookup.cpp | |
index 5822a93..7f1ac5c 100644 | |
--- a/stdlib/public/runtime/MetadataLookup.cpp | |
+++ b/stdlib/public/runtime/MetadataLookup.cpp | |
@@ -92,10 +92,14 @@ namespace { | |
#if defined(__APPLE__) && defined(__MACH__) | |
static void _initializeCallbacksToInspectDylib(); | |
#else | |
+ | |
+const void *__swift2_type_metadata_start = NULL; | |
+ | |
namespace swift { | |
void _swift_initializeCallbacksToInspectDylib( | |
void (*fnAddImageBlock)(const uint8_t *, size_t), | |
- const char *sectionName); | |
+ const char *sectionName, | |
+ const void **sectionDataAddr); | |
} | |
static void _addImageTypeMetadataRecordsBlock(const uint8_t *records, | |
@@ -114,7 +118,8 @@ struct TypeMetadataState { | |
#else | |
_swift_initializeCallbacksToInspectDylib( | |
_addImageTypeMetadataRecordsBlock, | |
- SWIFT_TYPE_METADATA_SECTION); | |
+ SWIFT_TYPE_METADATA_SECTION, | |
+ &__swift2_type_metadata_start); | |
#endif | |
} | |
diff --git a/stdlib/public/runtime/ProtocolConformance.cpp b/stdlib/public/runtime/ProtocolConformance.cpp | |
index 4ac9ad9..b9c2515 100644 | |
--- a/stdlib/public/runtime/ProtocolConformance.cpp | |
+++ b/stdlib/public/runtime/ProtocolConformance.cpp | |
@@ -235,10 +235,14 @@ namespace { | |
#if defined(__APPLE__) && defined(__MACH__) | |
static void _initializeCallbacksToInspectDylib(); | |
#else | |
+ | |
+const void *__swift2_protocol_conformances_start = NULL; | |
+ | |
namespace swift { | |
void _swift_initializeCallbacksToInspectDylib( | |
void (*fnAddImageBlock)(const uint8_t *, size_t), | |
- const char *sectionName); | |
+ const char *sectionName, | |
+ const void **sectionDataAddr); | |
} | |
static void _addImageProtocolConformancesBlock(const uint8_t *conformances, | |
@@ -257,7 +261,8 @@ struct ConformanceState { | |
#else | |
_swift_initializeCallbacksToInspectDylib( | |
_addImageProtocolConformancesBlock, | |
- SWIFT_PROTOCOL_CONFORMANCES_SECTION); | |
+ SWIFT_PROTOCOL_CONFORMANCES_SECTION, | |
+ &__swift2_protocol_conformances_start); | |
#endif | |
} | |
@@ -393,7 +398,23 @@ static int _addImageProtocolConformances(struct dl_phdr_info *info, | |
void swift::_swift_initializeCallbacksToInspectDylib( | |
void (*fnAddImageBlock)(const uint8_t *, size_t), | |
- const char *sectionName) { | |
+ const char *sectionName, | |
+ const void **sectionDataAddr) { | |
+ | |
+ fprintf(stderr, "sectionName: %s sectionDataAddr: %p *sectionDataAddr: %p\n", | |
+ sectionName, sectionDataAddr, | |
+ sectionDataAddr ? *sectionDataAddr : NULL); | |
+ | |
+ if (*sectionDataAddr) { | |
+ auto blockAddr = reinterpret_cast<const uint8_t*>(sectionDataAddr); | |
+ auto blockSize = *reinterpret_cast<const uint64_t*>(blockAddr); | |
+ blockAddr += sizeof(blockSize); | |
+ fprintf(stderr, "Static binary Adding blockAddr: %p, blockSize: %ld\n", | |
+ blockAddr, blockSize); | |
+ fnAddImageBlock(blockAddr, blockSize); | |
+ return; | |
+ } | |
+ fprintf(stderr, "Dynamic binary, using dl_iterate_phdr\n"); | |
InspectArgs inspectArgs = {fnAddImageBlock, sectionName}; | |
// Search the loaded dls. Unlike the above, this only searches the already | |
@@ -440,7 +461,8 @@ static int _addImageProtocolConformances(struct dl_phdr_info *info, | |
void swift::_swift_initializeCallbacksToInspectDylib( | |
void (*fnAddImageBlock)(const uint8_t *, size_t), | |
- const char *sectionName) { | |
+ const char *sectionName, | |
+ const void **sectionDataAddr) { | |
InspectArgs inspectArgs = {fnAddImageBlock, sectionName}; | |
_swift_dl_iterate_phdr(_addImageProtocolConformances, &inspectArgs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment