Skip to content
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

[android] Switch to new single-header modulemap for Bionic too #35707

Merged
merged 1 commit into from
Feb 10, 2022

Conversation

finagolfin
Copy link
Member

This pull gets all the same tests to pass in the Swift compiler test and validation suite when natively run on Android in the Termux app, but also gets 38 C++ interopability tests that were previously failing to pass, as was the intent of #32404. However, building libFoundationNetworking.so from the corelibs then fails with these errors:

<unknown>:0: error: fatal error encountered while reading from module 'Foundation'; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
<unknown>:0: note: module 'Foundation' full misc version is '5.4(5.4)/Swift version 5.4-dev (LLVM e2976fe639d1f50, Swift f9be289b9e04b3d)'

*** DESERIALIZATION FAILURE (please include this section in any bug report) ***
top-level value not found
Cross-reference to module 'CDispatch'
... memcmp
... with type (UnsafeRawPointer, UnsafeRawPointer, Int) -> Int32
--------
1.      Swift version 5.4-dev (LLVM e2976fe639d1f50, Swift f9be289b9e04b3d)
2.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, Serialize, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for FoundationNetworking.FoundationNetworking)
3.      While running pass #1974 SILModuleTransform "PerformanceSILLinker".
4.      While deserializing SIL function "$s10Foundation4DataV2eeoiySbAC_ACtFZ"
5.      While deserializing SIL function "memcmp"
<unknown>:0: error: unable to execute command: Aborted

I am not familiar with this error, so maybe a Swift compiler dev can chime in. I can reproduce when cross-compiling the corelibs for Android with #33724 and a couple other related pulls.

@CodaFi, @drodriguez, @hlopko, any input would be appreciated.

@@ -28,7 +28,6 @@ headers = [
'tgmath.h',
'time.h',
'utmp.h',
'utmpx.h',
Copy link
Member Author

Choose a reason for hiding this comment

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

This header is included twice, so removed one.

drodriguez added a commit that referenced this pull request Feb 8, 2021
Change the original UNSUPPORTED to XFAIL, to get signal if the test
starts working.

PR #35707 should allow this test to work properly.
@finagolfin
Copy link
Member Author

I just tried this pull again with the May 3rd trunk source snapshot and got the following error this time:

<unknown>:0: error: fatal error encountered while reading from module 'Foundation'; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
<unknown>:0: note: module 'Foundation' full misc version is '5.5(5.5)/Swift version 5.5-dev (LLVM 6337fa4dc365079, Swift a6915e7bfef8173)'

*** DESERIALIZATION FAILURE (please include this section in any bug report) ***
top-level value not found
Cross-reference to module 'CDispatch'
... memcmp
... with type (UnsafeRawPointer, UnsafeRawPointer, Int) -> Int32
Notes:
* 'memcmp' in module 'SwiftShims' was filtered out.
* 'memcmp' in module 'Foundation' was filtered out.
* 'memcmp' in module 'CDispatch' was filtered out.
* 'memcmp' in module 'Glibc' was filtered out.
* 'memcmp' in module 'SwiftGlibc' was filtered out.
* 'memcmp' in module 'SwiftOverlayShims' was filtered out.
* 'memcmp' in module 'CoreFoundation' was filtered out.
* 'memcmp' in module 'CFURLSessionInterface' was filtered out.
----------
1.	Swift version 5.5-dev (LLVM 6337fa4dc365079, Swift a6915e7bfef8173)
2.	While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, Serialize, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for FoundationNetworking.FoundationNetworking)
3.	While running pass #1640 SILModuleTransform "PerformanceSILLinker".
4.	While deserializing SIL function "$s10Foundation4DataV2eeoiySbAC_ACtFZ"
5.	While deserializing SIL function "memcmp"
<unknown>:0: error: unable to execute command: Aborted

@xymus, you added these new messages about Glibc being wrongly filtered out in #36431, any clue what might be going on or how to fix it?

@xymus
Copy link
Contributor

xymus commented May 10, 2021

We addressed this issue for macOS with the adequately numbered PR #36666. The problem here is that memcmp is sometimes defined with _Nullable parameters and other times with non-nullable parameters via the default behavior. The error message above means that all of these module know about a memcmp but the signatures don't fit.

You can probably extend the workaround from #36666 to Android to get rid of this issue.

@finagolfin
Copy link
Member Author

Alright, I will try that.

@finagolfin
Copy link
Member Author

Applying that fix got the corelibs to build again and for all the same corelibs tests to pass, thanks Alexis. I've kicked off a run of the Swift compiler unit test and validation suite natively on Android, which takes much longer.

@drodriguez, do you want to try applying this updated pull to the cross-compilation Android CI too, now that it seems to work natively on Android?

@finagolfin
Copy link
Member Author

This pull now gets 48 C++ Interop tests that were failing to pass, with no regressions in the validation suite. However, I now get a similar compiler error when building the Swift library wrapper for llbuild, this time with deserializing malloc. I will look into it.

