Skip to content

Commit 81ed148

Browse files
committed
Move some headers from runtime into include
1 parent 0c23901 commit 81ed148

17 files changed

+158
-129
lines changed

stdlib/public/runtime/ImageInspection.h renamed to include/swift/Runtime/ImageInspection.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define SWIFT_RUNTIME_IMAGEINSPECTION_H
2323

2424
#include "swift/Runtime/Config.h"
25+
#include "swift/Runtime/SymbolInfo.h"
2526

2627
#include <cstdint>
2728
#include <cstddef>
@@ -35,8 +36,6 @@
3536
#include <Windows.h>
3637
#endif
3738

38-
#include "SymbolInfo.h"
39-
4039
namespace swift {
4140

4241
/// Load the metadata from the image necessary to find protocols by name.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
//===--- ImageInspectionMachO.cpp - Mach-O image inspection ---------------===//
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+
/// This file includes routines that interact with dyld on Mach-O-based
16+
/// platforms to extract runtime metadata embedded in images generated by the
17+
/// Swift compiler.
18+
///
19+
//===----------------------------------------------------------------------===//
20+
21+
#ifndef SWIFT_RUNTIME_IMAGEINSPECTIONMACHO_H
22+
#define SWIFT_RUNTIME_IMAGEINSPECTIONMACHO_H
23+
24+
#if defined(__APPLE__) && defined(__MACH__) && \
25+
!defined(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)
26+
27+
#include "swift/Runtime/Config.h"
28+
#include "swift/Runtime/ImageInspection.h"
29+
#include "swift/Runtime/ImageInspectionCommon.h"
30+
#include <mach-o/dyld.h>
31+
#include <mach-o/getsect.h>
32+
#include <objc/runtime.h>
33+
#include <assert.h>
34+
#include <dlfcn.h>
35+
36+
namespace {
37+
38+
constexpr const char ProtocolsSection[] = MachOProtocolsSection;
39+
constexpr const char ProtocolConformancesSection[] =
40+
MachOProtocolConformancesSection;
41+
constexpr const char TypeMetadataRecordSection[] =
42+
MachOTypeMetadataRecordSection;
43+
constexpr const char DynamicReplacementSection[] =
44+
MachODynamicReplacementSection;
45+
constexpr const char DynamicReplacementSomeSection[] =
46+
MachODynamicReplacementSomeSection;
47+
constexpr const char AccessibleFunctionsSection[] =
48+
MachOAccessibleFunctionsSection;
49+
constexpr const char TextSegment[] = MachOTextSegment;
50+
51+
#if __POINTER_WIDTH__ == 64
52+
using mach_header_platform = mach_header_64;
53+
#else
54+
using mach_header_platform = mach_header;
55+
#endif
56+
57+
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
58+
void CONSUME_BLOCK(const void *baseAddress,
59+
const void *start, uintptr_t size)>
60+
void addImageCallback(const mach_header *mh) {
61+
#if __POINTER_WIDTH__ == 64
62+
assert(mh->magic == MH_MAGIC_64 && "loaded non-64-bit image?!");
63+
#endif
64+
65+
// Look for a __swift5_proto section.
66+
unsigned long size;
67+
const uint8_t *section =
68+
getsectiondata(reinterpret_cast<const mach_header_platform *>(mh),
69+
SEGMENT_NAME, SECTION_NAME,
70+
&size);
71+
72+
if (!section)
73+
return;
74+
75+
CONSUME_BLOCK(mh, section, size);
76+
}
77+
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
78+
void CONSUME_BLOCK(const void *baseAddress,
79+
const void *start, uintptr_t size)>
80+
void addImageCallback(const mach_header *mh, intptr_t vmaddr_slide) {
81+
addImageCallback<SEGMENT_NAME, SECTION_NAME, CONSUME_BLOCK>(mh);
82+
}
83+
84+
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
85+
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
86+
void CONSUME_BLOCK(const void *baseAddress,
87+
const void *start, uintptr_t size,
88+
const void *start2, uintptr_t size2)>
89+
void addImageCallback2Sections(const mach_header *mh) {
90+
#if __POINTER_WIDTH__ == 64
91+
assert(mh->magic == MH_MAGIC_64 && "loaded non-64-bit image?!");
92+
#endif
93+
94+
// Look for a section.
95+
unsigned long size;
96+
const uint8_t *section =
97+
getsectiondata(reinterpret_cast<const mach_header_platform *>(mh),
98+
SEGMENT_NAME, SECTION_NAME,
99+
&size);
100+
101+
if (!section)
102+
return;
103+
104+
// Look for another section.
105+
unsigned long size2;
106+
const uint8_t *section2 =
107+
getsectiondata(reinterpret_cast<const mach_header_platform *>(mh),
108+
SEGMENT_NAME2, SECTION_NAME2,
109+
&size2);
110+
if (!section2)
111+
size2 = 0;
112+
113+
CONSUME_BLOCK(mh, section, size, section2, size2);
114+
}
115+
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
116+
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
117+
void CONSUME_BLOCK(const void *baseAddress,
118+
const void *start, uintptr_t size,
119+
const void *start2, uintptr_t size2)>
120+
void addImageCallback2Sections(const mach_header *mh, intptr_t vmaddr_slide) {
121+
addImageCallback2Sections<SEGMENT_NAME, SECTION_NAME,
122+
SEGMENT_NAME2, SECTION_NAME2,
123+
CONSUME_BLOCK>(mh);
124+
}
125+
126+
} // end anonymous namespace
127+
128+
#if OBJC_ADDLOADIMAGEFUNC_DEFINED && SWIFT_OBJC_INTEROP
129+
#define REGISTER_FUNC(...) \
130+
if (__builtin_available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)) { \
131+
objc_addLoadImageFunc(__VA_ARGS__); \
132+
} else { \
133+
_dyld_register_func_for_add_image(__VA_ARGS__); \
134+
}
135+
#else
136+
#define REGISTER_FUNC(...) _dyld_register_func_for_add_image(__VA_ARGS__)
137+
#endif
138+
139+
#endif // defined(__APPLE__) && defined(__MACH__) &&
140+
// !defined(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)
141+
142+
#endif

