Skip to content

Commit 4fe16b8

Browse files
committed
[Runtime] Avoid referring to enum _dyld_section_location_kind.
If the SDK has dyld_priv.h but doesn't have enum _dyld_section_location_kind, we can't use enum _dyld_section_location_kind and it's hard to detect that. Instead, just use `int`, and use #defines for the values.
1 parent 68378b8 commit 4fe16b8

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

stdlib/public/runtime/ImageInspectionMachO.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,17 @@
3333
#if __has_include(<objc/objc-internal.h>) && __has_include(<mach-o/dyld_priv.h>)
3434
#include <mach-o/dyld_priv.h>
3535
#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-
5036
#endif
5137

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+
5247
#if !OBJC_ADDLOADIMAGEFUNC2_DEFINED
5348
// If we don't have objc_addLoadImageFunc2, fall back to objc_addLoadImageFunc.
5449
// Use a #define so we don't have to conditionalize the calling code below.
@@ -80,7 +75,7 @@ using mach_header_platform = mach_header;
8075

8176
// Callback for objc_addLoadImageFunc that just takes a mach_header.
8277
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
83-
enum _dyld_section_location_kind SECTION_KIND,
78+
int SECTION_KIND,
8479
void CONSUME_BLOCK(const void *baseAddress, const void *start,
8580
uintptr_t size)>
8681
void addImageCallback(const mach_header *mh) {
@@ -103,7 +98,7 @@ void addImageCallback(const mach_header *mh) {
10398
// Callback for objc_addLoadImageFunc2 that takes a mach_header and dyld info.
10499
#if OBJC_ADDLOADIMAGEFUNC2_DEFINED
105100
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
106-
enum _dyld_section_location_kind SECTION_KIND,
101+
int SECTION_KIND,
107102
void CONSUME_BLOCK(const void *baseAddress, const void *start,
108103
uintptr_t size)>
109104
void addImageCallback(const mach_header *mh,
@@ -121,7 +116,7 @@ void addImageCallback(const mach_header *mh,
121116
// Callback for _dyld_register_func_for_add_image that takes a mach_header and a
122117
// slide.
123118
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
124-
enum _dyld_section_location_kind SECTION_KIND,
119+
int SECTION_KIND,
125120
void CONSUME_BLOCK(const void *baseAddress, const void *start,
126121
uintptr_t size)>
127122
void addImageCallback(const mach_header *mh, intptr_t vmaddr_slide) {
@@ -132,8 +127,8 @@ void addImageCallback(const mach_header *mh, intptr_t vmaddr_slide) {
132127

133128
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
134129
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
135-
enum _dyld_section_location_kind SECTION_KIND,
136-
enum _dyld_section_location_kind SECTION_KIND2,
130+
int SECTION_KIND,
131+
int SECTION_KIND2,
137132
void CONSUME_BLOCK(const void *baseAddress,
138133
const void *start, uintptr_t size,
139134
const void *start2, uintptr_t size2)>
@@ -168,8 +163,8 @@ void addImageCallback2Sections(const mach_header *mh) {
168163
#if OBJC_ADDLOADIMAGEFUNC2_DEFINED
169164
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
170165
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
171-
enum _dyld_section_location_kind SECTION_KIND,
172-
enum _dyld_section_location_kind SECTION_KIND2,
166+
int SECTION_KIND,
167+
int SECTION_KIND2,
173168
void CONSUME_BLOCK(const void *baseAddress,
174169
const void *start, uintptr_t size,
175170
const void *start2, uintptr_t size2)>
@@ -198,8 +193,8 @@ void addImageCallback2Sections(const mach_header *mh,
198193
// slide.
199194
template <const char *SEGMENT_NAME, const char *SECTION_NAME,
200195
const char *SEGMENT_NAME2, const char *SECTION_NAME2,
201-
enum _dyld_section_location_kind SECTION_KIND,
202-
enum _dyld_section_location_kind SECTION_KIND2,
196+
int SECTION_KIND,
197+
int SECTION_KIND2,
203198
void CONSUME_BLOCK(const void *baseAddress, const void *start,
204199
uintptr_t size, const void *start2,
205200
uintptr_t size2)>

0 commit comments

Comments
 (0)