Skip to content

Commit

Permalink
Add architecture info to the 0141 warning
Browse files Browse the repository at this point in the history
Partial fix for #9544 to make
the warning more informative.  Architecture information is necessary as
the nuget in question might have the same library for various
architectures.
  • Loading branch information
grendello committed Nov 22, 2024
1 parent 78f8863 commit 8aa5ef7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1072,11 +1072,12 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS
{1} - NuGet package version</comment>
</data>
<data name="XA0141" xml:space="preserve">
<value>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</value>
<value>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</value>
<comment>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
</comment>
</data>
<data name="XA4249" xml:space="preserve">
Expand Down
8 changes: 7 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ static void AssertValidLibraryAlignment (TaskLoggingHelper log, uint pageSize, s
throw new InvalidOperationException ($"Internal error: {elf} is not ELF<ulong>");
}

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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 8aa5ef7

Please sign in to comment.