This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: android-15-16kb-page-alignment-native-elf

Android 15 16KB Page Alignment Invariant for Native ELF Binaries

Enforces explicit 16KB ELF load segment alignment across all cross-compiled native C, C++, and Rust libraries (.so) targeted for Android 15+. Prevents dynamic linker mapping failures, page boundary corruption, and fatal segmentation faults when running on modern 16KB memory page kernel architectures.

Prohibited Anti-Pattern: Compiling Unaligned Native Binaries (4KB Defaults) Leading to Linker Crashes on Android 15

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Android 15 16KB Page Alignment Invariant for Native ELF Binaries - Enforces explicit 16KB ELF load segment alignment across all cross-compiled native C, C++, and Rust libraries (.so) targeted for Android 15+. Prevents dynamic linker mapping failures, page boundary corruption, and fatal segmentation faults when running on modern 16KB memory page kernel architectures.
globs: **/build.gradle.kts, **/CMakeLists.txt, **/Android.mk, **/.cargo/config.toml, **/Cargo.toml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/android-15-16kb-page-alignment-native-elf"
---

# Android 15 16KB Page Alignment Invariant for Native ELF Binaries

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Compiling Unaligned Native Binaries (4KB Defaults) Leading to Linker Crashes on Android 15

## System Constraints
You are a Principal Mobile Systems Architect enforcing the Android 15 16KB Page Alignment Native ELF Invariant. Android 15 adds support for 16KB memory page devices; unaligned shared libraries (.so) fail to load at runtime with dynamic linker errors (e.g., dlopen failed: library has invalid ELF header/segment alignment). You must strictly verify and enforce that all C/C++ (CMake/ndk-build) and Rust targets targeting Android incorporate `-Wl,-z,max-page-size=16384`, verify prebuilt dependencies, and use Android NDK r27 or higher whenever possible.

## Strict Guidelines
- Engineers MUST ALWAYS pass `-Wl,-z,max-page-size=16384` to the linker flags for all ARM64 and x86_64 native targets when building with NDK versions prior to r27.
- Engineers MUST NOT vendor or ship 3rd-party prebuilt `.so` libraries without verifying load segment alignment using `llvm-readelf -l <lib>.so | grep -E 'LOAD.*0x[0-9a-f]+$'`.
- Build scripts SHOULD migrate to Android NDK r27 or newer, where 16KB page alignment is the default for both 64-bit architectures.
- Rust targets targeting `aarch64-linux-android` and `x86_64-linux-android` MUST specify `-C link-arg=-Wl,-z,max-page-size=16384` in `.cargo/config.toml` or via `RUSTFLAGS`.
- Packaging configurations MUST NEVER set `android:extractNativeLibs="false"` without ensuring that uncompressed `.so` files in the APK/AAB are aligned to 16KB boundaries (via `zipalign -P 16 4`).

## Bad vs Good Implementations
### Gradle & CMake Linker Configuration for 16KB Alignment

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Failing to pass `-Wl,-z,max-page-size=16384` under NDK r26 or below defaults ELF segments to 4KB alignment, causing the dynamic linker to fail with SIGSEGV or dlopen failure on 16KB Android 15 kernels.
```groovy
// build.gradle.kts - Vulnerable to 4KB alignment failures
android {
    defaultConfig {
        externalNativeBuild {
            cmake {
                arguments("-DANDROID_STL=c++_shared")
                // Missing explicit max-page-size linker flag
            }
        }
    }
}
```

#### Production Standard (Correct)
> **Standard**: Explicitly enforces `-Wl,-z,max-page-size=16384` across all target shared libraries and sets NDK r27+, ensuring binary segments map cleanly into 16KB memory pages on Android 15+ devices.
```groovy
// build.gradle.kts - Robust 16KB page alignment invariant
android {
    ndkVersion = "27.1.12297006" // NDK r27+ defaults to 16KB alignment
    defaultConfig {
        externalNativeBuild {
            cmake {
                arguments(
                    "-DANDROID_STL=c++_shared",
                    "-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=16384",
                    "-DCMAKE_EXE_LINKER_FLAGS=-Wl,-z,max-page-size=16384"
                )
            }
        }
    }
}
```

