HKG15-308: Kick-start your 64-bit AOSP build engines

21
Presented by Date HKG15-308: Kick-start your 64- bit AOSP build engines Amit Pundir February 2015

Transcript of HKG15-308: Kick-start your 64-bit AOSP build engines

Page 1: HKG15-308: Kick-start your 64-bit AOSP build engines

Presented by

Date

HKG15-308: Kick-start your 64-bit AOSP build engines

Amit Pundir

February 2015

Page 2: HKG15-308: Kick-start your 64-bit AOSP build engines

Android Multilib Build Cheat Sheet

● AOSP build configurations○ 32bit only, 64bit only and Multilib builds

● How to do a Multilib Build○ Multilib platform configuration○ Building Multilib Android Modules

● Multilib examples from AOSP

Page 3: HKG15-308: Kick-start your 64-bit AOSP build engines

AOSP Build Configurations

● 32bit only builds

● 64bit only builds

● Multilib builds○ 64bit Primary and 32bit Secondary○ 32bit Primary and 64bit Secondary

Page 4: HKG15-308: Kick-start your 64-bit AOSP build engines

AOSP Build Configurations

● 32bit only builds○ Android on 32bit arch○ Target support 32bit applications only○ Can be run on 64bit ARCH as well (Remember Juice?)

● 64bit only builds○ Android on 64bit arch○ Target support 64bit applications only○ Builds successfully but doesn’t boot up. Last tried booting on android-

5.0.2_r1

Page 5: HKG15-308: Kick-start your 64-bit AOSP build engines

Multilib builds

● Build/rootfs configuration supporting 64bit and 32bit applications

● 64bit Primary and 32bit Secondary○ 64bit arch is configured as the Primary arch and 32bit as Secondary.○ 64bit is the default target arch for modules if not configured otherwise.○ system_server will run as a 64bit process.

● 32bit Primary and 64bit Secondary○ Similar to 64bit Primary and 32bit Secondary. Build is broken for android-

5.0.2_r1

Page 6: HKG15-308: Kick-start your 64-bit AOSP build engines

Multilib builds

● Primary and Secondary Zygotes○ Multilib builds run two zygote processes (Primary and Secondary)

processes to support both 64bit and 32bit applications○ Zygote init config is not part of init.rc anymore. init.rc include init.${ro.

zygote}.rc at runtime which initialize zygotes

Enable/Select Multilib zygote in device config:PRODUCT_DEFAULT_PROPERTY_OVERRIDES += ro.zygote=zygote64_32PRODUCT_COPY_FILES += system/core/rootdir/init.zygote64_32.rc:root/init.zygote64_32.rc

In init.zygote64_32.rc:service zygote --> /system/bin/app_process64 --> 64bit VM Primaryservice zygote_secondary --> /system/bin/app_process32 --> 32bit VM Secondary

Page 7: HKG15-308: Kick-start your 64-bit AOSP build engines

How to do a Multilib build

● Multilib platform configuration○ Target archs○ Application support○ Custom toolchains

● Building Multilib modules○ Local build flags○ Building arch specific modules○ Binary installation path○ Handling pre-built modules

Page 8: HKG15-308: Kick-start your 64-bit AOSP build engines

Multilib platform configuration

● Target ARCH(s)○ Primary ARCH:

■ TARGET_ARCH and TARGET_CPU_* variables defined as usualTARGET_ARCH := arm64TARGET_ARCH_VARIANT := armv8-aTARGET_CPU_VARIANT := genericTARGET_CPU_ABI := arm64-v8a

○ Secondary ARCH:■ Android build system uses TARGET_2ND_* variables to set up an additional

compilation environment for the secondary archTARGET_2ND_ARCH := armTARGET_2ND_ARCH_VARIANT := armv7-a-neonTARGET_2ND_CPU_VARIANT := cortex-a15TARGET_2ND_CPU_ABI := armeabi-v7aTARGET_2ND_CPU_ABI2 := armeabi

