onnxruntime
84841991 - Fix libonnxruntime4j_jni.so 16KB page size compatibility on Android ARM64 (#24947)

Commit
361 days ago
Fix libonnxruntime4j_jni.so 16KB page size compatibility on Android ARM64 (#24947) ## Problem The `libonnxruntime4j_jni.so` native library was incompatible with 16KB page size configuration on ARM64 Android devices, while the main `libonnxruntime.so` was already compatible. This affected: - Modern Android devices using 16KB page configuration - Apple Silicon Macs running Android emulators - Any ARM64 system configured with 16KB pages ## Root Cause The issue occurred because: 1. The main `libonnxruntime.so` is built as a SHARED library and inherits `CMAKE_SHARED_LINKER_FLAGS` which contains the 16KB alignment flag (`-Wl,-z,max-page-size=16384`) 2. The `libonnxruntime4j_jni.so` is built as a MODULE library via `onnxruntime_add_shared_library_module()` function 3. `CMAKE_SHARED_LINKER_FLAGS` only applies to SHARED libraries, not MODULE libraries 4. Therefore, the JNI library was missing the required 16KB alignment ## Solution Added `CMAKE_MODULE_LINKER_FLAGS` alongside the existing `CMAKE_SHARED_LINKER_FLAGS` in `cmake/adjust_global_compile_flags.cmake` to ensure MODULE libraries also receive the 16KB alignment flag on Android builds. ```cmake if (ANDROID) # Build shared libraries with support for 16 KB ELF alignment # https://source.android.com/docs/core/architecture/16kb-page-size/16kb#build-lib-16kb-alignment set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384") # Also apply to MODULE libraries (like libonnxruntime4j_jni.so) set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,max-page-size=16384") endif() ``` ## Impact - ✅ `libonnxruntime.so`: Already compatible (no change) - ✅ `libonnxruntime4j_jni.so`: Now compatible (fixed) - ✅ All provider libraries: Compatible (inherit global flags) - ✅ Zero impact on non-Android platforms - ✅ Minimal change: only 2 lines added ## Testing The fix has been validated to: - Apply 16KB alignment to both SHARED and MODULE libraries on Android - Only affect Android builds (properly guarded by `if (ANDROID)`) - Follow existing CMake patterns in the codebase - Preserve all existing functionality Fixes #24902. > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `http://168.63.129.16:80/machine/` > - Triggering command: `/usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs ` (http block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to my [firewall allow list](https://gh.io/copilot/firewall-config) > > </details> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: vraspar <51386888+vraspar@users.noreply.github.com>
Author
Parents
Loading