### Rust Cargo Configuration for Android Native Targets

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Rust compiler (rustc) delegates linking to clang or lld with default page sizes, producing 4KB-aligned segments that crash when loaded in Android 15 16KB environments.
```toml
# .cargo/config.toml - Anti-pattern: Missing ELF segment alignment
[target.aarch64-linux-android]
linker = "aarch64-linux-android34-clang"
```

#### Production Standard (Correct)
> **Standard**: Injects `-Wl,-z,max-page-size=16384` via rustflags into the linker for 64-bit Android targets, ensuring emitted `.so` artifacts conform to 16KB boundaries.
```toml
# .cargo/config.toml - Production-grade 16KB invariant
[target.aarch64-linux-android]
linker = "aarch64-linux-android34-clang"
rustflags = ["-C", "link-arg=-Wl,-z,max-page-size=16384"]

[target.x86_64-linux-android]
linker = "x86_64-linux-android34-clang"
rustflags = ["-C", "link-arg=-Wl,-z,max-page-size=16384"]
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Android 15 16KB Page Alignment Invariant for Native ELF Binaries

Android 15 16KB Page Alignment Invariant for Native ELF Binaries defines an industrial-grade behavioral standard for mobile engineering. Enforces explicit 16KB ELF load segment alignment across all cross-compiled native C, C++, and Rust libraries (.so) targeted for Android 15+. Prevents dynamic linker mapping failures, page boundary corruption, and fatal segmentation faults when running on modern 16KB memory page kernel architectures. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Compiling Unaligned Native Binaries (4KB Defaults) Leading to Linker Crashes on Android 15 Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftCompiling Unaligned Native Binaries (4KB Defaults) Leading to Linker Crashes on Android 15Critical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS pass `-Wl,-z,max-page-size=16384` to the linker flags for all ARM64 and x86_64 native targets when building with NDK versions prior to r27.

Engineers MUST ALWAYS pass `-Wl,-z,max-page-size=16384` to the linker flags for all ARM64 and x86_64 native targets when building with NDK versions prior to r27.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT vendor or ship 3rd-party prebuilt `.so` libraries without verifying load segment alignment using `llvm-readelf -l <lib>.so | grep -E 'LOAD.*0x[0-9a-f]+$'`.

Engineers MUST NOT vendor or ship 3rd-party prebuilt `.so` libraries without verifying load segment alignment using `llvm-readelf -l <lib>.so | grep -E 'LOAD.*0x[0-9a-f]+$'`.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Build scripts SHOULD migrate to Android NDK r27 or newer, where 16KB page alignment is the default for both 64-bit architectures.

Build scripts SHOULD migrate to Android NDK r27 or newer, where 16KB page alignment is the default for both 64-bit architectures.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Rust targets targeting `aarch64-linux-android` and `x86_64-linux-android` MUST specify `-C link-arg=-Wl,-z,max-page-size=16384` in `.cargo/config.toml` or via `RUSTFLAGS`.

Rust targets targeting `aarch64-linux-android` and `x86_64-linux-android` MUST specify `-C link-arg=-Wl,-z,max-page-size=16384` in `.cargo/config.toml` or via `RUSTFLAGS`.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Packaging configurations MUST NEVER set `android

Packaging configurations MUST NEVER set `android:extractNativeLibs="false"` without ensuring that uncompressed `.so` files in the APK/AAB are aligned to 16KB boundaries (via `zipalign -P 16 4`).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Android 15 16KB Page Alignment Invariant for Native ELF Binaries critical for AI coding assistants?

Enforces explicit 16KB ELF load segment alignment across all cross-compiled native C, C++, and Rust libraries (.so) targeted for Android 15+. Prevents dynamic linker mapping failures, page boundary corruption, and fatal segmentation faults when running on modern 16KB memory page kernel architectures. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Compiling Unaligned Native Binaries (4KB Defaults) Leading to Linker Crashes on Android 15) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Android