关闭patchoat

关闭patchoat可以减少data分区的占用并加快开机速度,但可能增加安全风险。通过在/art/runtime/globals.h和/frameworks/base/core/jni/AndroidRuntime.cpp中修改代码,可以关闭patchoat。该操作将data空间占用减少69%,开机时间缩短76%。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

art patchoat

This tool takes already compiled images and oat files and changes their base address, acting as a cheap form of relocation.

Add a –include-patch-information flag to dex2oat and code to add required patch information to oat files created with the quick compiler.

https://android.googlesource.com/platform/art/+/53cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3c

关闭patchoat

尽管打开了WITH_PREODEX之后,已经生成了odex文件,但是第一次开机的时候,android会去做patchoat的动作,会修改odex文件偏移量,并放到/data/dalvik-cache/arm/目录下面。这样做主要是为了安全考虑,因为ELF文件被load进系统之后,如果每一次都映射同样的位置,很容易被hack利用这一点进行攻击。如果不考虑这种安全性问题,可以把这个属性给关闭。
关闭方法如下:
/art/runtime/globals.h

static constexpr bool kDefaultMustRelocate = false; //从而可以取消patch oat。

MTK平台还要修改如下的地方,否则有一些三方工具运行不起来:
/frameworks/base/core/jni/AndroidRuntime.cpp

#if 1 //将if 1改为#if 0,从而避免等待。
 if (!bootOatDone) {
     if (!strcmp(className, "com.android.internal.os.RuntimeInit")) {
         waitOatDone();
         bootOatDone = true;
     }
 }
#endif

这样修改之后既可以减小data分区的空间,又可以加快开机速度,但风险就是容易被hack利用固定映射地址进行攻击。

  • /data空间从开机后占用686.4M减少到212.4M,空间占用减少69%。
  • 第一次开机时间从179s减少到42s,耗时减少76%。
