Skip to content

Hide all ICU public C++ Symbols #34

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 2 commits into from
Jul 29, 2024
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
4 changes: 2 additions & 2 deletions icuSources/i18n/uspoof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,13 +781,13 @@ uspoof_getRecommendedSet(UErrorCode *status) {
return gRecommendedSet->toUSet();
}

U_I18N_API const UnicodeSet * U_EXPORT2
U_CAPI const UnicodeSet * U_EXPORT2
uspoof_getInclusionUnicodeSet(UErrorCode *status) {
umtx_initOnce(gSpoofInitStaticsOnce, &initializeStatics, *status);
return gInclusionSet;
}

U_I18N_API const UnicodeSet * U_EXPORT2
U_CAPI const UnicodeSet * U_EXPORT2
uspoof_getRecommendedUnicodeSet(UErrorCode *status) {
umtx_initOnce(gSpoofInitStaticsOnce, &initializeStatics, *status);
return gRecommendedSet;
Expand Down
32 changes: 25 additions & 7 deletions icuSources/include/_foundation_unicode/utypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,31 @@ typedef double UDate;
#endif

#if defined(U_COMBINED_IMPLEMENTATION)
#define U_DATA_API U_EXPORT
#define U_COMMON_API U_EXPORT
#define U_I18N_API U_EXPORT
#define U_LAYOUT_API U_EXPORT
#define U_LAYOUTEX_API U_EXPORT
#define U_IO_API U_EXPORT
#define U_TOOLUTIL_API U_EXPORT
// SwiftFoundationICU Changes: hide all C++ public symbols
// Rationale: When FoundationInternationalization tests are executed,
// we effectively load two ICU instances into memory:
//
// 1) The system ICU loaded by XCTest via system Foundation;
// 2) The package ICU SwiftFoundation utilizes.
//
// These two ICUs cause symbol collisions for dyld due to the fact that
// all public C++ symbols share a global namespace and coalesce across all loaded dylibs.
// Consequently, we encounter sporadic test failures in SwiftFoundation as dyld
// arbitrarily selects ICU symbols and occasionally chooses the system one.
//
// To address this issue, we resolved to hide all C++ APIs,
// ensuring they are not weakly referenced and potentially bound to
// the system ICU implementation.
//
// This solution proves effective for SwiftFoundation,
// as it does not actually utilize the C++ APIs.
#define U_DATA_API __attribute__((visibility("hidden")))
#define U_COMMON_API __attribute__((visibility("hidden")))
#define U_I18N_API __attribute__((visibility("hidden")))
#define U_LAYOUT_API __attribute__((visibility("hidden")))
#define U_LAYOUTEX_API __attribute__((visibility("hidden")))
#define U_IO_API __attribute__((visibility("hidden")))
#define U_TOOLUTIL_API __attribute__((visibility("hidden")))
#elif defined(U_STATIC_IMPLEMENTATION)
#define U_DATA_API
#define U_COMMON_API
Expand Down