Strange symbols in shared library

693 views
Skip to first unread message

Lascha Lagidse

unread,
Dec 29, 2013, 9:07:56 AM12/29/13
to andro...@googlegroups.com
Hi all,

I've build a shared library using ANT, and found that its size was really large (3.6MB). I am trying to reduce that size, so I used readelf.exe from the ndk toolchain and found a few problems:

1. I encountered symbols like $d and $a, which have no size but are still exported. There are about 15000 symbols like that!! It seems really redundant, what are they?

Symbol table '.symtab' contains 23111 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
    ...
    13: 000a7830     0 NOTYPE  LOCAL  DEFAULT    8 $d
    14: 000a7838     0 NOTYPE  LOCAL  DEFAULT    8 $a
    15: 000a7844     0 NOTYPE  LOCAL  DEFAULT    8 $d
    16: 000a7848     0 NOTYPE  LOCAL  DEFAULT    8 $a
    17: 000a786c     0 NOTYPE  LOCAL  DEFAULT    8 $d
    18: 000a7874     0 NOTYPE  LOCAL  DEFAULT    8 $a
    19: 000a7890     0 NOTYPE  LOCAL  DEFAULT    8 $d
    20: 000a7898     0 NOTYPE  LOCAL  DEFAULT    8 $a

    ...

2. I make use of templated objects, and they also seem to generate a very large amount of symbols, some of which seem like duplicates, like so:

  562: 000ac0c0    52 FUNC    WEAK   DEFAULT    8 _ZN9TSmartPtrI11TCallable1PIvRK22TMouseButtonPressEventEED2Ev
  563: 000ac0c0    52 FUNC    WEAK   DEFAULT    8 _ZN9TSmartPtrI11TCallable1PIvRK22TMouseButtonPressEventEED1Ev
  564: 000ac0f4    60 FUNC    WEAK   DEFAULT    8 _ZN9TSmartPtrI11TCallable1PIvRK22TMouseButtonPressEventEED0Ev
  ...
  16256: 00172c60     8 OBJECT  WEAK   DEFAULT   15 _ZTI9TSmartPtrI22TMouseButtonPressEventE
  16257: 001650e8    37 OBJECT  WEAK   DEFAULT   11 _ZTS9TSmartPtrI22TMouseButtonPressEventE

Note that the symbols are almost identical... What does this mean? It seems very redundant to me.

Not sure if this will help, but wouldn't hurt to add:
Compiler command line:

-Wno-psabi -funswitch-loops -D"ANDROID_NDK" -D"ANDROID" -D"__ANDROID__" -D"__ARM_EABI__" -D"__ARM_ARCH_5__" -D"__ARM_ARCH_5T__" -D"__ARM_ARCH_5E__" -D"__ARM_ARCH_5TE__" -fexceptions -fomit-frame-pointer -fno-strict-aliasing -I"D:\Development\Source\Engine\\Core" -I"../Middleware/glew/include" -I"../Middleware/zlib/" -I"../Middleware/libpng" -I"../Middleware/box2d/" -I"../Middleware/lua/src/" -I"../Middleware/luabridge/Source/LuaBridge/" -finline-limit=100 -fstack-protector -fno-short-enums -D"NDEBUG" -D"_MBCS" -D"GLEW_NO_GLU" -O3 -frtti -I"C:\android-ndk-r8e\platforms\android-8\arch-arm\usr\include" -I"C:\android-ndk-r8e\sources\cxx-stl\gnu-libstdc++\4.7\include" -I"C:\android-ndk-r8e\sources\cxx-stl\gnu-libstdc++\4.7\libs\armeabi\include" -marm -o "Android\Release\%(FileName).o"
Linker command line:
-o "D:\Development\Source\Android\Release\libEngine.so" -Wl,--no-undefined "-lGLESv2" "-lpng" "-llua" "-lbox2d" "-lstdc++" "-lsupc++" "C:\android-ndk-r8e\sources\cxx-stl\gnu-libstdc++\4.7\libs\armeabi\libgnustl_shared.so" "-lgcc" --sysroot="C:\android-ndk-r8e\platforms\android-8\arch-arm\usr\lib\..\.." -L"C:\android-ndk-r8e\platforms\android-8\arch-arm\usr\lib" -L"C:\android-ndk-r8e\sources\cxx-stl\gnu-libstdc++\4.7\libs\armeabi" -l"c" -l"m" -l"log" -l"gcc" -l"z" -shared -Wl,-z,noexecstack -Wl,-rpath-link="C:\android-ndk-r8e\platforms\android-8\arch-arm\usr\lib" -L"D:\Development\Source\/Android/Release/"

David Turner

unread,
Dec 30, 2013, 7:04:47 AM12/30/13
to andro...@googlegroups.com
On Sun, Dec 29, 2013 at 3:07 PM, Lascha Lagidse <lolly...@gmail.com> wrote:
Hi all,

