Merge "Extend page alignment compat to cover x86_64." into main
diff --git a/build/cmake/android-legacy.toolchain.cmake b/build/cmake/android-legacy.toolchain.cmake
index 610024b..252a199 100644
--- a/build/cmake/android-legacy.toolchain.cmake
+++ b/build/cmake/android-legacy.toolchain.cmake
@@ -459,7 +459,7 @@
 
 if(ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES)
   list(APPEND ANDROID_COMPILER_FLAGS -D__BIONIC_NO_PAGE_SIZE_MACRO)
-  if(ANDROID_ABI STREQUAL arm64-v8a)
+  if(ANDROID_ABI STREQUAL arm64-v8a OR ANDROID_ABI STREQUAL x86_64)
     list(APPEND ANDROID_LINKER_FLAGS -Wl,-z,max-page-size=16384)
   endif()
 endif()
diff --git a/build/cmake/flags.cmake b/build/cmake/flags.cmake
index f1f4eb9..11acc04 100644
--- a/build/cmake/flags.cmake
+++ b/build/cmake/flags.cmake
@@ -32,7 +32,7 @@
 
 if(ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES)
   string(APPEND _ANDROID_NDK_INIT_CFLAGS " -D__BIONIC_NO_PAGE_SIZE_MACRO")
-  if(ANDROID_ABI STREQUAL arm64-v8a)
+  if(ANDROID_ABI STREQUAL arm64-v8a OR ANDROID_ABI STREQUAL x86_64)
     string(APPEND _ANDROID_NDK_INIT_LDFLAGS " -Wl,-z,max-page-size=16384")
   endif()
 endif()
diff --git a/build/core/build-binary.mk b/build/core/build-binary.mk
index a09ef5c..7940c66 100644
--- a/build/core/build-binary.mk
+++ b/build/core/build-binary.mk
@@ -134,7 +134,7 @@
 
 ifeq ($(APP_SUPPORT_FLEXIBLE_PAGE_SIZES),true)
   LOCAL_CFLAGS += -D__BIONIC_NO_PAGE_SIZE_MACRO
-  ifeq ($(APP_ABI),arm64-v8a)
+  ifneq (,$(filter $(APP_ABI),arm64-v8a x86_64))
     LOCAL_LDFLAGS += -Wl,-z,max-page-size=16384
   endif
 endif
diff --git a/tests/build/alignment_compat/test.py b/tests/build/alignment_compat/test.py
index 46f2f66..1c7633e 100644
--- a/tests/build/alignment_compat/test.py
+++ b/tests/build/alignment_compat/test.py
@@ -61,8 +61,8 @@
         if alignment != expected_alignment:
             return (
                 False,
-                f"{path.resolve()}: LOAD section at {offset:x} has incorrect alignment {alignment:x}. "
-                f"Expected {expected_alignment:x}",
+                f"{path.resolve()}: LOAD section at {offset:#x} has incorrect "
+                f"alignment {alignment:#x}. Expected {expected_alignment:#x}",
             )
     return True, None
 
@@ -95,8 +95,14 @@
         ndk_build_builder.build()
     except CalledProcessError as ex:
         return False, f"Build failed:\n{ex.stdout}"
+
+    if config.abi in (Abi("arm64-v8a"), Abi("x86_64")):
+        expected_alignment = 16 * 1024
+    else:
+        expected_alignment = 4 * 1024
+
     return verify_load_section_alignment_each_file(
         [cmake_builder.out_dir / "libfoo.so", ndk_build_builder.out_dir / "libfoo.so"],
         Path(ndk_path),
-        expected_alignment=16 * 1024 if config.abi == Abi("arm64-v8a") else 4 * 1024,
+        expected_alignment,
     )