stdlib/public/CompatibilityOverride/CompatibilityOverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#ifdef SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT
2020

21-
#include "../runtime/ImageInspection.h"
21+
#include "swift/Runtime/ImageInspection.h"
2222
#include "swift/Runtime/Once.h"
2323
#include <assert.h>
2424
#include <atomic>

stdlib/public/runtime/AccessibleFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#include "ImageInspection.h"
1817
#include "Private.h"
1918
#include "swift/Basic/Lazy.h"
2019
#include "swift/Demangling/Demangler.h"
2120
#include "swift/Runtime/AccessibleFunction.h"
2221
#include "swift/Runtime/Concurrent.h"
22+
#include "swift/Runtime/ImageInspection.h"
2323
#include "swift/Runtime/Metadata.h"
2424

2525
#include <cstdint>

stdlib/public/runtime/Errors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
#endif
3333
#include <stdarg.h>
3434

35-
#include "ImageInspection.h"
3635
#include "swift/Demangling/Demangle.h"
3736
#include "swift/Runtime/Debug.h"
37+
#include "swift/Runtime/ImageInspection.h"
3838
#include "swift/Runtime/Portability.h"
3939
#include "swift/Runtime/Win32.h"
4040
#include "swift/Threading/Errors.h"

stdlib/public/runtime/ImageInspectionCOFF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#if !defined(__ELF__) && !defined(__MACH__)
1414

15-
#include "ImageInspection.h"
15+
#include "swift/Runtime/ImageInspection.h"
1616

1717
#if defined(__CYGWIN__)
1818
#include <dlfcn.h>

