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

Make sure app bundle has soname set #2192

Merged
merged 1 commit into from
Sep 27, 2018

Conversation

grendello
Copy link
Contributor

Android API23 and newer requires that any shared library used by an application
which targets API23 or newer has its soname set in the ELF header or otherwise
the OS will refuse to load it:

09-18 08:07:27.687 10698 10698 W linker : Warning: "/data/app/Mono.Android_Tests-O9bT_-xHyd26brpmOI9RNg==/lib/x86/libmonodroid_bundle_app.so" has no DT_SONAME (will use libmonodroid_bundle_app.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.
com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 22) (TaskId:201)

This commit fixes the problem by passing -soname libmonodroid_bundle_app.so to
the linker when building the bundle.

@jonpryor
Copy link
Member

This PR should update one of the mkbundle .apk tests so that it's targetSdkVersion is >= 23, as "crash on app launch" seems like a significant problem that we should prevent from happening.

We currently have tests/CodeGen-MkBundle/Xamarin.Android.MakeBundle-Tests, which sets $(BundleAssemblies)=True, but that's not currently run on-device because it has no .projitems file which is included in tests/RunApkTests.targets.

Should we update an existing on-device test to set $(BundleAssemblies)=True? Or should we add the existing Xamarin.Android.MakeBundle-Tests set to RunApkTests.targets?

@grendello grendello force-pushed the mkbundle-use-soname branch 2 times, most recently from 96e7504 to b1007bb Compare September 19, 2018 08:36
{
public static class Config
{
public static readonly string LlvmReadobj = Path.Combine ("@ANDROID_NDK_DIRECTORY@", "toolchains", "llvm", "prebuilt", "@HOST_ARCH@", "bin", "llvm-readobj@EXECUTABLE_EXTENSION@");
Copy link
Member

Choose a reason for hiding this comment

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

As per 3440227, this should use @"@ANDROID_NDK_DIRECTORY@" (using @-strings), so that this works properly on Windows.

public static class Config
{
public static readonly string LlvmReadobj = Path.Combine ("@ANDROID_NDK_DIRECTORY@", "toolchains", "llvm", "prebuilt", "@HOST_ARCH@", "bin", "llvm-readobj@EXECUTABLE_EXTENSION@");
public static readonly string GccReadelf = Path.Combine ("@ANDROID_NDK_DIRECTORY@", "toolchains", "@OLD_TOOLCHAIN@", "prebuilt", "@HOST_ARCH@", "bin", "x86_64-linux-android-readelf@EXECUTABLE_EXTENSION@");
Copy link
Member

Choose a reason for hiding this comment

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

As per 3440227, this should use @"@ANDROID_NDK_DIRECTORY@" (using @-strings), so that this works properly on Windows.

</ProjectReference>
</ItemGroup>

<Target Name="Prepare"
Copy link
Member

Choose a reason for hiding this comment

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

From the "Appeasing Visual Studio for Mac" department, custom targets should not go into .csproj files, because whenever you e.g. add a project to the .sln, Visual Studio for Mac will "reformat" every .csproj referenced by the .sln. (Related: https://bugzilla.xamarin.com/show_bug.cgi?id=42603)

To appease VS for Mac -- and keep our sanity! -- custom targets should go into a .targets file, e.g. Xamarin.Android.MakeBundle-UnitTests.targets -- and the .csproj should <Import/> the .targets file. (See e.g. Mono.Android.csproj, mono-runtimes.csproj, and nearly every other project we have!)

@grendello
Copy link
Contributor Author

build

@grendello
Copy link
Contributor Author

The failure is due a misbehaving HttpWebRequest test:

  09-25 23:12:20.155  4801  4930 E mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Unable to read data from the transport connection: interrupted. ---> System.Net.Sockets.SocketException: interrupted (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at System.Net.Sockets.Socket.Receive (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags) [0x00017] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/ext
ernal/mono/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs:1773  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x0009b] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/referencesource/Sys
tem/net/System/Net/Sockets/NetworkStream.cs:513  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :    --- End of inner exception stack trace --- (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x000c3] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/referencesource/Sys
tem/net/System/Net/Sockets/NetworkStream.cs:525  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at System.Net.RequestStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x00033] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/System/System.Net/RequestS
tream.cs:141  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at MonoTests.System.Net.StreamExtensions.ReadAll (System.IO.Stream stream, System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x00004] in <506591a0ad94482da7f4d89d0939a426>:0  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at MonoTests.System.Net.HttpWebRequestTest+<>c__DisplayClass63_0.<PrematureStreamCloseAborts>b__1 (System.Net.HttpListenerContext c) [0x0000b] in <506591a0ad94482da7f4d89d0939a426>:0  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at MonoTests.System.Net.HttpWebRequestTest+ListenerScope+<>c__DisplayClass4_0.<RequestHandler>b__0 (System.Object o) [0x00000] in <506591a0ad94482da7f4d89d0939a426>:0  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x0000d] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/th
reading/threadpool.cs:1308  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in /Users/builder
/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:961  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in /Users/builder/jenkins
/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:908  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/referencesource/mscor
lib/system/threading/threadpool.cs:1285  (TaskId:139)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:858  (TaskId:13
9)
  09-25 23:12:20.155  4801  4930 E mono-rt :   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:
1213  (TaskId:139)
  09-25 23:12:20.297  1702  1702 I Zygote  : Process 4801 exited cleanly (255) (TaskId:139)
  09-25 23:12:20.297  1848  2454 I ActivityManager: Process Xamarin.Android.Bcl_Tests (pid 4801) has died: fore FGS  (TaskId:139)

The exception is thrown on a threadpool thread and is not delivered to the runner, thus the unhandled status and process exit.

@grendello
Copy link
Contributor Author

build

@@ -0,0 +1,7 @@
#!/bin/bash -e
Copy link
Member

Choose a reason for hiding this comment

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

What is this file used for? I don't see any other mentions of run.sh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's just a way to run this without having to launch the whole msbuild machinery - faster turnover of changes

@jonpryor
Copy link
Member

If run.sh isn't needed, I'd be fine with just removing it and merging without waiting for another PR build.

Android API23 and newer requires that any shared library used by an application
which targets API23 or newer has its soname set in the ELF header or otherwise
the OS will refuse to load it:

   09-18 08:07:27.687 10698 10698 W linker  : Warning: "/data/app/Mono.Android_Tests-O9bT_-xHyd26brpmOI9RNg==/lib/x86/libmonodroid_bundle_app.so" has no DT_SONAME (will use libmonodroid_bundle_app.so instead) and will not work when the app moves to API level 23 or later (https://android.googlesource.
com/platform/bionic/+/master/missing-soname-enforced-for-api-level-23) (allowing for now because this app's target API level is still 22) (TaskId:201)

This commit fixes the problem by passing `-soname libmonodroid_bundle_app.so` to
the linker when building the bundle.
@jonpryor jonpryor merged commit 914bfcc into dotnet:master Sep 27, 2018
@grendello grendello deleted the mkbundle-use-soname branch September 27, 2018 14:45
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants