How to compile .so for Android O without Writable and Executable Segments? How to set specific ELF permissions?

陌路散爱 提交于 2019-12-02 06:14:31

问题


https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#Writable-and-Executable-Segments-Enforced-for-API-level-26

Currently Android O Preview 4 is blocking the loading of certain native libraries due to having Writable and Executable Segments. They determine this by doing a scan of the ELF.

I am trying to compile a native shared object library for Android without such Writable and Executable Segments.

Not being very familiar with this type of low-level compilation-speak, can someone explain how to set the segments to be properly mutually exclusive with respect to writable and executable permissions?

I figure I may need to add some specific flags to my Android.mk file to prevent this issue, with other initial thoughts that this may be something to do with the NDK toolchain being used for compilation.

Any help or advice on where to look is appreciated.


回答1:


The GNU toolchains and the Android toolchains have been doing the right thing for a long, long time now. You can use the readelf/grep command in the article:

$ readelf --program-headers -W libBadFlags.so | grep WE

If there is no output, you should be fine. If there is output, you need to track down the source of the writable/executable mapping. For a GNU_STACK header, it is likely an assembler file with a missing annotation (a mere oversight). But much more obscure things are possible, so there is no generic solution.

But in most cases, no changes to your project should be needed.



来源:https://stackoverflow.com/questions/45512293/how-to-compile-so-for-android-o-without-writable-and-executable-segments-how-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!