Skip to content

Commit 05ee723

Browse files
vivkongparkera
authored andcommitted
Support Linux on z (#386)
* Add support for Linux s390x, use the corresponding mapping table for big endian * Fix endianness issues in Foundation * Add s390x support in NSRange.swift
1 parent 841c604 commit 05ee723

File tree

8 files changed

+79
-22
lines changed

8 files changed

+79
-22
lines changed

CoreFoundation/Base.subproj/CFInternal.h

+20-19
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,13 @@ CF_PRIVATE Boolean __CFProcessIsRestricted();
343343
CF_EXPORT void * __CFConstantStringClassReferencePtr;
344344
CF_EXPORT void *__CFConstantStringClassReference[];
345345

346+
#if __CF_BIG_ENDIAN__
347+
#define CFINFO {0x00, 0x00, 0x07, 0xc8}
348+
#elif __CF_LITTLE_ENDIAN__
349+
#define CFINFO {0xc8, 0x07, 0x00, 0x00}
350+
#endif
351+
352+
346353
#ifdef __CONSTANT_CFSTRINGS__
347354

348355
#if DEPLOYMENT_RUNTIME_SWIFT
@@ -353,59 +360,53 @@ CF_EXPORT void *__CFConstantStringClassReference[];
353360
#define CONST_STRING_SECTION
354361
#endif
355362

363+
356364
// TODO: Pinned retain count for constants?
357365
#define CONST_STRING_DECL(S, V) \
358-
const struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
366+
const struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
359367
const CFStringRef S = (CFStringRef)&__##S;
360368

361369
#define PE_CONST_STRING_DECL(S, V) \
362-
const static struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
370+
const static struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
363371
CF_PRIVATE const CFStringRef S = (CFStringRef)&__##S;
364372

373+
365374
#else
366375

367376
#define CONST_STRING_DECL(S, V) \
368-
const struct __CFConstStr __##S = {{(uintptr_t)&__CFConstantStringClassReference, _CFSWIFT_RC_INIT {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
377+
const struct __CFConstStr __##S = {{(uintptr_t)&__CFConstantStringClassReference, _CFSWIFT_RC_INIT CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
369378
const CFStringRef S = (CFStringRef)&__##S;
370379

371380
#define PE_CONST_STRING_DECL(S, V) \
372-
const static struct __CFConstStr __##S = {{(uintptr_t)&__CFConstantStringClassReference, _CFSWIFT_RC_INIT {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
381+
const static struct __CFConstStr __##S = {{(uintptr_t)&__CFConstantStringClassReference, _CFSWIFT_RC_INIT CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
373382
CF_PRIVATE const CFStringRef S = (CFStringRef)&__##S;
374383

384+
375385
#endif
376386

377387
#else
378388

379389
struct CF_CONST_STRING {
380390
CFRuntimeBase _base;
381391
uint8_t *_ptr;
392+
#if defined(__LP64__) && defined(__BIG_ENDIAN__)
393+
uint64_t _length;
394+
#else
382395
uint32_t _length;
396+
#endif
383397
};
384398

385399
CF_EXPORT int __CFConstantStringClassReference[];
386400

387401
/* CFNetwork also has a copy of the CONST_STRING_DECL macro (for use on platforms without constant string support in cc); please warn cfnetwork-core@group.apple.com of any necessary changes to this macro. -- REW, 1/28/2002 */
388402

389-
#if __CF_BIG_ENDIAN__
390-
391-
#define CONST_STRING_DECL(S, V) \
392-
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0x00, 0x00, 0x07, 0xc8}}, (uint8_t *)V, sizeof(V) - 1}; \
393-
const CFStringRef S = (CFStringRef) & __ ## S ## __;
394-
#define PE_CONST_STRING_DECL(S, V) \
395-
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0x00, 0x00, 0x07, 0xc8}}, (uint8_t *)V, sizeof(V) - 1}; \
396-
CF_PRIVATE const CFStringRef S = (CFStringRef) & __ ## S ## __;
397-
398-
#elif __CF_LITTLE_ENDIAN__
399-
400403
#define CONST_STRING_DECL(S, V) \
401-
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
404+
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
402405
const CFStringRef S = (CFStringRef) & __ ## S ## __;
403406
#define PE_CONST_STRING_DECL(S, V) \
404-
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
407+
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
405408
CF_PRIVATE const CFStringRef S = (CFStringRef) & __ ## S ## __;
406409

407-
#endif
408-
409410
#endif // __CONSTANT_CFSTRINGS__
410411

411412
CF_EXPORT bool __CFOASafe;

