From d5684fd61b2602b45bdf1561c08d3705938c3a38 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 22 Nov 2024 11:45:17 +0100 Subject: [PATCH 1/3] Add architecture info to the 0141 warning Partial fix for https://github.com/dotnet/android/issues/9544 to make the warning more informative. Architecture information is necessary as the nuget in question might have the same library for various architectures. --- .../Properties/Resources.Designer.cs | 4 ++-- src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | 3 ++- src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs | 8 +++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs index 636e491f4a9..cbdc6925bd2 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -531,7 +531,7 @@ public static string XA0140 { } /// - /// Looks up a localized string similar to NuGet package '{0}' version '{1}' contains a shared library '{2}' which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details. + /// Looks up a localized string similar to NuGet package '{0}' version '{1}' contains a shared library '{2}' ({3}) which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details. /// public static string XA0141 { get { diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 54ad2397fa9..04f9815fd96 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -1063,11 +1063,12 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS {1} - NuGet package version - NuGet package '{0}' version '{1}' contains a shared library '{2}' which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details + NuGet package '{0}' version '{1}' contains a shared library '{2}' ({3}) which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details The following is a literal name and should not be translated: NuGet {0} - NuGet package id {1} - NuGet package version {2} - shared library file name +{3} - target architecture name diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs index 9bee404bb7c..fdea6441f8f 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs @@ -45,6 +45,12 @@ static void AssertValidLibraryAlignment (TaskLoggingHelper log, uint pageSize, s throw new InvalidOperationException ($"Internal error: {elf} is not ELF"); } + string archName = elf.Machine switch { + Machine.AArch64 => "arm64-v8a", + Machine.AMD64 => "x86_64", + _ => throw new NotSupportedException ($"Internal error: ELF architecture {elf.Machine} is not supported") + }; + // We need to find all segments of Load type and make sure their alignment is as expected. foreach (ISegment segment in elf64.Segments) { if (segment.Type != SegmentType.Load) { @@ -66,7 +72,7 @@ static void AssertValidLibraryAlignment (TaskLoggingHelper log, uint pageSize, s log.LogDebugMessage ($" expected segment alignment of 0x{pageSize:x}, found 0x{segment64.Alignment:x}"); (string packageId, string packageVersion) = GetNugetPackageInfo (); - log.LogCodedWarning ("XA0141", Properties.Resources.XA0141, packageId, packageVersion, Path.GetFileName (path)); + log.LogCodedWarning ("XA0141", Properties.Resources.XA0141, packageId, packageVersion, Path.GetFileName (path), archName); break; } From 26686215fbef1114cf081d1842e83960e701eccb Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 22 Nov 2024 16:51:38 +0100 Subject: [PATCH 2/3] Address feedback --- .../Utilities/ELFHelper.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs index fdea6441f8f..3f94dc73595 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs @@ -72,7 +72,16 @@ static void AssertValidLibraryAlignment (TaskLoggingHelper log, uint pageSize, s log.LogDebugMessage ($" expected segment alignment of 0x{pageSize:x}, found 0x{segment64.Alignment:x}"); (string packageId, string packageVersion) = GetNugetPackageInfo (); - log.LogCodedWarning ("XA0141", Properties.Resources.XA0141, packageId, packageVersion, Path.GetFileName (path), archName); + log.LogCodedWarning ( + "XA0141", + path, + lineNumber: 0, + Properties.Resources.XA0141, + packageId, + packageVersion, + Path.GetFileName (path), + archName + ); break; } From c60b54ab066ecd1e989d63af3625f8d846dcea4f Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 22 Nov 2024 20:54:56 +0100 Subject: [PATCH 3/3] Change wording a bit, include page size in the message --- .../Properties/Resources.Designer.cs | 2 +- src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | 3 ++- src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs index cbdc6925bd2..13a28371195 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs @@ -531,7 +531,7 @@ public static string XA0140 { } /// - /// Looks up a localized string similar to NuGet package '{0}' version '{1}' contains a shared library '{2}' ({3}) which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details. + /// Looks up a localized string similar to NuGet package '{0}' version '{1}' contains a shared library '{2}' ({3}) which is not aligned to the {4} byte boundary. Google will require such alignment in the future. See https://developer.android.com/guide/practices/page-sizes for more details /// public static string XA0141 { get { diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 04f9815fd96..e486f634722 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -1063,12 +1063,13 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS {1} - NuGet package version - NuGet package '{0}' version '{1}' contains a shared library '{2}' ({3}) which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details + NuGet package '{0}' version '{1}' contains a shared library '{2}' ({3}) which is not aligned to the {4} byte boundary. Google will require such alignment in the future. See https://developer.android.com/guide/practices/page-sizes for more details The following is a literal name and should not be translated: NuGet {0} - NuGet package id {1} - NuGet package version {2} - shared library file name {3} - target architecture name +{4} - is an integer (size in bytes) diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs index 3f94dc73595..bc48aa436bd 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs @@ -80,7 +80,8 @@ static void AssertValidLibraryAlignment (TaskLoggingHelper log, uint pageSize, s packageId, packageVersion, Path.GetFileName (path), - archName + archName, + pageSize ); break; }