Page 9: HKG15-308: Kick-start your 64-bit AOSP build engines

Multilib platform configuration

● Application SupportUse TARGET_SUPPORTS_32_BIT_APPS and TARGET_SUPPORTS_64_BIT_APPS

to choose which native libraries to build for an app.○ If both are set, it will use 64bit unless TARGET_PREFER_32_BIT is set.○ If only one is set, it will only build apps that work on that arch.○ If neither is set it will fall back to only building 32bit apps.

● Set Custom Toolchains○ Use TARGET_GCC_VERSION_EXP if you are using a common GCC toolchain

version for both the archs.○ Set TARGET_TOOLCHAIN_ROOT and 2ND_TARGET_TOOLCHAIN_ROOT to use different

toolchain versions for 64bit and 32bit binaries.

Page 10: HKG15-308: Kick-start your 64-bit AOSP build engines

Building Multilib modules

● Building an Android module with Multilib support○ Module names in product configuration, PRODUCT_PACKAGES, together with

the dependency graph decides what binaries will be built and installed to the system image.■ For libraries pulled in by dependency, a 32bit library is only installed if it’s

required by a 32bit library or executable. The same is true for 64bit libraries.■ For executables, by default the build system builds only the 64bit version, but

it can be overridden by a global BoardConfig.mk variable or a module-scoped variable

○ Module names on the make command line cover only the 64bit version. For example, after running “lunch aosp_arm64-eng”, “make libc” builds only the 64bit libc. To build the 32bit libc, you need to run “make libc_32”.

Page 11: HKG15-308: Kick-start your 64-bit AOSP build engines

Building Multilib modules

● Building an Android module with Multilib support○ Module names in product configuration, PRODUCT_PACKAGES, together with

the dependency graph decides what binaries will be built and installed to the system image.■ For libraries pulled in by dependency, a 32bit library is only installed if it’s

required by a 32bit library or executable. The same is true for 64bit libraries.■ For executables, by default the build system builds only the 64bit version, but

it can be overridden by a global BoardConfig.mk variable or a module-scoped variable

Page 12: HKG15-308: Kick-start your 64-bit AOSP build engines

Building Multilib modules

● Module definition in Android.mk○ Set LOCAL_MULTILIB to build for 64bit and/or 32bit archs

■ LOCAL_MULTILIB := first to build a module for the first architecture (64bit on a 64bit target, 32bit on a 32bit target). This is same as LOCAL_NO_2ND_ARCH := true

■ LOCAL_MULTILIB := 32 to build a module 32bit. This is the same as LOCAL_32_BIT_ONLY := true

■ LOCAL_MULTILIB := 64 is set then package.mk will use it to only install 64bit native apps on devices that only have a 64bit zygote.

■ LOCAL_MULTILIB := both to build for both architectures on a Mulitlib target.

If LOCAL_MULTILIB is not set libraries will default to "both", and executables, packages, and prebuilts will default to building for the first architecture if supported by the module, otherwise the second. LOCAL_MULTILIB overrides the global TARGET_PREFER_32_BIT.

Page 13: HKG15-308: Kick-start your 64-bit AOSP build engines

Building Multilib modules○ Local build flags:

To set up a local build, use the LOCAL_ variables.■ An arch-specific LOCAL_ variable is a normal LOCAL_ variable with an arch suffix

i.e. LOCAL_*_$(TARGET_ARCH) and LOCAL_*_$(TARGET_2ND_ARCH).● For example: LOCAL_CFLAGS_arm64, LOCAL_SRC_FILES_arm ..

■ Or set LOCAL_ variable with a _32 or _64 suffix based on whether it’s currently being built for 32bit or 64bit.● For example: LOCAL_SRC_FILES_32, LOCAL_SRC_FILES_64 ..

Page 14: HKG15-308: Kick-start your 64-bit AOSP build engines

