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

最近由于要测试在 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 -pie
LOCAL_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);
   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值