CoreFoundation/Base.subproj/SwiftRuntime/TargetConditionals.h

+18
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#define TARGET_CPU_ARM64 0
108108
#define TARGET_CPU_MIPS 0
109109
#define TARGET_CPU_MIPS64 0
110+
#define TARGET_CPU_S390X 0
110111
#elif __arm64__ || __aarch64__
111112
#define TARGET_CPU_PPC 0
112113
#define TARGET_CPU_PPC64 0
@@ -116,6 +117,7 @@
116117
#define TARGET_CPU_ARM64 1
117118
#define TARGET_CPU_MIPS 0
118119
#define TARGET_CPU_MIPS64 0
120+
#define TARGET_CPU_S390X 0
119121
#elif __mips64__
120122
#define TARGET_CPU_PPC 0
121123
#define TARGET_CPU_PPC64 0
@@ -125,6 +127,7 @@
125127
#define TARGET_CPU_ARM64 0
126128
#define TARGET_CPU_MIPS 0
127129
#define TARGET_CPU_MIPS64 1
130+
#define TARGET_CPU_S390X 0
128131
#elif __powerpc64__
129132
#define TARGET_CPU_PPC 0
130133
#define TARGET_CPU_PPC64 1
@@ -134,6 +137,7 @@
134137
#define TARGET_CPU_ARM64 0
135138
#define TARGET_CPU_MIPS 0
136139
#define TARGET_CPU_MIPS64 0
140+
#define TARGET_CPU_S390X 0
137141
#elif __i386__
138142
#define TARGET_CPU_PPC 0
139143
#define TARGET_CPU_PPC64 0
@@ -143,6 +147,7 @@
143147
#define TARGET_CPU_ARM64 0
144148
#define TARGET_CPU_MIPS 0
145149
#define TARGET_CPU_MIPS64 0
150+
#define TARGET_CPU_S390X 0
146151
#elif __arm__
147152
#define TARGET_CPU_PPC 0
148153
#define TARGET_CPU_PPC64 0
@@ -152,6 +157,7 @@
152157
#define TARGET_CPU_ARM64 0
153158
#define TARGET_CPU_MIPS 0
154159
#define TARGET_CPU_MIPS64 0
160+
#define TARGET_CPU_S390X 0
155161
#elif __mips__
156162
#define TARGET_CPU_PPC 0
157163
#define TARGET_CPU_PPC64 0
@@ -161,6 +167,7 @@
161167
#define TARGET_CPU_ARM64 0
162168
#define TARGET_CPU_MIPS 1
163169
#define TARGET_CPU_MIPS64 0
170+
#define TARGET_CPU_S390X 0
164171
#elif __powerpc__
165172
#define TARGET_CPU_PPC 1
166173
#define TARGET_CPU_PPC64 0
@@ -170,6 +177,17 @@
170177
#define TARGET_CPU_ARM64 0
171178
#define TARGET_CPU_MIPS 0
172179
#define TARGET_CPU_MIPS64 0
180+
#define TARGET_CPU_S390X 0
181+
#elif __s390x__
182+
#define TARGET_CPU_PPC 0
183+
#define TARGET_CPU_PPC64 0
184+
#define TARGET_CPU_X86 0
185+
#define TARGET_CPU_X86_64 0
186+
#define TARGET_CPU_ARM 0
187+
#define TARGET_CPU_ARM64 0
188+
#define TARGET_CPU_MIPS 0
189+
#define TARGET_CPU_MIPS64 0
190+
#define TARGET_CPU_S390X 1
173191
#else
174192
#error unknown architecture
175193
#endif

CoreFoundation/String.subproj/CFString.h

+11
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ struct __CFConstStr {
165165
uint8_t _pad[4];
166166
} _base;
167167
uint8_t *_ptr;
168+
#if defined(__LP64__) && defined(__BIG_ENDIAN__)
169+
uint64_t _length;
170+
#else
168171
uint32_t _length;
172+
#endif
169173
};
170174

171175
#if DEPLOYMENT_TARGET_LINUX
@@ -174,10 +178,17 @@ struct __CFConstStr {
174178
#define CONST_STRING_LITERAL_SECTION
175179
#endif
176180

181+
#if __BIG_ENDIAN__
182+
#define CFSTR(cStr) ({ \
183+
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, {0x00, 0x00, 0x07, 0xc8}, {0x00, 0x00, 0x00, 0x00}}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
184+
(CFStringRef)&str; \
185+
})
186+
#else
177187
#define CFSTR(cStr) ({ \
178188
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, {0xc8, 0x07, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00}}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
179189
(CFStringRef)&str; \
180190
})
191+
#endif
181192