I've build a shared library using ANT, and found that its size was really large (3.6MB). I am trying to reduce that size, so I used readelf.exe from the ndk toolchain and found a few problems:

1. I encountered symbols like $d and $a, which have no size but are still exported. There are about 15000 symbols like that!! It seems really redundant, what are they?

Symbol table '.symtab' contains 23111 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
    ...
    13: 000a7830     0 NOTYPE  LOCAL  DEFAULT    8 $d
    14: 000a7838     0 NOTYPE  LOCAL  DEFAULT    8 $a
    15: 000a7844     0 NOTYPE  LOCAL  DEFAULT    8 $d
    16: 000a7848     0 NOTYPE  LOCAL  DEFAULT    8 $a
    17: 000a786c     0 NOTYPE  LOCAL  DEFAULT    8 $d
    18: 000a7874     0 NOTYPE  LOCAL  DEFAULT    8 $a
    19: 000a7890     0 NOTYPE  LOCAL  DEFAULT    8 $d
    20: 000a7898     0 NOTYPE  LOCAL  DEFAULT    8 $a

    ...

These are ARM-specific symbols uses to indicate transitions between 32-bit ARM and 16-bit Thumb sections of code.

 
2. I make use of templated objects, and they also seem to generate a very large amount of symbols, some of which seem like duplicates, like so:

  562: 000ac0c0    52 FUNC    WEAK   DEFAULT    8 _ZN9TSmartPtrI11TCallable1PIvRK22TMouseButtonPressEventEED2Ev
  563: 000ac0c0    52 FUNC    WEAK   DEFAULT    8 _ZN9TSmartPtrI11TCallable1PIvRK22TMouseButtonPressEventEED1Ev
  564: 000ac0f4    60 FUNC    WEAK   DEFAULT    8 _ZN9TSmartPtrI11TCallable1PIvRK22TMouseButtonPressEventEED0Ev
  ...
  16256: 00172c60     8 OBJECT  WEAK   DEFAULT   15 _ZTI9TSmartPtrI22TMouseButtonPressEventE
  16257: 001650e8    37 OBJECT  WEAK   DEFAULT   11 _ZTS9TSmartPtrI22TMouseButtonPressEventE

Note that the symbols are almost identical... What does this mean? It seems very redundant to me.


Welcome to the wonderful world of C++ :-)

D2Ev, D1Ev, D0Ev are suffixes uses to denote several types of destructors, as required by the C++ specification.
These are auto-generated by the compiler if you don't specify them. Most of them should be purged from your final binaries if you use the right compiler and linker flags. 

Not sure if this will help, but wouldn't hurt to add:
Compiler command line:

-Wno-psabi -funswitch-loops -D"ANDROID_NDK" -D"ANDROID" -D"__ANDROID__" -D"__ARM_EABI__" -D"__ARM_ARCH_5__" -D"__ARM_ARCH_5T__" -D"__ARM_ARCH_5E__" -D"__ARM_ARCH_5TE__" -fexceptions -fomit-frame-pointer -fno-strict-aliasing -I"D:\Development\Source\Engine\\Core" -I"../Middleware/glew/include" -I"../Middleware/zlib/" -I"../Middleware/libpng" -I"../Middleware/box2d/" -I"../Middleware/lua/src/" -I"../Middleware/luabridge/Source/LuaBridge/" -finline-limit=100 -fstack-protector -fno-short-enums -D"NDEBUG" -D"_MBCS" -D"GLEW_NO_GLU" -O3 -frtti -I"C:\android-ndk-r8e\platforms\android-8\arch-arm\usr\include" -I"C:\android-ndk-r8e\sources\cxx-stl\gnu-libstdc++\4.7\include" -I"C:\android-ndk-r8e\sources\cxx-stl\gnu-libstdc++\4.7\libs\armeabi\include" -marm -o "Android\Release\%(FileName).o"
Linker command line:
-o "D:\Development\Source\Android\Release\libEngine.so" -Wl,--no-undefined "-lGLESv2" "-lpng" "-llua" "-lbox2d" "-lstdc++" "-lsupc++" "C:\android-ndk-r8e\sources\cxx-stl\gnu-libstdc++\4.7\libs\armeabi\libgnustl_shared.so" "-lgcc" --sysroot="C:\android-ndk-r8e\platforms\android-8\arch-arm\usr\lib\..\.." -L"C:\android-ndk-r8e\platforms\android-8\arch-arm\usr\lib" -L"C:\android-ndk-r8e\sources\cxx-stl\gnu-libstdc++\4.7\libs\armeabi" -l"c" -l"m" -l"log" -l"gcc" -l"z" -shared -Wl,-z,noexecstack -Wl,-rpath-link="C:\android-ndk-r8e\platforms\android-8\arch-arm\usr\lib" -L"D:\Development\Source\/Android/Release/"

Try adding "-ffunction-section -fdata-section" to your compiler flags, and "-Wl,--gc-sections" to your linker flags to get rid of a lot of C++ template cruft at link time. This may slow down your build though.

Hope this helps.


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages