|
| 1 | +//===--- ImageInspectionStatic.cpp - image inspection for static stdlib ---===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +/// |
| 13 | +/// \file |
| 14 | +/// |
| 15 | +/// Implementation of ImageInspection for static stdlib (no dynamic loader |
| 16 | +/// present) environments. Assumes that only a single image exists in memory. |
| 17 | +/// |
| 18 | +//===----------------------------------------------------------------------===// |
| 19 | + |
| 20 | +#if defined(__MACH__) && defined(SWIFT_RUNTIME_MACHO_NO_DYLD) |
| 21 | + |
| 22 | +#include "ImageInspection.h" |
| 23 | +#include "ImageInspectionCommon.h" |
| 24 | + |
| 25 | +using namespace swift; |
| 26 | + |
| 27 | +#define GET_SECTION_START_AND_SIZE(start, size, _seg, _sec) \ |
| 28 | + extern void *__s##_seg##_sec __asm("section$start$" _seg "$" _sec); \ |
| 29 | + extern void *__e##_seg##_sec __asm("section$end$" _seg "$" _sec); \ |
| 30 | + start = &__s##_seg##_sec; \ |
| 31 | + size = (char *)&__e##_seg##_sec - (char *)&__s##_seg##_sec; |
| 32 | + |
| 33 | +void swift::initializeProtocolLookup() { |
| 34 | + void *start; |
| 35 | + uintptr_t size; |
| 36 | + GET_SECTION_START_AND_SIZE(start, size, TextSegment, ProtocolsSection); |
| 37 | + if (start == nullptr || size == 0) |
| 38 | + return; |
| 39 | + addImageProtocolsBlockCallbackUnsafe(start, size); |
| 40 | +} |
| 41 | + |
| 42 | +void swift::initializeProtocolConformanceLookup() { |
| 43 | + void *start; |
| 44 | + uintptr_t size; |
| 45 | + GET_SECTION_START_AND_SIZE(start, size, TextSegment, |
| 46 | + ProtocolConformancesSection); |
| 47 | + if (start == nullptr || size == 0) |
| 48 | + return; |
| 49 | + addImageProtocolConformanceBlockCallbackUnsafe(start, size); |
| 50 | +} |
| 51 | +void swift::initializeTypeMetadataRecordLookup() { |
| 52 | + void *start; |
| 53 | + uintptr_t size; |
| 54 | + GET_SECTION_START_AND_SIZE(start, size, TextSegment, |
| 55 | + TypeMetadataRecordSection); |
| 56 | + if (start == nullptr || size == 0) |
| 57 | + return; |
| 58 | + addImageTypeMetadataRecordBlockCallbackUnsafe(start, size); |
| 59 | +} |
| 60 | + |
| 61 | +void swift::initializeDynamicReplacementLookup() { |
| 62 | + void *start1; |
| 63 | + uintptr_t size1; |
| 64 | + GET_SECTION_START_AND_SIZE(start1, size1, TextSegment, |
| 65 | + DynamicReplacementSection); |
| 66 | + if (start1 == nullptr || size1 == 0) |
| 67 | + return; |
| 68 | + void *start2; |
| 69 | + uintptr_t size2; |
| 70 | + GET_SECTION_START_AND_SIZE(start2, size2, TextSegment, |
| 71 | + DynamicReplacementSection); |
| 72 | + if (start2 == nullptr || size2 == 0) |
| 73 | + return; |
| 74 | + addImageDynamicReplacementBlockCallback(start1, size1, start2, size2); |
| 75 | +} |
| 76 | + |
| 77 | +#endif // defined(__MACH__) && defined(SWIFT_RUNTIME_MACHO_NO_DYLD) |
0 commit comments