其他分享
首页 > 其他分享> > error: only position independent executables (PIE) are supported

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

标签:executables,independent,linker,run,supported,PIE,pie,android
来源: https://blog.51cto.com/u_15147256/2799146