Skip to content

[android] Put in fixes for librt and armv7-a #554

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 1 commit into from
Feb 24, 2021

Conversation

finagolfin
Copy link
Member

Android doesn't have a separate librt, it's just part of libc. Also, the static build wasn't working for armv7-a, because the test executables wouldn't link with the multiple definition errors listed in android/ndk#176, so use the workaround given there.

I didn't have any problems when cross-compiling for 64-bit arches, but hit the first one because I happen to have an i686 libc package installed in Ubuntu and the armv7 build would try to use librt.so from that. The second libunwind issue has been around for awhile, and I worked around it before by not building the tests for libdispatch, but this gets them to build and run.

@compnerd, let me know what you think.

find_package(LibRT)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Android)
find_package(LibRT)
endif()
Copy link
Member

Choose a reason for hiding this comment

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

This is fine to do, but really unfortunate. CMake already already can deal with librt properly on various targets, but we don't use CMake properly :-(.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you could use CMAKE_FIND_ROOT_PATH, like I do when cross-compiling the corelibs, if there is an librt.so to find, but there is none on Android- it's just part of libc.so- so this is the right change for Android.

if(NOT BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL Android AND
CMAKE_SYSTEM_PROCESSOR STREQUAL armv7-a)
target_link_options(${name} PRIVATE "LINKER:--allow-multiple-definition")
endif()
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs a huge comment. This is indicative of an issue - the multiple definitions shouldnt be there. The warnings indicate that there is a mix up between libgcc and libunwind, which is a really bad thing as it will crash at runtime in a difficult to diagnose manner (the internal layouts of the unwind context is not compatible/guaranteed).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I don't know exactly what's going on here, their doc doesn't clear it up for me. All I know is that applying this workaround flag gets the test executables to build, and I tried moving a handful to Android and they ran fine. I will add a comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the comment.

Android doesn't have a separate librt, it's just part of libc. Also, the static
build wasn't working for armv7-a, because the test executables wouldn't link
with the multiple definition errors listed in android/ndk#176, so use the
workaround given there.
@finagolfin
Copy link
Member Author

Ping, would be good to get this in before the 5.4 branch. @MadCoder or @drexin, maybe one of you could merge if Saleem is busy?

@finagolfin
Copy link
Member Author

Ping, if someone can run the CI, we can get this in.

@finagolfin
Copy link
Member Author

@benlangmuir, mind running the CI on this?

@benlangmuir
Copy link
Contributor

@swift-ci please test

3 similar comments
@benlangmuir
Copy link
Contributor

@swift-ci please test

@benlangmuir
Copy link
Contributor

@swift-ci please test

@benlangmuir
Copy link
Contributor

@swift-ci please test

@finagolfin
Copy link
Member Author

A final CI run and this can be merged.

@drexin
Copy link
Contributor

drexin commented Jan 6, 2021

@swift-ci test

@finagolfin
Copy link
Member Author

CI failed because of unrelated lldb compilation error.

@benlangmuir
Copy link
Contributor

@swift-ci please test

@finagolfin
Copy link
Member Author

Passed CI, can someone merge?

@finagolfin
Copy link
Member Author

I just ran into the build failing when cross-compiling for Android AArch64 too, because it tries to link against the system libRT.so on Fedora Core x86_64 too.

@benlangmuir, mind merging?

@benlangmuir
Copy link
Contributor

Someone who works on this project should review/merge. I'm not the right person to look at this. It looks like @compnerd was looking at it earlier.

@finagolfin
Copy link
Member Author

Alright, @MadCoder, mind reviewing?

@finagolfin
Copy link
Member Author

Ping @drexin, can you get this simple pull in?

@drexin drexin merged commit 34f383d into swiftlang:main Feb 24, 2021
@finagolfin finagolfin deleted the droid-arm branch February 25, 2021 06:17
rokhinip pushed a commit that referenced this pull request Nov 5, 2021
[android] Put in fixes for librt and armv7-a

Signed-off-by: Rokhini Prabhu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants