native icon indicating copy to clipboard operation
native copied to clipboard

[native_toolchain_c] Android 15 16kb elf alignment

Open dcharkes opened this issue 1 year ago • 5 comments

Android 15 has the support to require dylib elf sections to be 16kb aligned.

We should probably have a default flag for this in package:native_toolchain_c so that packages using flutter create --template package_ffi will work out of the box for Android 15 devices with 16kb memory pages.

Context:

  • https://github.com/flutter/flutter/pull/155508
  • https://developer.android.com/guide/practices/page-sizes#compile-r26-lower

dcharkes avatar Sep 27 '24 12:09 dcharkes

Also possibly related https://github.com/flutter/flutter/issues/125090

reidbaker avatar Sep 27 '24 13:09 reidbaker

Out of curiosity: Does Android's NDK compiler toolchain not automatically use 16 KB by-default? Or is this for handling older Android compiler toolchains that don't have that default yet?

mkustermann avatar Sep 27 '24 13:09 mkustermann

Related: https://github.com/dart-lang/native/issues/1608

Out of curiosity: Does Android's NDK compiler toolchain not automatically use 16 KB by-default? Or is this for handling older Android compiler toolchains that don't have that default yet?

NDK r27 does with this flag set: -DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON

HosseinYousefi avatar Sep 27 '24 13:09 HosseinYousefi

Out of curiosity: Does Android's NDK compiler toolchain not automatically use 16 KB by-default? Or is this for handling older Android compiler toolchains that don't have that default yet?

We're currently still on r26b on the CI here:

https://github.com/dart-lang/native/blob/16918aef9da60646e5ae0ad0307fe0e1a64355b2/.github/workflows/native.yaml#L55

Also flutter_tools is at 26 at the moment:

https://github.com/flutter/flutter/blob/9be22b58c4bfe8b6cb447de13a500db4e1bd8c33/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy#L58-L63

If you invoke 27 or up directly (not via Groovy, Kotlin, or Application.mk) it also requires passing the flag: https://developer.android.com/guide/practices/page-sizes#other-build-systems

dcharkes avatar Sep 27 '24 14:09 dcharkes

Bumping the version on the CI here:

  • https://github.com/dart-lang/native/pull/1612

dcharkes avatar Sep 27 '24 14:09 dcharkes

Workaround before we address this:

    final cbuilder = CBuilder.library(
      name: packageName,
      assetName: '${packageName}_bindings_generated.dart',
      sources: [
        'src/$packageName.c',
      ],
      flags: ['-Wl,-z,max-page-size=16384',], // <----
    );

dcharkes avatar Oct 11 '24 17:10 dcharkes