182193
#else
183194

CoreFoundation/String.subproj/CFUnicodeDataL.S CoreFoundation/String.subproj/CFUnicodeData.S

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
// This source file is part of the Swift.org open source project
22
//
3-
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
3+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
44
// Licensed under Apache License v2.0 with Runtime Library Exception
55
//
66
// See http://swift.org/LICENSE.txt for license information
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if defined(__BIG_ENDIAN__)
11+
.global __CFUnicodeDataB
12+
__CFUnicodeDataB:
13+
.incbin "CoreFoundation/CharacterSets/CFUnicodeData-B.mapping"
14+
15+
.global __CFUnicodeDataBEnd
16+
__CFUnicodeDataBEnd:
17+
.byte 0
18+
19+
.global __CFUnicodeDataBSize
20+
__CFUnicodeDataBSize:
21+
.int __CFUnicodeDataBEnd - __CFUnicodeDataB
22+
#else
1023
.global __CFUnicodeDataL
1124
__CFUnicodeDataL:
1225
.incbin "CoreFoundation/CharacterSets/CFUnicodeData-L.mapping"
@@ -18,3 +31,4 @@ __CFUnicodeDataLEnd:
1831
.global __CFUnicodeDataLSize
1932
__CFUnicodeDataLSize:
2033
.int __CFUnicodeDataLEnd - __CFUnicodeDataL
34+
#endif

CoreFoundation/StringEncodings.subproj/CFUniChar.c

+8
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,21 @@ static bool __CFUniCharLoadFile(const wchar_t *bitmapName, const void **bytes, i
320320
return *bytes ? true : false;
321321
#elif USE_RAW_SYMBOL
322322
extern void *__CFCharacterSetBitmapData;
323+
#if __CF_BIG_ENDIAN__
324+
extern void *__CFUnicodeDataB;
325+
#else
323326
extern void *__CFUnicodeDataL;
327+
#endif
324328
extern void *__CFUniCharPropertyDatabase;
325329

326330
if (strcmp(bitmapName, CF_UNICHAR_BITMAP_FILE) == 0) {
327331
*bytes = &__CFCharacterSetBitmapData;
328332
} else if (strcmp(bitmapName, MAPPING_TABLE_FILE) == 0) {
333+
#if __CF_BIG_ENDIAN__
334+
*bytes = &__CFUnicodeDataB;
335+
#else
329336
*bytes = &__CFUnicodeDataL;
337+
#endif
330338
} else if (strcmp(bitmapName, PROP_DB_FILE) == 0) {
331339
*bytes = &__CFUniCharPropertyDatabase;
332340
}

Foundation/NSRange.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ extension NSRange: NSSpecialValueCoding {
8989
static func objCType() -> String {
9090
#if arch(i386) || arch(arm)
9191
return "{_NSRange=II}"
92-
#elseif arch(x86_64) || arch(arm64)
92+
#elseif arch(x86_64) || arch(arm64) || arch(s390x)
9393
return "{_NSRange=QQ}"
9494
#else
9595
NSUnimplemented()

build.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
'CoreFoundation/URL.subproj/CFURLComponents.c',
260260
'CoreFoundation/URL.subproj/CFURLComponents_URIParser.c',
261261
'CoreFoundation/String.subproj/CFCharacterSetData.S',
262-
'CoreFoundation/String.subproj/CFUnicodeDataL.S',
262+
'CoreFoundation/String.subproj/CFUnicodeData.S',
263263
'CoreFoundation/String.subproj/CFUniCharPropertyDatabase.S',
264264
'CoreFoundation/String.subproj/CFRegularExpression.c',
265265
'CoreFoundation/String.subproj/CFAttributedString.c',

lib/target.py

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ArchType:
5252
kalimba = 38
5353
shave = 39
5454
armv6 = 40
55+
s390x = 41
5556
# Do not assume that these are 1:1 mapping. This should follow
5657
# canonical naming conventions for arm, etc. architectures.
5758
# See apple/swift PR #608
@@ -137,6 +138,8 @@ def to_string(value):
137138
return "kalimba"
138139
if value == ArchType.shave:
139140
return "shave"
141+
if value == ArchType.s390x:
142+
return "s390x"
140143
return "unknown"
141144
# Not 1:1, See to_string
142145
@staticmethod
@@ -227,6 +230,8 @@ def from_string(string):
227230
return ArchType.kalimba
228231
if string == "shave":
229232
return ArchType.shave
233+
if string == "s390x":
234+
return ArchType.s390x
230235

231236
return ArchType.UnknownArch
232237

0 commit comments

Comments
 (0)