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

Conversation

iCharlesHu
Copy link
Contributor

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 have their own namespaces 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 in the same namespace as the system ICU. This solution proves effective for SwiftFoundation, as it does not actually utilize the C++ APIs.

Copy link
Contributor

@jmschonfeld jmschonfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also revert #19 as part of this change?

@iCharlesHu
Copy link
Contributor Author

iCharlesHu commented Jul 24, 2024

Should we also revert #19 as part of this change?

I didn't bother because we are gonna upgrade ICU very soon anyways. We just won't apply that diff anymore

@iCharlesHu iCharlesHu force-pushed the charles/hide-cxx-apis branch from 528ad42 to 85d92d8 Compare July 24, 2024 02:42
@iCharlesHu
Copy link
Contributor Author

Added comments.

Copy link
Contributor

@jmschonfeld jmschonfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two small nits on the wording in the comment that I think might help clarify what we found in our investigation, but otherwise this looks good to me thanks!

Should we run a full toolchain build before merging to ensure we don't break the toolchain with this change just in case something goes wrong?

**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.
@iCharlesHu
Copy link
Contributor Author

Toolchain build test: swiftlang/swift#75452

@jmschonfeld
Copy link
Contributor

Looks like this caused toolchain build failures that we'll need to resolve:

/home/build-user/swift-foundation-icu/icuSources/i18n/uspoof.cpp:784:1: error: visibility does not match previous declaration
  784 | U_I18N_API const UnicodeSet * U_EXPORT2
      | ^
/home/build-user/swift-foundation-icu/icuSources/include/_foundation_unicode/utypes.h:377:39: note: expanded from macro 'U_I18N_API'
  377 | #define U_I18N_API     __attribute__((visibility("hidden")))
      |                                       ^
/home/build-user/swift-foundation-icu/icuSources/include/_foundation_unicode/uspoof.h:1555:1: note: previous attribute is here
 1555 | U_CAPI const icu::UnicodeSet * U_EXPORT2
      | ^
/home/build-user/swift-foundation-icu/icuSources/include/_foundation_unicode/umachine.h:110:24: note: expanded from macro 'U_CAPI'
  110 | #define U_CAPI U_CFUNC U_EXPORT
      |                        ^
/home/build-user/swift-foundation-icu/icuSources/include/_foundation_unicode/platform.h:821:36: note: expanded from macro 'U_EXPORT'
  821 | #   define U_EXPORT __attribute__((visibility("default")))
      |

@iCharlesHu
Copy link
Contributor Author

Building new toolchain now...

@iCharlesHu iCharlesHu merged commit 0b2f641 into swiftlang:main Jul 29, 2024
@iCharlesHu iCharlesHu deleted the charles/hide-cxx-apis branch July 29, 2024 17:18
@itingliu itingliu mentioned this pull request Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants