Android mylib.so 有文本重定位。这会浪费内存并且存在安全风险。请修复
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20141538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mylib.so has text relocations. This is wasting memory and is a security risk. Please fix
提问by Jerome
My Android application (using native library) print this warning on Android 4.4 :
我的 Android 应用程序(使用本机库)在 Android 4.4 上打印此警告:
linker mylib.so has text relocations. This is wasting memory and is a security risk. Please fix.
链接器 mylib.so 具有文本重定位。这会浪费内存并且存在安全风险。请修复。
Have you got an idea of what it is and how to fix it ? Thanks,
你知道它是什么以及如何修复它吗?谢谢,
采纳答案by Chris Stratton
This would appear to be a result of two ndk-gcc bugs mentioned at https://code.google.com/p/android/issues/detail?id=23203
这似乎是https://code.google.com/p/android/issues/detail?id=23203 中提到的两个 ndk-gcc 错误的结果
and stated there to have been fixed as of ndk-r8c.
并表示自 ndk-r8c 起已修复。
It would appear that the check for libraries with the issue has been added only recently.
似乎最近才添加了对有问题的库的检查。
Note: please do notedit this post to hide the link URL. It is explicit because the destination is what makes it authoritative.
注意:请不要编辑此帖子以隐藏链接 URL。它是明确的,因为目的地使它具有权威性。
Further NoteChanging NDK versions is only a fix when the warning is due to the code of your application. It will have no effectif the warning is instead on a system component such as libdvm - that can only be fixed by a system update.
进一步说明更改 NDK 版本只是在警告是由您的应用程序代码引起时的一种修复。如果警告出现在诸如 libdvm 之类的系统组件上,则不会产生任何影响- 只能通过系统更新来修复。
回答by Hypothetical inthe Clavicle
You need to make the code in your library position independent...add -fpic
or -fPIC
to your LOCALC_FLAGS
in your Android.mk and you also need to ensure that you're not linking against any static or shared libraries that contain text relocations themselves. If they do and you can re-compile them, use one of the flags mentioned above.
您需要使库位置中的代码独立...添加-fpic
或添加-fPIC
到您LOCALC_FLAGS
的 Android.mk 中,并且您还需要确保您没有链接到任何包含文本重定位本身的静态或共享库。如果他们这样做并且您可以重新编译它们,请使用上面提到的标志之一。
回答by not2qubit
In short, you need to compile your library with one of the -fpic
or -fPIC
flags, where PICis an abbreviation for Position Independent Code.
简而言之,您需要使用-fpic
或-fPIC
标志之一编译您的库,其中PIC是Position Independent Code的缩写。
The longer answer is that your yourlib.sohas been compiled in a manner that does not conform to the Google Android standard for an ELF file, where this Dynamic Array Tag
entry is unexpected. In the best case the library will still run, but it is still an error and future AOS version will probably not allow it to run.
更长的答案是您的yourlib.so已以不符合 ELF 文件的 Google Android 标准的方式编译,其中此条Dynamic Array Tag
目是意外的。在最好的情况下,库仍然会运行,但它仍然是一个错误,未来的 AOS 版本可能不允许它运行。
DT_TEXTREL 0x16 (22)
DT_TEXTREL 0x16 (22)
To check whats in you library use something along the line of:
要检查库中的内容,请使用以下内容:
# readelf --wide -S yourlib.so
There are 37 section headers, starting at offset 0x40:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS 0000000000000000 002400 068f80 00 AX 0 0 16
[ 2] .rodata PROGBITS 0000000000000000 06b380 05ad00 00 WA 0 0 32
...
[16] .rela.text RELA 0000000000000000 26b8e8 023040 18 14 1 8
...
[36] .rela.debug_frame RELA 0000000000000000 25a608 0112e0 18 14 27 8
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
Please see my extensive answeron the topic, for more DT entry
details. For details how to write proper dynamic libraries this is a must-read.
回答by Ravit D
I got the same error with my application. The application was using a native daemon that used a native library which was not implementing all the functions in its header file. When I added the required implementations to the native library everything just worked.
我的应用程序遇到了同样的错误。该应用程序使用的本机守护程序使用本机库,该库未实现其头文件中的所有功能。当我将所需的实现添加到本机库时,一切正常。
I don't know if you have the exact same issue but it just probably means the your native side has some mismatch.
我不知道您是否有完全相同的问题,但这可能意味着您的本地端有一些不匹配。