From da809679169581338426dce5c8dfd79324fb6904 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Mon, 24 Nov 2025 15:58:10 +0100 Subject: [PATCH] [build] Relax 16k native library alignment checks Fixes: https://github.com/dotnet/android/issues/10601 Android allows libraries aligned to at least 16k, as long as they are aligned to a power of two. Follow suit. --- .../Utilities/ELFHelper.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs index b619c6a50fd..d487aec2618 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs @@ -70,14 +70,14 @@ static void AssertValidLibraryAlignment (TaskLoggingHelper log, uint pageSize, s throw new InvalidOperationException ($"Internal error: {segment} is not Segment"); } - // TODO: what happens if the library is aligned at, say, 64k while 16k is required? Should we erorr out? - // We will need more info about that, have to wait till Google formally announce the requirement. - // At this moment the script https://developer.android.com/guide/practices/page-sizes#test they - // provide suggests it's a strict requirement, so we test for equality below. - if (segment64.Alignment == pageSize) { + // Android allows alignment higher than the page size, as long as it's a power of two. See: + // + // https://android.googlesource.com/platform//system/extras/+/3c784e9fd9f4e3f8e363a023939567c41c19d634%5E%21/#F0 + // + if (segment64.Alignment >= pageSize && (segment64.Alignment % 2 == 0)) { continue; } - log.LogDebugMessage ($" expected segment alignment of 0x{pageSize:x}, found 0x{segment64.Alignment:x}"); + log.LogDebugMessage ($" expected segment alignment of at least 0x{pageSize:x} and a power of two, found 0x{segment64.Alignment:x}"); (string packageId, string packageVersion, string originalFile) = GetNugetPackageInfo (); log.LogCodedWarning ("XA0141", Properties.Resources.XA0141, packageId, packageVersion, originalFile, Path.GetFileName (path));