Skip to content

Commit 49479b9

Browse files
authored
[build] Relax 16k native library alignment checks (#10608)
Fixes: #10601 Context: https://android.googlesource.com/platform//system/extras/+/3c784e9fd9f4e3f8e363a023939567c41c19d634%5E%21/#F0 For 64-bit native libraries Android allows the alignment to be 16k at the minimum, with any higher value acceptable as long as it's a power of two. With this commit we follow suit, accepting the same set of values as Android.
1 parent ccefa0d commit 49479b9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ static void AssertValidLibraryAlignment (TaskLoggingHelper log, uint pageSize, s
7070
throw new InvalidOperationException ($"Internal error: {segment} is not Segment<ulong>");
7171
}
7272

73-
// TODO: what happens if the library is aligned at, say, 64k while 16k is required? Should we erorr out?
74-
// We will need more info about that, have to wait till Google formally announce the requirement.
75-
// At this moment the script https://developer.android.com/guide/practices/page-sizes#test they
76-
// provide suggests it's a strict requirement, so we test for equality below.
77-
if (segment64.Alignment == pageSize) {
73+
// Android allows alignment higher than the page size, as long as it's a power of two. See:
74+
//
75+
// https://android.googlesource.com/platform//system/extras/+/3c784e9fd9f4e3f8e363a023939567c41c19d634%5E%21/#F0
76+
//
77+
if (segment64.Alignment >= pageSize && (segment64.Alignment % 2 == 0)) {
7878
continue;
7979
}
80-
log.LogDebugMessage ($" expected segment alignment of 0x{pageSize:x}, found 0x{segment64.Alignment:x}");
80+
log.LogDebugMessage ($" expected segment alignment of at least 0x{pageSize:x} and a power of two, found 0x{segment64.Alignment:x}");
8181

8282
(string packageId, string packageVersion, string originalFile) = GetNugetPackageInfo ();
8383
log.LogCodedWarning ("XA0141", Properties.Resources.XA0141, packageId, packageVersion, originalFile, Path.GetFileName (path));

0 commit comments

Comments
 (0)