【错误笔记】NDK编译程序运行出现 unused DT entry 错误

文章目录

  • 一、问题描述
  • 二、原因分析
    • 1. 先看官方对问题给出的一些描述
    • 2. 总结
  • 三、解决方法
  • 四、制作 android-elf-cleaner 工具
    • 1. github地址
    • 2. 编译
    • 3. 使用
  • 五、android系统版本 和 API 对应表

一、问题描述

NDK版本:ndk16b;

使用 NDK 制作的编译工具链编译出可执行文件后,传到 Android 中运行的时候,会出现如下的 WARNING 信息:

root@XXX_Device:/data/test # ./test
WARNING: linker: ./test: unused DT entry: type 0x6ffffffe arg 0xb04
WARNING: linker: ./test: unused DT entry: type 0x6ffffffe arg 0x1
...

提示信息可能有些数据不相同,但都属于 unused DT entry 问题;

二、原因分析

1. 先看官方对问题给出的一些描述

  • Q: What are “unused DT entry” errors?

    If you have reached this page, it’s probably because you have compiled or attempted to run some binaries on your ARM based Android system, with the result that your binary/app crashes or generates a lot of warnings in your logcat. Typically something like this:

    WARNING: linker: /blahblah/libopenssl.so: unused DT entry: type 0x6ffffffe arg 0x1188

  • Q: What is a “DT entry”?

    In a few words, they are descriptive array entries in the file structure of an ELF file. Specifically they are known as Dynamic Array Tags and are requirements for executable and shared objects. However, not all entries are required or available, depending on the processor and kernel architecture.

    In our case we are faced with a “Warning” that one of these are “unused”. What that means is, that your executable or library (*.so) files has been compiled with the DT entry indicated, but your kernel is not supporting that entry, for various reasons. The best examples are found on ARM based Android systems, where the system library paths are fixed and the cross compilers used for your firmware (OS/kernel) are set not to use these entries. Usually the binaries still run just fine, but the kernel is flagging this warning every time you’re using it.

  • Q: When does this happen?

    This can happen when:

    • Your ARM kernel is cross-compiled using the wrong flags (usually meant for other processor architectures).
    • Your ARM binaries and libraries are cross-compiled using AOS deprecated compilation flags.
    • and probably other ways yet to be discovered…

    Starting from 5.1 (API 22) the Android linker warns about the VERNEED and VERNEEDNUM ELF dynamic sections.

    The most common flags that cause this error on Android devices are:

    • DT_RPATH 0x0f (15) The DT_STRTAB string table offset of a null-terminated library search path string. This element’s use has been superseded by DT_RUNPATH.
    • DT_RUNPATH 0x1d (29) The DT_STRTAB string table offset of a null-terminated library search path string.
    • DT_VERNEED 0x6ffffffe The address of the version dependency table. Elements within this table contain indexes into the string table DT_STRTAB. This element requires that the DT_VERNEEDNUM element also be present.
    • DT_VERNEEDNUM 0x6fffffff The number of entries in the DT_VERNEEDNUM table.

2. 总结

官方已经给出了详细的说明、原因以及警告的类型,而且从 Android5.1开始,就会警告 verneed 和 verneednum 的问题;

下面给出解决方法:

三、解决方法

制作 android_elf_cleaner 工具,处理一下编译出来的可执行文件,再次运行即可消除此问题;

root@XXX_Device:/data/test # ./android-elf-cleaner ./test
./android-elf-cleaner: Removing the DT_VERNEEDED dynamic section entry from './test'
./android-elf-cleaner: Removing the DT_VERNEEDNUM dynamic section entry from './test'
root@XXX_Device:/data/test # 

四、制作 android-elf-cleaner 工具

1. github地址

android-elf-cleaner

2. 编译

直接在 linux 中执行 make 命令,即可编译得到 android-elf-cleaner 可执行程序;

3. 使用

usage: ./android-elf-cleaner <filename>
       Processes ELF files to remove DT_VERNEEDED, DT_VERNEEDNUM, DT_RPATH
       and DT_RUNPATH entries (which the Android linker warns about)

五、android系统版本 和 API 对应表

adb shell 获取 android 系统版本:
getprop ro.build.version.release
adb shell 获取 android 系统 API 版本:
getprop ro.build.version.sdk

API Level Android版本
28 9
27 8.1
26 8.0
25 7.1.1
24 7.0
23 6.0
22 5.1.1
21 5.0.1
20 4.4w.2
19 4.4.2
18 4.3.1
17 4.2.2
16 4.1.2
15 4.0.3
14 4.0
10 2.3
8 2.2

—— 2018-12-04 ——

你可能感兴趣的:(●,【,问题集,】)