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

一、问题描述

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 LevelAndroid版本
289
278.1
268.0
257.1.1
247.0
236.0
225.1.1
215.0.1
204.4w.2
194.4.2
184.3.1
174.2.2
164.1.2
154.0.3
144.0
102.3
82.2

—— 2018-12-04 ——

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值