Building Multilib modules○ Building for specific ARCH(s):

To do an arch-specific build, use the arch-specific variables.■ LOCAL_MODULE_TARGET_ARCH and LOCAL_MODULE_UNSUPPORTED_TARGET_ARCH

specifies that a module can or cannot be built for one or more architectures.■ LOCAL_MODULE_TARGET_ARCH_WARN and

LOCAL_MODULE_UNSUPPORTED_TARGET_ARCH_WARN are the same, but warn that the arch is not supported, which is useful for modules that are critical but not yet working.

If TARGET_PREFER_32_BIT is set then it needs to try the 32bit build rule first, then fall back to the 64bit rule in case the module specifies LOCAL_MODULE_TARGET_ARCH or LOCAL_MODULE_UNSUPPORTED_TARGET_ARCH is set to disallow the 32bit build.

Page 15: HKG15-308: Kick-start your 64-bit AOSP build engines

Building Multilib modules○ Installation Path:

■ Libraries: /system/lib always contain 32bit libraries, and /system/lib64 will always have 64bit libraries.

■ Executables: If you build an executable as both 32bit and 64bit, then wither set LOCAL_MODULE_STEM_32 and LOCAL_MODULE_STEM_64 to distinguish the installed file name, or set LOCAL_MODULE_PATH_32, LOCAL_MODULE_PATH_64 to distinguish the install path.

Set LOCAL_MODULE_RELATIVE_PATH in multilib builds to set the install location instead of LOCAL_MODULE_PATH. In multilib builds the install location depends on the arch. HALs will generally use: LOCAL_MODULE_RELATIVE_PATH := hw

Page 16: HKG15-308: Kick-start your 64-bit AOSP build engines

Building Multilib modules○ Handling pre-built Multilib modules:

■ Pre-built Multilib modules are handled as beforeinclude $(CLEAR_VARS)LOCAL_MODULE := libsampleLOCAL_MULTILIB := bothLOCAL_SRC_FILES_arm64 := arm64/$(LOCAL_MODULE).soLOCAL_SRC_FILES_arm := arm/$(LOCAL_MODULE).soLOCAL_MODULE_CLASS := SHARED_LIBRARIESLOCAL_MODULE_SUFFIX := .soLOCAL_MODULE_TAGS := optionalinclude $(BUILD_PREBUILT)

■ All the build rules for Multilib modules hold true for pre-built modules as well. For example: if you don’t provide LOCAL_MODULE_STEM_{64,32} or LOCAL_MODULE_PATH_{64,32}, then _32 executable will override the _64 executable in /system/bin.

Page 17: HKG15-308: Kick-start your 64-bit AOSP build engines

Multilib Examples from AOSP● device/htc/flounder/Boardconfig.mk

○ Device config or Global build variables usage

● system/core/debuggerd/Android.mk○ Local or Module build variables usage

Page 18: HKG15-308: Kick-start your 64-bit AOSP build engines

● 64_32 device config: Flounderdevice/htc/flounder/BoardConfig.mk○ Set Primary, Secondary CPUs and

supported ABIs○ TARGET_USES_64_BIT_BINDER should be

set even while doing a 32bit only build for a 64bit arch.

○ TARGET_SUPPORTS_{64,32}_BIT_APPS, target support 64bit and/or 32bit applications.

Page 19: HKG15-308: Kick-start your 64-bit AOSP build engines

● Multilib Android Module: debuggerdsystem/core/debuggerd/Android.mk○ LOCAL_SRC_FILES, common src○ LOCAL_SRC_FILES_*, Arch specific src○ TARGET_IS_64_BIT, true if TARGET_ARCH is

64bit i.e. {arm64, x86_64 or mips64}.○ LOCAL_MODULE_STEM_*, install

executables at same location i.e. /system/bin with different names.

○ LOCAL_MULTILIB, build module for both Archs.

Page 21: HKG15-308: Kick-start your 64-bit AOSP build engines