mylib.so has text relocations. This is wasting memory and is a security risk. Please fix mylib.so has text relocations. This is wasting memory and is a security risk. Please fix android android

mylib.so has text relocations. This is wasting memory and is a security risk. Please fix


This would appear to be a result of two ndk-gcc bugs mentioned at https://code.google.com/p/android/issues/detail?id=23203

and stated there to have been fixed as of ndk-r8c.

It would appear that the check for libraries with the issue has been added only recently.

Note: please do not edit this post to hide the link URL. It is explicit because the destination is what makes it authoritative.

Further Note Changing NDK versions is only a fix when the warning is due to the code of your application. It will have no effect if the warning is instead on a system component such as libdvm - that can only be fixed by a system update.


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.


In short, you need to compile your library with one of the -fpic or -fPIC flags, where PIC is an abbreviation for Position Independent Code.

The longer answer is that your yourlib.so has 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.

DT_TEXTREL 0x16 (22)

To check whats in you library use something along the line of:

# readelf --wide -S yourlib.soThere 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  8Key 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 answer on the topic, for more DT entry details. For details how to write proper dynamic libraries this is a must-read.