33
33
#if __has_include(<objc/objc-internal.h>) && __has_include(<mach-o/dyld_priv.h>)
34
34
#include < mach-o/dyld_priv.h>
35
35
#include < objc/objc-internal.h>
36
- #else
37
-
38
- // Bring our own definition of enum _dyld_section_location_kind and some of its
39
- // values. They'll be unused when we can't include dyld_priv.h, but the code
40
- // needs them in order to compile.
41
- enum _dyld_section_location_kind {
42
- _dyld_section_location_text_swift5_protos,
43
- _dyld_section_location_text_swift5_proto,
44
- _dyld_section_location_text_swift5_types,
45
- _dyld_section_location_text_swift5_replace,
46
- _dyld_section_location_text_swift5_replace2,
47
- _dyld_section_location_text_swift5_ac_funcs,
48
- };
49
-
50
36
#endif
51
37
38
+ // Bring our own definition of _dyld_section_location constants in case we're
39
+ // using an older SDK that doesn't have them.
40
+ #define _dyld_section_location_text_swift5_protos 0
41
+ #define _dyld_section_location_text_swift5_proto 1
42
+ #define _dyld_section_location_text_swift5_types 2
43
+ #define _dyld_section_location_text_swift5_replace 3
44
+ #define _dyld_section_location_text_swift5_replace2 4
45
+ #define _dyld_section_location_text_swift5_ac_funcs 5
46
+
52
47
#if !OBJC_ADDLOADIMAGEFUNC2_DEFINED
53
48
// If we don't have objc_addLoadImageFunc2, fall back to objc_addLoadImageFunc.
54
49
// Use a #define so we don't have to conditionalize the calling code below.
@@ -79,8 +74,7 @@ using mach_header_platform = mach_header;
79
74
#endif
80
75
81
76
// 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,
77
+ template <const char *SEGMENT_NAME, const char *SECTION_NAME, int SECTION_KIND,
84
78
void CONSUME_BLOCK (const void *baseAddress, const void *start,
85
79
uintptr_t size)>
86
80
void addImageCallback(const mach_header *mh) {
@@ -102,8 +96,7 @@ void addImageCallback(const mach_header *mh) {
102
96
103
97
// Callback for objc_addLoadImageFunc2 that takes a mach_header and dyld info.
104
98
#if OBJC_ADDLOADIMAGEFUNC2_DEFINED
105
- template <const char *SEGMENT_NAME, const char *SECTION_NAME,
106
- enum _dyld_section_location_kind SECTION_KIND,
99
+ template <const char *SEGMENT_NAME, const char *SECTION_NAME, int SECTION_KIND,
107
100
void CONSUME_BLOCK (const void *baseAddress, const void *start,
108
101
uintptr_t size)>
109
102
void addImageCallback(const mach_header *mh,
@@ -112,16 +105,17 @@ void addImageCallback(const mach_header *mh,
112
105
assert (mh->magic == MH_MAGIC_64 && " loaded non-64-bit image?!" );
113
106
#endif
114
107
115
- auto result = _dyld_lookup_section_info (mh, dyldInfo, SECTION_KIND);
108
+ auto result = _dyld_lookup_section_info (
109
+ mh, dyldInfo,
110
+ static_cast <enum _dyld_section_location_kind>(SECTION_KIND));
116
111
if (result.buffer )
117
112
CONSUME_BLOCK (mh, result.buffer , result.bufferSize );
118
113
}
119
114
#endif
120
115
121
116
// Callback for _dyld_register_func_for_add_image that takes a mach_header and a
122
117
// slide.
123
- template <const char *SEGMENT_NAME, const char *SECTION_NAME,
124
- enum _dyld_section_location_kind SECTION_KIND,
118
+ template <const char *SEGMENT_NAME, const char *SECTION_NAME, int SECTION_KIND,
125
119
void CONSUME_BLOCK (const void *baseAddress, const void *start,
126
120
uintptr_t size)>
127
121
void addImageCallback(const mach_header *mh, intptr_t vmaddr_slide) {
@@ -132,11 +126,10 @@ void addImageCallback(const mach_header *mh, intptr_t vmaddr_slide) {
132
126
133
127
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
134
128
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)>
129
+ int SECTION_KIND, int SECTION_KIND2,
130
+ void CONSUME_BLOCK (const void *baseAddress, const void *start,
131
+ uintptr_t size, const void *start2,
132
+ uintptr_t size2)>
140
133
void addImageCallback2Sections(const mach_header *mh) {
141
134
#if __POINTER_WIDTH__ == 64
142
135
assert (mh->magic == MH_MAGIC_64 && " loaded non-64-bit image?!" );
@@ -168,23 +161,26 @@ void addImageCallback2Sections(const mach_header *mh) {
168
161
#if OBJC_ADDLOADIMAGEFUNC2_DEFINED
169
162
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
170
163
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)>
164
+ int SECTION_KIND, int SECTION_KIND2,
165
+ void CONSUME_BLOCK (const void *baseAddress, const void *start,
166
+ uintptr_t size, const void *start2,
167
+ uintptr_t size2)>
176
168
void addImageCallback2Sections(const mach_header *mh,
177
169
struct _dyld_section_location_info_s *dyldInfo) {
178
170
#if __POINTER_WIDTH__ == 64
179
171
assert (mh->magic == MH_MAGIC_64 && " loaded non-64-bit image?!" );
180
172
#endif
181
173
182
174
// Look for a section.
183
- auto result = _dyld_lookup_section_info (mh, dyldInfo, SECTION_KIND);
175
+ auto result = _dyld_lookup_section_info (
176
+ mh, dyldInfo,
177
+ static_cast <enum _dyld_section_location_kind>(SECTION_KIND));
184
178
if (!result.buffer )
185
179
return ;
186
180
187
- auto result2 = _dyld_lookup_section_info (mh, dyldInfo, SECTION_KIND2);
181
+ auto result2 = _dyld_lookup_section_info (
182
+ mh, dyldInfo,
183
+ static_cast <enum _dyld_section_location_kind>(SECTION_KIND2));
188
184
// No NULL check here, we allow this one not to be present. dyld gives us
189
185
// a NULL pointer and 0 size when the section isn't in the dylib so we don't
190
186
// need to zero anything out.
@@ -198,8 +194,7 @@ void addImageCallback2Sections(const mach_header *mh,
198
194
// slide.
199
195
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
200
196
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
201
- enum _dyld_section_location_kind SECTION_KIND,
202
- enum _dyld_section_location_kind SECTION_KIND2,
197
+ int SECTION_KIND, int SECTION_KIND2,
203
198
void CONSUME_BLOCK (const void *baseAddress, const void *start,
204
199
uintptr_t size, const void *start2,
205
200
uintptr_t size2)>
0 commit comments