Skip to content

Add support for compiler-managed CFSTR() on non-Darwin systems #1735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CoreFoundation/Base.subproj/CFInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ CF_PRIVATE Boolean __CFProcessIsRestricted(void);

CF_EXPORT void * __CFConstantStringClassReferencePtr;

#if DEPLOYMENT_RUNTIME_SWIFT
#if DEPLOYMENT_RUNTIME_SWIFT && TARGET_OS_MAC

#if DEPLOYMENT_TARGET_LINUX
#define CONST_STRING_SECTION __attribute__((section(".cfstr.data")))
Expand Down
6 changes: 6 additions & 0 deletions CoreFoundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ target_compile_options(CoreFoundation
-fconstant-cfstrings
-fdollars-in-identifiers
-fexceptions)
if(CF_DEPLOYMENT_SWIFT)
target_compile_options(CoreFoundation
PRIVATE
-fcf-runtime-abi=swift)
endif()

target_compile_options(CoreFoundation
PRIVATE
-Wno-shorten-64-to-32
Expand Down
22 changes: 9 additions & 13 deletions CoreFoundation/String.subproj/CFString.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,16 @@ since it is the default choice with Mac OS X developer tools.
#endif

#if DEPLOYMENT_RUNTIME_SWIFT
#if TARGET_OS_MAC
#define _CF_CONSTANT_STRING_SWIFT_CLASS $s15SwiftFoundation19_NSCFConstantStringCN
#else
#define _CF_CONSTANT_STRING_SWIFT_CLASS $s10Foundation19_NSCFConstantStringCN
#endif

#if TARGET_OS_MAC
#define _CF_CONSTANT_STRING_SWIFT_CLASS $s15SwiftFoundation19_NSCFConstantStringCN
#else
#define _CF_CONSTANT_STRING_SWIFT_CLASS $s10Foundation19_NSCFConstantStringCN
CF_EXPORT void *_CF_CONSTANT_STRING_SWIFT_CLASS[];
#endif

CF_EXPORT void *_CF_CONSTANT_STRING_SWIFT_CLASS[];
#if DEPLOYMENT_RUNTIME_SWIFT && TARGET_OS_MAC

struct __CFConstStr {
struct {
Expand All @@ -175,20 +177,14 @@ struct __CFConstStr {
#endif // defined(__LP64__) || defined(__LLP64__)
};

#if TARGET_OS_LINUX
#define CONST_STRING_LITERAL_SECTION __attribute__((section(".cfstrlit.data")))
#else
#define CONST_STRING_LITERAL_SECTION
#endif // TARGET_OS_LINUX

#if __BIG_ENDIAN__
#define CFSTR(cStr) ({ \
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&_CF_CONSTANT_STRING_SWIFT_CLASS, _CF_CONSTANT_OBJECT_STRONG_RC, 0x00000000C8070000}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
static struct __CFConstStr str = {{(uintptr_t)&_CF_CONSTANT_STRING_SWIFT_CLASS, _CF_CONSTANT_OBJECT_STRONG_RC, 0x00000000C8070000}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
(CFStringRef)&str; \
})
#else // Little endian:
#define CFSTR(cStr) ({ \
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&_CF_CONSTANT_STRING_SWIFT_CLASS, _CF_CONSTANT_OBJECT_STRONG_RC, 0x07C8}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
static struct __CFConstStr str = {{(uintptr_t)&_CF_CONSTANT_STRING_SWIFT_CLASS, _CF_CONSTANT_OBJECT_STRONG_RC, 0x07C8}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
(CFStringRef)&str; \
})
#endif // __BIG_ENDIAN__
Expand Down
1 change: 1 addition & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'-Wno-int-conversion',
'-Wno-unused-function',
'-I./',
'-fcf-runtime-abi=swift',
])

swift_cflags += [
Expand Down