Android IFUNC支持
IFUNC概念
参考 GNU_IFUNC。
Android支持限制
在 Android linker changes for NDK developers 中描述,android api>=29才支持该特性:
Use of IFUNC in libc (True for all API levels on devices running Q)
Starting with Android Q (API level 29), libc uses IFUNC functionality in the dynamic linker to choose optimized assembler routines at run time rather than at build time. This lets us use the same libc.so on all devices, and is similar to what other OSes already did. Because the zygote uses the C library, this decision is made long before we know what API level an app targets, so all code sees the new IFUNC-using C library. Most apps should be unaffected by this change, but apps that hook or try to detect hooking of C library functions might need to fix their code to cope with IFUNC relocations. The affected functions are from <string.h>, but may expand to include more functions (and more libraries) in future.
而且到目前为止,只有<string.h>
的函数才使用了该特性。
这从linker64 DSO
中就可以看到:
xuwakao@chiefhsing-PC:~/android-11.0.0_r29/out/target/product/crosshatch$ ~/Android/Sdk/ndk/20.0.5594570/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/readelf -s ./apex/com.android.runtime/bin/linker64 | grep 'IFUNC'
6993: 00000000000bf404 12 IFUNC LOCAL DEFAULT 11 __dl_strchr
6994: 00000000000bf410 12 IFUNC LOCAL DEFAULT 11 __dl_strcmp
6995: 00000000000bf41c 12 IFUNC LOCAL DEF