stdlib/public/runtime/ImageInspectionCommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
#include "swift/shims/Visibility.h"
2525
#include "swift/shims/MetadataSections.h"
26-
#include "ImageInspection.h"
2726
#include "swift/Basic/Lazy.h"
2827
#include "swift/Runtime/Concurrent.h"
28+
#include "swift/Runtime/ImageInspection.h"
2929

3030
#include <algorithm>
3131
#include <atomic>

stdlib/public/runtime/ImageInspectionELF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020

2121
#if defined(__ELF__)
2222

23-
#include "ImageInspection.h"
23+
#include "swift/Runtime/ImageInspection.h"
2424

2525
#endif // defined(__ELF__)

stdlib/public/runtime/ImageInspectionMachO.cpp

Lines changed: 1 addition & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -21,120 +21,10 @@
2121
#if defined(__APPLE__) && defined(__MACH__) && \
2222
!defined(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)
2323

24-
#include "ImageInspection.h"
25-
#include "ImageInspectionCommon.h"
26-
#include "swift/Runtime/Config.h"
27-
#include <mach-o/dyld.h>
28-
#include <mach-o/getsect.h>
29-
#include <objc/runtime.h>
30-
#include <assert.h>
31-
#include <dlfcn.h>
24+
#include "swift/Runtime/ImageInspectionMachO.h"
3225

3326
using namespace swift;
3427

35-
namespace {
36-
37-
constexpr const char ProtocolsSection[] = MachOProtocolsSection;
38-
constexpr const char ProtocolConformancesSection[] =
39-
MachOProtocolConformancesSection;
40-
constexpr const char TypeMetadataRecordSection[] =
41-
MachOTypeMetadataRecordSection;
42-
constexpr const char DynamicReplacementSection[] =
43-
MachODynamicReplacementSection;
44-
constexpr const char DynamicReplacementSomeSection[] =
45-
MachODynamicReplacementSomeSection;
46-
constexpr const char AccessibleFunctionsSection[] =
47-
MachOAccessibleFunctionsSection;
48-
constexpr const char TextSegment[] = MachOTextSegment;
49-
50-
#if __POINTER_WIDTH__ == 64
51-
using mach_header_platform = mach_header_64;
52-
#else
53-
using mach_header_platform = mach_header;
54-
#endif
55-
56-
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
57-
void CONSUME_BLOCK(const void *baseAddress,
58-
const void *start, uintptr_t size)>
59-
void addImageCallback(const mach_header *mh) {
60-
#if __POINTER_WIDTH__ == 64
61-
assert(mh->magic == MH_MAGIC_64 && "loaded non-64-bit image?!");
62-
#endif
63-
64-
// Look for a __swift5_proto section.
65-
unsigned long size;
66-
const uint8_t *section =
67-
getsectiondata(reinterpret_cast<const mach_header_platform *>(mh),
68-
SEGMENT_NAME, SECTION_NAME,
69-
&size);
70-
71-
if (!section)
72-
return;
73-
74-
CONSUME_BLOCK(mh, section, size);
75-
}
76-
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
77-
void CONSUME_BLOCK(const void *baseAddress,
78-
const void *start, uintptr_t size)>
79-
void addImageCallback(const mach_header *mh, intptr_t vmaddr_slide) {
80-
addImageCallback<SEGMENT_NAME, SECTION_NAME, CONSUME_BLOCK>(mh);
81-
}
82-
83-
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
84-
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
85-
void CONSUME_BLOCK(const void *baseAddress,
86-
const void *start, uintptr_t size,
87-
const void *start2, uintptr_t size2)>
88-
void addImageCallback2Sections(const mach_header *mh) {
89-
#if __POINTER_WIDTH__ == 64
90-
assert(mh->magic == MH_MAGIC_64 && "loaded non-64-bit image?!");
91-
#endif
92-
93-
// Look for a section.
94-
unsigned long size;
95-
const uint8_t *section =
96-
getsectiondata(reinterpret_cast<const mach_header_platform *>(mh),
97-
SEGMENT_NAME, SECTION_NAME,
98-
&size);
99-
100-
if (!section)
101-
return;
102-
103-
// Look for another section.
104-
unsigned long size2;
105-
const uint8_t *section2 =
106-
getsectiondata(reinterpret_cast<const mach_header_platform *>(mh),
107-
SEGMENT_NAME2, SECTION_NAME2,
108-
&size2);
109-
if (!section2)
110-
size2 = 0;
111-
112-
CONSUME_BLOCK(mh, section, size, section2, size2);
113-
}
114-
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
115-
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
116-
void CONSUME_BLOCK(const void *baseAddress,
117-
const void *start, uintptr_t size,
118-
const void *start2, uintptr_t size2)>
119-
void addImageCallback2Sections(const mach_header *mh, intptr_t vmaddr_slide) {
120-
addImageCallback2Sections<SEGMENT_NAME, SECTION_NAME,
121-
SEGMENT_NAME2, SECTION_NAME2,
122-
CONSUME_BLOCK>(mh);
123-
}
124-
125-
} // end anonymous namespace
126-
127-
#if OBJC_ADDLOADIMAGEFUNC_DEFINED && SWIFT_OBJC_INTEROP
128-
#define REGISTER_FUNC(...) \
129-
if (__builtin_available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)) { \
130-
objc_addLoadImageFunc(__VA_ARGS__); \
131-
} else { \
132-
_dyld_register_func_for_add_image(__VA_ARGS__); \
133-
}
134-
#else
135-
#define REGISTER_FUNC(...) _dyld_register_func_for_add_image(__VA_ARGS__)
136-
#endif
137-
13828
// WARNING: the callbacks are called from unsafe contexts (with the dyld and
13929
// ObjC runtime locks held) and must be very careful in what they do. Locking
14030
// must be arranged to avoid deadlocks (other code must never call out to dyld

