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

前端 未结 4 1859
攒了一身酷
攒了一身酷 2020-11-29 02:39

My Android application (using native library) print this warning on Android 4.4 :

linker mylib.so has text relocations. This is wasting memory an

相关标签:
4条回答
  • 2020-11-29 02:48

    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.

    0 讨论(0)
  • 2020-11-29 02:51

    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.

    0 讨论(0)
  • 2020-11-29 03:04

    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.

    0 讨论(0)
  • 2020-11-29 03:06

    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.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 answer on the topic, for more DT entry details. For details how to write proper dynamic libraries this is a must-read.

    0 讨论(0)
提交回复
热议问题