@finagolfin
Copy link
Member Author

Rebased and that last malloc issue appears to have gone away. Applying this patch to the Nov. 19 trunk source snapshot got 50 C++ Interop tests that were failing to pass natively on Android, while natively compiling the rest of the toolchain now works. I then applied this patch to cross-compiling the last Dec. 6 trunk snapshot for Android, finagolfin/swift-android-sdk@e174127, and was able to cross-compile the SDK and 11 Swift packages that passed their tests on the Android x86_64 emulator.

I had to patch Swift NIO for some Bionic constants in that commit, but that's it. Hopefully, I won't need to revert the C++ interoperability that @zoecarver added to libswift any longer once this pull is in.

@MaxDesiatov, would you run the CI?

@xymus, would you review?

@drodriguez, you may want to try this on your local setup that reproduces the Android CI before this is merged, though I doubt it will break that CI.

@MaxDesiatov
Copy link
Contributor

@swift-ci please smoke test

Copy link
Contributor

@vgorloff vgorloff left a comment

Choose a reason for hiding this comment

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

PR changes working on my side, when applied on top of toolchain https://github.com/vgorloff/swift-everywhere-toolchain/releases/tag/1.0.77.

The only thing I changed – is maintained C/C++ header search paths (passed to swift build command).

# Before
-Xcc -I/usr/local/ndk/21.4.7075529/.../include/c++/v1

# After
-Xcxx -I/usr/local/ndk/21.4.7075529/.../include/c++/v1.

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

If it works for all of you, LGTM

@finagolfin
Copy link
Member Author

finagolfin commented Dec 19, 2021

@drodriguez, I just ran the compiler validation suite on linux x86_64 with a trunk commit from today, after applying this pull and #40625, for both AArch64 and armv7 and the same tests passed as on the Android CI, ie only the 13 C++ Interop tests that are currently broken on the Android CI failed (I was hoping this patch would fix those 13 tests, but no such luck).

I think you can merge this now, shouldn't break anything.

finagolfin added a commit to finagolfin/swift-nio that referenced this pull request Jan 5, 2022
…om NIOCore

Motivation:

An upcoming pull, swiftlang/swift#35707, moves Android to the same single-header
modulemap for Bionic as used on linux, but that doesn't work unless this casting
is changed. This approach works both with the current release toolchain and
with that new modulemap.

Modifications:

- Change how these constants are cast.
- Remove them from NIOCore.

Result:

This repo compiles for Android and the tests pass with both modulemap approaches.
finagolfin added a commit to finagolfin/swift-nio that referenced this pull request Jan 5, 2022
Motivation:

An upcoming pull, swiftlang/swift#35707, moves Android to the same single-header
modulemap for Bionic as used on linux, but that doesn't work unless this casting
is changed. This approach works both with the current release toolchain and
with that new modulemap.

Modifications:

Change how these constants are cast.

Result:

This repo compiles for Android and the tests pass with both modulemap approaches.
finagolfin added a commit to finagolfin/swift-nio that referenced this pull request Jan 5, 2022
Motivation:

An upcoming pull, swiftlang/swift#35707, moves Android to the same single-header
modulemap for Bionic as used on linux, but that doesn't work unless this is
changed. This approach works both with the current release toolchain and
with that new modulemap.

Modifications:

Change how these Bionic constants are imported.

Result:

This repo compiles for Android and the tests pass with both modulemap approaches.
Lukasa added a commit to apple/swift-nio that referenced this pull request Jan 6, 2022
Motivation:

An upcoming pull, swiftlang/swift#35707, moves Android to the same single-header
modulemap for Bionic as used on linux, but that doesn't work unless this is
changed. This approach works both with the current release toolchain and
with that new modulemap.

Modifications:

Change how these Bionic constants are imported.

Result:

This repo compiles for Android and the tests pass with both modulemap approaches.

Co-authored-by: Cory Benfield <[email protected]>
@finagolfin
Copy link
Member Author

@artemcm, would you run the CI again? It hasn't been re-run since the holiday break.

@artemcm
Copy link
Contributor

artemcm commented Jan 13, 2022

@swift-ci please test

@finagolfin
Copy link
Member Author

Ping, @drodriguez, just waiting for you to merge this.

@finagolfin
Copy link
Member Author

@CodaFi, would you merge? This will unbreak the build on the Android CI, and if @drodriguez has any changes he wants made, we can always add those whenever he gets back.

@finagolfin
Copy link
Member Author

@drodriguez, can we get this in?

@CodaFi CodaFi merged commit f5bc40b into swiftlang:main Feb 10, 2022
@finagolfin finagolfin deleted the droid branch February 11, 2022 05:45
@finagolfin
Copy link
Member Author

Alright, this fixed the build on the Android CI and it's able to run the host tests from the compiler validation suite again. @drodriguez, if you have any input, let us know, going to submit this for the 5.6 branch next.

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.

7 participants