@@ -49,7 +49,26 @@ enum _dyld_section_location_kind {
49
49
50
50
#endif
51
51
52
- #if !OBJC_ADDLOADIMAGEFUNC2_DEFINED
52
+ // Bring our own definition of _dyld_section_location constants in case we're
53
+ // using an older SDK that doesn't have them.
54
+ #define _dyld_section_location_text_swift5_protos 0
55
+ #define _dyld_section_location_text_swift5_proto 1
56
+ #define _dyld_section_location_text_swift5_types 2
57
+ #define _dyld_section_location_text_swift5_replace 3
58
+ #define _dyld_section_location_text_swift5_replace2 4
59
+ #define _dyld_section_location_text_swift5_ac_funcs 5
60
+
61
+ #if OBJC_ADDLOADIMAGEFUNC2_DEFINED
62
+ // Redefine _dyld_lookup_section_info as weak so we can build against it but
63
+ // still run when it's not present at runtime. Note that we don't have to check
64
+ // for its presence at runtime, as it's guaranteed to be available if we get
65
+ // the callbacks from objc_addLoadImageFunc2.
66
+ LLVM_ATTRIBUTE_WEAK
67
+ struct _dyld_section_info_result
68
+ _dyld_lookup_section_info (const struct mach_header *mh,
69
+ _dyld_section_location_info_t locationHandle,
70
+ enum _dyld_section_location_kind kind);
71
+ #else
53
72
// If we don't have objc_addLoadImageFunc2, fall back to objc_addLoadImageFunc.
54
73
// Use a #define so we don't have to conditionalize the calling code below.
55
74
#define objc_addLoadImageFunc2 objc_addLoadImageFunc
@@ -79,8 +98,7 @@ using mach_header_platform = mach_header;
79
98
#endif
80
99
81
100
// Callback for objc_addLoadImageFunc that just takes a mach_header.
82
- template <const char *SEGMENT_NAME, const char *SECTION_NAME,
83
- enum _dyld_section_location_kind SECTION_KIND,
101
+ template <const char *SEGMENT_NAME, const char *SECTION_NAME, int SECTION_KIND,
84
102
void CONSUME_BLOCK (const void *baseAddress, const void *start,
85
103
uintptr_t size)>
86
104
void addImageCallback(const mach_header *mh) {
@@ -102,8 +120,7 @@ void addImageCallback(const mach_header *mh) {
102
120
103
121
// Callback for objc_addLoadImageFunc2 that takes a mach_header and dyld info.
104
122
#if OBJC_ADDLOADIMAGEFUNC2_DEFINED
105
- template <const char *SEGMENT_NAME, const char *SECTION_NAME,
106
- enum _dyld_section_location_kind SECTION_KIND,
123
+ template <const char *SEGMENT_NAME, const char *SECTION_NAME, int SECTION_KIND,
107
124
void CONSUME_BLOCK (const void *baseAddress, const void *start,
108
125
uintptr_t size)>
109
126
void addImageCallback(const mach_header *mh,
@@ -112,16 +129,17 @@ void addImageCallback(const mach_header *mh,
112
129
assert (mh->magic == MH_MAGIC_64 && " loaded non-64-bit image?!" );
113
130
#endif
114
131
115
- auto result = _dyld_lookup_section_info (mh, dyldInfo, SECTION_KIND);
132
+ auto result = _dyld_lookup_section_info (
133
+ mh, dyldInfo,
134
+ static_cast <enum _dyld_section_location_kind>(SECTION_KIND));
116
135
if (result.buffer )
117
136
CONSUME_BLOCK (mh, result.buffer , result.bufferSize );
118
137
}
119
138
#endif
120
139
121
140
// Callback for _dyld_register_func_for_add_image that takes a mach_header and a
122
141
// slide.
123
- template <const char *SEGMENT_NAME, const char *SECTION_NAME,
124
- enum _dyld_section_location_kind SECTION_KIND,
142
+ template <const char *SEGMENT_NAME, const char *SECTION_NAME, int SECTION_KIND,
125
143
void CONSUME_BLOCK (const void *baseAddress, const void *start,
126
144
uintptr_t size)>
127
145
void addImageCallback(const mach_header *mh, intptr_t vmaddr_slide) {
@@ -132,11 +150,10 @@ void addImageCallback(const mach_header *mh, intptr_t vmaddr_slide) {
132
150
133
151
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
134
152
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
135
- enum _dyld_section_location_kind SECTION_KIND,
136
- enum _dyld_section_location_kind SECTION_KIND2,
137
- void CONSUME_BLOCK (const void *baseAddress,
138
- const void *start, uintptr_t size,
139
- const void *start2, uintptr_t size2)>
153
+ int SECTION_KIND, int SECTION_KIND2,
154
+ void CONSUME_BLOCK (const void *baseAddress, const void *start,
155
+ uintptr_t size, const void *start2,
156
+ uintptr_t size2)>
140
157
void addImageCallback2Sections(const mach_header *mh) {
141
158
#if __POINTER_WIDTH__ == 64
142
159
assert (mh->magic == MH_MAGIC_64 && " loaded non-64-bit image?!" );
@@ -168,23 +185,26 @@ void addImageCallback2Sections(const mach_header *mh) {
168
185
#if OBJC_ADDLOADIMAGEFUNC2_DEFINED
169
186
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
170
187
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
171
- enum _dyld_section_location_kind SECTION_KIND,
172
- enum _dyld_section_location_kind SECTION_KIND2,
173
- void CONSUME_BLOCK (const void *baseAddress,
174
- const void *start, uintptr_t size,
175
- const void *start2, uintptr_t size2)>
188
+ int SECTION_KIND, int SECTION_KIND2,
189
+ void CONSUME_BLOCK (const void *baseAddress, const void *start,
190
+ uintptr_t size, const void *start2,
191
+ uintptr_t size2)>
176
192
void addImageCallback2Sections(const mach_header *mh,
177
193
struct _dyld_section_location_info_s *dyldInfo) {
178
194
#if __POINTER_WIDTH__ == 64
179
195
assert (mh->magic == MH_MAGIC_64 && " loaded non-64-bit image?!" );
180
196
#endif
181
197
182
198
// Look for a section.
183
- auto result = _dyld_lookup_section_info (mh, dyldInfo, SECTION_KIND);
199
+ auto result = _dyld_lookup_section_info (
200
+ mh, dyldInfo,
201
+ static_cast <enum _dyld_section_location_kind>(SECTION_KIND));
184
202
if (!result.buffer )
185
203
return ;
186
204
187
- auto result2 = _dyld_lookup_section_info (mh, dyldInfo, SECTION_KIND2);
205
+ auto result2 = _dyld_lookup_section_info (
206
+ mh, dyldInfo,
207
+ static_cast <enum _dyld_section_location_kind>(SECTION_KIND2));
188
208
// No NULL check here, we allow this one not to be present. dyld gives us
189
209
// a NULL pointer and 0 size when the section isn't in the dylib so we don't
190
210
// need to zero anything out.
@@ -198,8 +218,7 @@ void addImageCallback2Sections(const mach_header *mh,
198
218
// slide.
199
219
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
200
220
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
201
- enum _dyld_section_location_kind SECTION_KIND,
202
- enum _dyld_section_location_kind SECTION_KIND2,
221
+ int SECTION_KIND, int SECTION_KIND2,
203
222
void CONSUME_BLOCK (const void *baseAddress, const void *start,
204
223
uintptr_t size, const void *start2,
205
224
uintptr_t size2)>
0 commit comments