FAILED: out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/boot.art /bin/bash -c "(mkdir -p out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm/ ) && (rm -f out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm//*.art out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm//*.oat out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm//*.art.rel ) && (rm -f out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm//*.art ) && (rm -f out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm//*.oat ) && (rm -f out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm//*.art.rel ) && (ANDROID_LOG_TAGS=\"*:e\" out/host/linux-x86/bin/dex2oatd --runtime-arg -Xms64m --runtime-arg -Xmx64m --compiler-filter=speed-profile --profile-file=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot.prof --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-framework_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-telephony-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-telephony-base_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/core-oj_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/okhttp_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/bouncycastle_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/apache-xml_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/voip-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/ims-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.hidl.base-V1.0-java_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.hidl.manager-V1.0-java_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/framework-oahl-backward-compatibility_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.test.base_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-ims-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-telecom-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-cta_intermediates/javalib.jar --dex-location=/system/framework/mediatek-common.jar --dex-location=/system/framework/mediatek-framework.jar --dex-location=/system/framework/mediatek-telephony-common.jar --dex-location=/system/framework/mediatek-telephony-base.jar --dex-location=/system/framework/core-oj.jar --dex-location=/system/framework/core-libart.jar --dex-location=/system/framework/conscrypt.jar --dex-location=/system/framework/okhttp.jar --dex-location=/system/framework/bouncycastle.jar --dex-location=/system/framework/apache-xml.jar --dex-location=/system/framework/ext.jar --dex-location=/system/framework/framework.jar --dex-location=/system/framework/telephony-common.jar --dex-location=/system/framework/voip-common.jar --dex-location=/system/framework/ims-common.jar --dex-location=/system/framework/android.hidl.base-V1.0-java.jar --dex-location=/system/framework/android.hidl.manager-V1.0-java.jar --dex-location=/system/framework/framework-oahl-backward-compatibility.jar --dex-location=/system/framework/android.test.base.jar --dex-location=/system/framework/mediatek-ims-common.jar --dex-location=/system/framework/mediatek-telecom-common.jar --dex-location=/system/framework/mediatek-cta.jar --oat-symbols=out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm/boot.oat --oat-file=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/boot.oat --oat-location=/system/framework/arm/boot.oat --image=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/boot.art --base=0x70000000 --instruction-set=arm --instruction-set-variant=cortex-a53 --instruction-set-features=default --android-root=out/target/product/p12_k37mv1_bsp/system --runtime-arg -Xnorelocate --compile-pic --no-generate-debug-info --generate-build-id --multi-image --no-inline-from=core-oj.jar --abort-on-hard-verifier-error --abort-on-soft-verifier-error --no-abort-on-soft-verifier-error --generate-mini-debug-info || ( echo \"ERROR: Dex2oat failed to compile a boot image. It is likely that the boot classpath is inconsistent. Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS=\"--runtime-arg -verbose:verifier\" to see verification errors.\" ; false ) && ANDROID_LOG_TAGS=\"*:e\" ANDROID_ROOT=out/target/product/p12_k37mv1_bsp/system ANDROID_DATA=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/ out/host/linux-x86/bin/patchoatd --input-image-location=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot.art --output-image-relocation-directory=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/ --instruction-set=arm --base-offset-delta=0x10000000 )" patchoatd E 08-01 17:03:32 1204514 1204514 image_space.cc:1761] Could not create image space with image file 'out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot.art'. Attempting to fall back to imageless running. Error was: Failed to mmap at expected address, mapped at 0x72f9d8a00000 instead of 0x7057a000 patchoatd E 08-01 17:03:32 1204514 1204514 image_space.cc:1761] Attempted image: out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot-framework.art patchoatd E 08-01 17:03:32 1204514 1204514 runtime.cc:1290] Dex file fallback disabled, cannot continue without image. patchoatd E 08-01 17:03:32 1204514 1204514 patchoat.cc:485] Unable to initialize runtime [ 32% 292/886] //frameworks/base/media/jni:libmedia2_jni link libmedia2_jni.so ninja: build stopped: subcommand failed. 17:03:37 ninja failed with: exit status 1
08-02
FAILED: out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/boot.art /bin/bash -c "(mkdir -p out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm/ ) && (rm -f out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm//*.art out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm//*.oat out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm//*.art.rel ) && (rm -f out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm//*.art ) && (rm -f out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm//*.oat ) && (rm -f out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm//*.art.rel ) && (ANDROID_LOG_TAGS=\"*:e\" out/host/linux-x86/bin/dex2oatd --runtime-arg -Xms64m --runtime-arg -Xmx64m --compiler-filter=speed-profile --profile-file=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot.prof --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-framework_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-telephony-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-telephony-base_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/core-oj_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/okhttp_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/bouncycastle_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/apache-xml_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/voip-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/ims-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.hidl.base-V1.0-java_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.hidl.manager-V1.0-java_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/framework-oahl-backward-compatibility_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.test.base_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-ims-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-telecom-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-cta_intermediates/javalib.jar --dex-location=/system/framework/mediatek-common.jar --dex-location=/system/framework/mediatek-framework.jar --dex-location=/system/framework/mediatek-telephony-common.jar --dex-location=/system/framework/mediatek-telephony-base.jar --dex-location=/system/framework/core-oj.jar --dex-location=/system/framework/core-libart.jar --dex-location=/system/framework/conscrypt.jar --dex-location=/system/framework/okhttp.jar --dex-location=/system/framework/bouncycastle.jar --dex-location=/system/framework/apache-xml.jar --dex-location=/system/framework/ext.jar --dex-location=/system/framework/framework.jar --dex-location=/system/framework/telephony-common.jar --dex-location=/system/framework/voip-common.jar --dex-location=/system/framework/ims-common.jar --dex-location=/system/framework/android.hidl.base-V1.0-java.jar --dex-location=/system/framework/android.hidl.manager-V1.0-java.jar --dex-location=/system/framework/framework-oahl-backward-compatibility.jar --dex-location=/system/framework/android.test.base.jar --dex-location=/system/framework/mediatek-ims-common.jar --dex-location=/system/framework/mediatek-telecom-common.jar --dex-location=/system/framework/mediatek-cta.jar --oat-symbols=out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm/boot.oat --oat-file=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/boot.oat --oat-location=/system/framework/arm/boot.oat --image=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/boot.art --base=0x70000000 --instruction-set=arm --instruction-set-variant=cortex-a53 --instruction-set-features=default --android-root=out/target/product/p12_k37mv1_bsp/system --runtime-arg -Xnorelocate --compile-pic --no-generate-debug-info --generate-build-id --multi-image --no-inline-from=core-oj.jar --abort-on-hard-verifier-error --abort-on-soft-verifier-error --no-abort-on-soft-verifier-error --generate-mini-debug-info || ( echo \"ERROR: Dex2oat failed to compile a boot image. It is likely that the boot classpath is inconsistent. Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS=\"--runtime-arg -verbose:verifier\" to see verification errors.\" ; false ) && ANDROID_LOG_TAGS=\"*:e\" ANDROID_ROOT=out/target/product/p12_k37mv1_bsp/system ANDROID_DATA=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/ out/host/linux-x86/bin/patchoatd --input-image-location=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot.art --output-image-relocation-directory=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/ --instruction-set=arm --base-offset-delta=0x10000000 )" patchoatd E 08-01 17:32:01 1225778 1225778 image_space.cc:1761] Could not create image space with image file 'out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot.art'. Attempting to fall back to imageless running. Error was: Failed to mmap at expected address, mapped at 0x7ead86400000 instead of 0x7057a000 patchoatd E 08-01 17:32:01 1225778 1225778 image_space.cc:1761] Attempted image: out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot-framework.art patchoatd E 08-01 17:32:01 1225778 1225778 runtime.cc:1290] Dex file fallback disabled, cannot continue without image. patchoatd E 08-01 17:32:01 1225778 1225778 patchoat.cc:485] Unable to initialize runtime ninja: build stopped: subcommand failed. 17:32:01 ninja failed with: exit status 1 怎么关闭
最新发布
08-02
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值