stdlib/public/runtime/ImageInspectionStatic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
#if defined(__MACH__) && defined(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)
2121

22-
#include "ImageInspection.h"
23-
#include "ImageInspectionCommon.h"
22+
#include "swift/Runtime/ImageInspection.h"
23+
#include "swift/Runtime/ImageInspectionCommon.h"
2424

2525
extern "C" const char __dso_handle[];
2626

stdlib/public/runtime/ImageInspectionWasm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
#if defined(__wasm__)
2020

21+
#include "swift/Runtime/ImageInspection.h"
2122
#include "swift/shims/MetadataSections.h"
22-
#include "ImageInspection.h"
2323

2424
using namespace swift;
2525

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "../CompatibilityOverride/CompatibilityOverride.h"
18-
#include "ImageInspection.h"
1918
#include "Private.h"
2019
#include "swift/ABI/TypeIdentity.h"
2120
#include "swift/Basic/Lazy.h"
@@ -27,6 +26,7 @@
2726
#include "swift/Runtime/Debug.h"
2827
#include "swift/Runtime/EnvironmentVariables.h"
2928
#include "swift/Runtime/HeapObject.h"
29+
#include "swift/Runtime/ImageInspection.h"
3030
#include "swift/Runtime/Metadata.h"
3131
#include "swift/Strings.h"
3232
#include "swift/Threading/Mutex.h"

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
#include "swift/Runtime/Concurrent.h"
2525
#include "swift/Runtime/EnvironmentVariables.h"
2626
#include "swift/Runtime/HeapObject.h"
27+
#include "swift/Runtime/ImageInspection.h"
2728
#include "swift/Runtime/Metadata.h"
2829
#include "swift/Basic/Unreachable.h"
2930
#include "llvm/ADT/DenseMap.h"
3031
#include "../CompatibilityOverride/CompatibilityOverride.h"
31-
#include "ImageInspection.h"
3232
#include "Private.h"
3333

3434
#include <new>

0 commit comments

Comments
 (0)