android PIE error: only position independent executables (PIE) are supported解决方法

来源:互联网 发布:post json method 编辑:程序博客网 时间:2024/06/03 15:34
最近由于要测试在Android L上的运行情况发现,当运行某些可执行文件时,报如下错误:


error: only position independent executables (PIE) are supported.

PIE这个安全机制从4.1引入,但是Android L之前的系统版本并不会去检验可执行文件是否基于PIE编译出的。因此不会报错。但是Android L已经开启验证,如果调用的可执行文件不是基于PIE方式编译的,则无法运行。解决办法非常简单,在Android.mk中加入如下flag就行。

LOCAL_CFLAGS += -fPIE -pieLOCAL_LDFLAGS += -fPIE -pie

如果是自己定制系统且需要兼容之前的程序,可以去除PIE的校验。

可以修改/system/bin/linker文件。

google官方增加PIE验证的log:

https://android.googlesource.com/platform/bionic/+/2aebf5429bb1241a3298b5b642d38f73124c2026%5E!/#F0

如下:

可以修改android源码的bionic/linker/linker.cpp文件

屏蔽如下代码:

ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);  if (elf_hdr->e_type != ET_DYN) { __libc_format_fd(2, "error: only position independent executables (PIE) are supported.\n");        exit(EXIT_FAILURE);   }

0 0