W/linker: libxxx.so: unused DT entry: type 0x6ffffffe arg 0x5a4
条评论- 1. Q:What are “unused DT entry” errors?
- 2. Q: What is a “DT entry”?
- 3. Q: When does this happen?
- 4. Q: How do I find what DT entries my system or binaries are using?
- 5. Q: So how do you solve or deal with these issues?
- 6. Q. What else?
- 7. WARNING: linker: ./demo: unused DT entry: type 0x6ffffffe 解决!!
- 8. Reference
我正在使用libserialport.so,在运行时,我收到以下警告:
1 | W/linker: libserialport.so: unused DT entry: type 0x6ffffffe arg 0x5a4 |
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:
如果您已到达此页面,可能是因为您已编译或尝试在基于ARM的Android系统上运行某些二进制文件,结果导致您的二进制文件/应用程序崩溃或在您的系统中生成大量警告 logcat。通常是这样的:
1 | 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.
简而言之,它们是ELF文件的文件结构中的描述性数组条目 。具体而言,它们被称为 Dynamic Array Tags 可执行和共享对象的要求。但是,并非所有条目都是必需的或可用的,具体取决于处理器和内核体系结构。在我们的案例中,我们面临一个“警告”,其中一个是“未使用”。这意味着,您的可执行文件或库(*.so)文件已使用 指示的DT条目进行编译 ,但由于各种原因,您的内核不支持该条目。最好的例子可以在基于ARM的Android系统上找到,其中系统库路径是固定的,用于固件的交叉编译器(OS /内核)设置为不使用这些条目。通常二进制文件仍然可以正常运行,但内核每次使用它时都会标记此警告。
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).
- 您的ARM内核使用错误的标志进行交叉编译(通常用于其他处理器体系结构)。
- Your ARM binaries and libraries are cross-compiled using AOS deprecated compilation flags.
- 您的ARM二进制文件和库是使用AOS弃用的编译标志进行交叉编译的。
- 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.
从5.1(API 22)开始,Android链接器会警告VERNEED和VERNEEDNUM ELF动态部分。
The most common flags that cause this error on Android devices are:
在Android设备上导致此错误的最常见标志是:
1 | DT_RPATH 0x0f (15) The DT_STRTAB string table offset of a null-terminated library search path string. |
Tracking down the error above, we find that this message comes from the bionic
library linker.cpp:
追踪上面的错误,我们发现此消息来自 bionic
库linker.cpp:
1 | case DT_VERNEED: |
The code (above) supporting this symbol versioning was committed on April 9, 2015. Thus if your NDK build is either set to support API’s earlier than this, or using build tools linking to this earlier library, you will get these warnings.
支持此符号版本控制的代码(上文) 于2015年4月9日提交 。因此,如果您的NDK构建设置为支持早于此的API,或者使用链接到此早期库的构建工具,您将收到这些警告。
Q: How do I find what DT entries my system or binaries are using?
There are many ways to do this:
- You look into your kernel sources for
<linux/elf.h>
. - You look in your Android NDK installation folders and check:
1 | To find all elf.h files: |
- Do an readelf of your binary:
1 | readelf --dynamic libopenssl.so |
As you can see from the error above, the type corresponds to DT_VERNEED.
From THIS document:
DT_RPATH
This element holds the string table offset of a null-terminated search library search path string, discussed in “Shared Object Dependencies.” The offset is an index into the table recorded in the DT_STRTAB entry. DT_RPATH may give a string that holds a list of directories, separated by colons (:). All LD_LIBRARY_PATH directories are searched after those from DT_RPATH.
DT_RPATH此元素保存以“共享对象依赖关系”中讨论的以null结尾的搜索库搜索路径字符串的字符串表偏移量。偏移量是DT_STRTAB条目中记录的表的索引。DT_RPATH可以给出一个包含目录列表的字符串,以冒号(:)分隔。在DT_RPATH之后搜索所有LD_LIBRARY_PATH目录。
Q: So how do you solve or deal with these issues?
There are essentially 3 ways to deal with this:
- the quick
- the bad
- the ugly
The Quick (you don’t have any sources or just can’t be bothered)
Use an “ELF cleaner” to remove the offending DT entries from a all your binaries. This is an easy and quick remedy, especially when you don’t have the sources to recompile them properly for your system. There are at least two cleaners out there that you can use.
The Bad (you have the sources)
Is the right way to do it, because you’ll become a bad-ass ARM cross compiler guru in the process of getting it to work. You basically need to find and tune the compiler settings in the Makefiles used.
From here:
解决方法:https://github.com/kost/android-elf-cleaner
The Android linker (/system/bin/linker) does not support RPATH or RUNPATH, so we set LD_LIBRARY_PATH=$USR/lib and try to avoid building useless rpath entries with –disable-rpath configure flags. Another option to avoid depending on LD_LIBRARY_PATH would be supplying a custom linker - this is not done due to the overhead of maintaining a custom linker.
The Ugly (You just want your app to work with any dirty binary.)
You tell your Java app not to freak out when checking for null in error handlers and instead get fed these warnings, possibly causing fatal exceptions. Use something like:
1 | class OpensslErrorThread extends Thread { |
This is very bad and ugly as it doesn’t solve anything, while bloating your code. In addition, the warnings are there for a reason, and that is that in future AOS versions, this will become a full fledged error!
Q. What else?
Many changes in the API’s between 18-25 (J to N) has been made in way the Android kernel and libraries are compiled. I cannot provide a remotely close explanation of all that, but perhaps this will help guide you in the right direction. The best sources is of course looking in the Android sources and documentation itself.
And finally the full list:
1 | Name Value d_un Executable Shared Object |
WARNING: linker: ./demo: unused DT entry: type 0x6ffffffe 解决!!
- demo.c
1 |
|
- Android.mk
1 | LOCAL_PATH := $(call my-dir) |
- Application.mk
1 | APP_OPTIM := release |
- NDK编译:
1 | C:\Users\piao\Downloads\adbi\demo\jni |
经过测试~~
此警告只会在5.0以上系统出现:
1 | root@ido:/data/local/tmp # ./demo |
解决方法:https://github.com/kost/android-elf-cleaner
在Ubuntu16.04编译后:
1 | piao@piaopiao:~/Desktop/android-elf-cleaner$ make |
然后执行:
1 | piao@piaopiao:~/Desktop/android-elf-cleaner$ ./android-elf-cleaner demo |
再次push到手机里面运行:
1 | root@ido:/data/local/tmp # ./demo |
Reference
https://stackoverflow.com/questions/33206409/unused-dt-entry-type-0x1d-arg
NDK升级遇到的一些问题汇总
WARNING: linker: ./demo: unused DT entry: type 0x6ffffffe 解决!!
本文标题:W/linker: libxxx.so: unused DT entry: type 0x6ffffffe arg 0x5a4
文章作者:xmaihh
发布时间:2019-03-05
最后更新:2019-03-05
版权声明:采用[CC BY-NC-SA 4.0许可协议]进行许可
分享