error: only position independent executables (PIE) are supported


    PIE, position independent executables.

    android 4.1上开始支持PIE,所以4.1之前的版本不能使用PIE的executable,而之前开发的app一般都是非PIE的。

    Android 4.1
    
            PIE (Position Independent Executable) support
            Read-only relocations / immediate binding (-Wl,-z,relro -Wl,-z,now)
            dmesg_restrict enabled (avoid leaking kernel addresses)
            kptr_restrict enabled (avoid leaking kernel addresses)
    
    

    在android L后,linker.cpp中,

    //bionic\linker\linker.cpp
    static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(Addr) linker_base) {
      ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
      //不是PIE的直接报错返回,而之前的版本中都没有
      if (elf_hdr->e_type != ET_DYN) {
        __libc_format_fd(2, "error: only position independent executables (PIE) are supported.\n");
        exit(EXIT_FAILURE);
      }
    }

    所以在android L后,非PIE的exe执行都会报错error: only position independent executables (PIE) are supported.

    1.但是如果在android 4.1之前的版本运行PIE, 也是有办法的:
    The Chromium project released a wrapper that allows PIE binaries to run on pre-JB Android releases。

    具体的使用方法见http://stackoverflow.com/questions/24818902/running-a-native-library-on-android-l-error-only-position-independent-executab

    其中run_pie在android L中的external\chromium_org\tools\android\run_pie中可找到,下面是run_pie.c中的注释,说明run_pie主要是为了在linker不支持PIE的早期版本中运行PIE。

    // This is a wrapper to run position independent executables on Android ICS,
    // where the linker doesn't support PIE. This requires the PIE binaries to be
    // built with CFLAGS +=-fvisibility=default -fPIE, and LDFLAGS += -rdynamic -pie
    // such that the main() symbol remains exported and can be dlsym-ed.

    2.那么在android L之后的版本运行非PIE,有没有办法?
    目前是没有解决方案,除非你把bionic的linker替换,具体参考下面的文章,使用其中修改编译过的linker, http://forum.xda-developers.com/google-nexus-5/development/fix-bypassing-pie-security-check-t2797731

    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值