Skip to content

Commit

Permalink
Implement requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Jul 16, 2024
1 parent 9a27b17 commit 9f47f63
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ The .NET Foundation licenses this file to you under the MIT license.
<LinkerArg Include="@(ExtraLinkerArg->'-Wl,%(Identity)')" />
<LinkerArg Include="@(NativeFramework->'-framework %(Identity)')" Condition="'$(_IsApplePlatform)' == 'true'" />
<LinkerArg Include="-Wl,--eh-frame-hdr" Condition="'$(_IsApplePlatform)' != 'true'" />

<!-- Google requires all the native libraries to be aligned to 16 bytes (for 16k memory page size)
This is required only for 64-bit binaries.
-->
<LinkerArg Include="-Wl,-z,max-page-size=16384" Condition=" '$(_linuxLibcFlavor)' == 'bionic' " />
</ItemGroup>

<Exec Command="clang --version" Condition="'$(_IsApplePlatform)' == 'true'" IgnoreExitCode="true" StandardOutputImportance="Low" ConsoleToMSBuild="true">
Expand Down
13 changes: 7 additions & 6 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,6 @@ else()
message(FATAL_ERROR "TARGET_ARCH='${TARGET_ARCH}' not supported.")
endif()

if(HOST_ANDROID AND (HOST_AMD64 OR HOST_ARM64))
# Google requires all the native libraries to be aligned to 16 bytes (for 16k memory page size)
# This applies only to 64-bit binaries
add_link_options(LINKER:-z,max-page-size=16384)
endif()

# arm64 MacCatalyst runtime host or AOT target is more like Apple mobile targets than x64
if ((HOST_MACCAT AND HOST_ARM64) OR (TARGET_MACCAT AND TARGET_ARM64))
set(TARGET_APPLE_MOBILE 1)
Expand Down Expand Up @@ -903,6 +897,13 @@ if(CLR_CMAKE_HOST_APPLE)
endif()
endif()

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

include_directories("${CLR_SRC_NATIVE_DIR}")
Expand Down
6 changes: 4 additions & 2 deletions src/tasks/LibraryBuilder/LibraryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,10 @@ private string BuildAndroidLibrary(List<string> sources, List<string> libs, List
buildOptions.LinkerArguments.Add($"--soname={libraryName}");

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

0 comments on commit 9f47f63

Please sign in to comment.