Skip to content

Commit 9f8a2ea

Browse files
committed
Implement requested changes
1 parent 3dceaa4 commit 9f8a2ea

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ The .NET Foundation licenses this file to you under the MIT license.
240240
<LinkerArg Include="@(ExtraLinkerArg->'-Wl,%(Identity)')" />
241241
<LinkerArg Include="@(NativeFramework->'-framework %(Identity)')" Condition="'$(_IsApplePlatform)' == 'true'" />
242242
<LinkerArg Include="-Wl,--eh-frame-hdr" Condition="'$(_IsApplePlatform)' != 'true'" />
243+
244+
<!-- Google requires all the native libraries to be aligned to 16 bytes (for 16k memory page size)
245+
This is required only for 64-bit binaries.
246+
-->
247+
<LinkerArg Include="-Wl,-z,max-page-size=16384" Condition=" '$(_linuxLibcFlavor)' == 'bionic' " />
243248
</ItemGroup>
244249

245250
<Exec Command="clang --version" Condition="'$(_IsApplePlatform)' == 'true'" IgnoreExitCode="true" StandardOutputImportance="Low" ConsoleToMSBuild="true">

src/mono/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,6 @@ else()
503503
message(FATAL_ERROR "TARGET_ARCH='${TARGET_ARCH}' not supported.")
504504
endif()
505505

506-
if(HOST_ANDROID AND (HOST_AMD64 OR HOST_ARM64))
507-
# Google requires all the native libraries to be aligned to 16 bytes (for 16k memory page size)
508-
# This applies only to 64-bit binaries
509-
add_link_options(LINKER:-z,max-page-size=16384)
510-
endif()
511-
512506
# arm64 MacCatalyst runtime host or AOT target is more like Apple mobile targets than x64
513507
if ((HOST_MACCAT AND HOST_ARM64) OR (TARGET_MACCAT AND TARGET_ARM64))
514508
set(TARGET_APPLE_MOBILE 1)
@@ -903,6 +897,13 @@ if(CLR_CMAKE_HOST_APPLE)
903897
endif()
904898
endif()
905899

900+
if(HOST_ANDROID)
901+
if(HOST_AMD64 OR HOST_ARM64)
902+
# Google requires all the native libraries to be aligned to 16 bytes (for 16k memory page size)
903+
# This applies only to 64-bit binaries
904+
add_link_options(LINKER:-z,max-page-size=16384)
905+
endif()
906+
endif()
906907
### End of OS specific checks
907908

908909
include_directories("${CLR_SRC_NATIVE_DIR}")

src/tasks/LibraryBuilder/LibraryBuilder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,10 @@ private string BuildAndroidLibrary(List<string> sources, List<string> libs, List
339339
buildOptions.LinkerArguments.Add($"--soname={libraryName}");
340340

341341
// Google requires all the native libraries to be aligned to 16 bytes (for 16k memory page size)
342-
// This is required only for 64-bit binaries, but there's not much harm if it is also done for 32-bit ones.
343-
buildOptions.LinkerArguments.Add($"-z,max-page-size=16384");
342+
// This is required only for 64-bit binaries.
343+
if (string.CompareOrdinal ("android-arm64", RuntimeIdentifier) == 0 || string.CompareOrdinal ("android-x64", RuntimeIdentifier) == 0) {
344+
buildOptions.LinkerArguments.Add($"-z,max-page-size=16384");
345+
}
344346
buildOptions.LinkerArguments.AddRange(linkerArgs);
345347
buildOptions.NativeLibraryPaths.AddRange(libs);
346348
buildOptions.Sources.AddRange(sources);

0 commit comments

Comments
 (0)