arm-eabi-strip and binary size

4,172 views
Skip to first unread message

Eugene Mymrin

unread,
Oct 20, 2010, 6:33:54 AM10/20/10
to andro...@googlegroups.com
Hello,

My shared library size is about 950K when built in release mode.
I want to have it as small as possible, so every time the library is
rebuilt I invoke

arm-eabi-strip -g -S -d --strip-debug --strip-unneeded libxxx.so

This makes the library as small as 850K.

I wonder:
1. Is it OK to manually invoke arm-eabi-strip with these parameters?
2. Which flags are passed to arm-eabi-strip when release lib is built
using ndk-build?
3. Can I change arm-eabi-strip behavior using variables in
Application.mk so that I don't have to invoke arm-eabi-strip manually
every time?

I know APP_OPTIM allows to explicitly request release/checked mode but
I could not find anything that lets redefine arm-eabi-strip behavior.

Thanks,
Eugene

David Turner

unread,
Oct 20, 2010, 10:03:34 PM10/20/10
to andro...@googlegroups.com
Hello Eugene,

Currently, the behaviour of stripping cannot be changed in the Android.mk.
You can however modify the NDK build scripts to do that for you, look at the definition of the cmd-strip command under build/toolchains/<name>/setup.mk, which currently looks like:

cmd-strip = $(TOOLCHAIN_PREFIX)strip --strip-debug $1

Regarding the flags, you are using, please note that "-g", "-S", "-d" and "--strip-debug" are all equivalent, as far as I know.

I always thought that --strip-unneeded was dangerous because it sometimes removes critical information, but according to http://www.technovelty.org/linux/strip.html, this can only occur when stripping static libraries. The NDK never tries to strip these, so I guess using the flag is useful.

In short, try replacing --strip-debug by --strip-unneeded in this definition. I'll consider this for a later NDK release.

Hope this helps



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Eugene Mymrin

unread,
Oct 21, 2010, 6:17:13 AM10/21/10
to andro...@googlegroups.com
Thank you, David.
Tried your suggestion, and indeed, in case of shared library
--strip-unneeded switch alone produces exactly the same result.
As well as --strip-all, exactly as it's claimed at
http://www.technovelty.org/linux/strip.html.
Also, in my project there are two more shared libraries loaded in a
company with the first one, and all of them remain usable after
"additional" stripping is applied.

Glenn Kasten

unread,
Oct 21, 2010, 10:31:22 AM10/21/10
to android-ndk
By default, global functions appear in the .so symbol table, even if
they are not desired entry points. To reduce .so size further I also
recommend that you add this to your Android.mk:
LOCAL_CFLAGS += -fvisibility=hidden -
DAPIENTRY='__attribute__((visibility("default")))'

Prefix only your exported function definitions with macro APIENTRY,
for example:
APIENTRY int sum(int i, int j)
{
return i+j;
}

You will likely see a decrease in size of your .so, especially if you
have a lot of global functions that are not entry points.
Run this command to see the resulting symbol table:
arm-eabi-readelf -s -W file.so
Symbols of type "FUNC GLOBAL DEFAULT" are your remaining entry points.

Glenn

On Oct 21, 3:17 am, Eugene Mymrin <emym...@gmail.com> wrote:
> Thank you, David.
> Tried your suggestion, and indeed, in case of shared library
> --strip-unneeded switch alone produces exactly the same result.
> As well as --strip-all, exactly as it's claimed athttp://www.technovelty.org/linux/strip.html.
> Also, in my project there are two more shared libraries loaded in a
> company with the first one, and all of them remain usable after
> "additional" stripping is applied.
>
> On Thu, Oct 21, 2010 at 6:03 AM, David Turner <di...@android.com> wrote:
> > Hello Eugene,
> > Currently, the behaviour of stripping cannot be changed in the Android.mk.
> > You can however modify the NDK build scripts to do that for you, look at the
> > definition of the cmd-strip command under build/toolchains/<name>/setup.mk,
> > which currently looks like:
>
> > cmd-strip = $(TOOLCHAIN_PREFIX)strip --strip-debug $1
>
> > Regarding the flags, you are using, please note that "-g", "-S", "-d" and
> > "--strip-debug" are all equivalent, as far as I know.
> > I always thought that --strip-unneeded was dangerous because it sometimes
> > removes critical information, but according
> > to http://www.technovelty.org/linux/strip.html, this can only occur when
> > stripping static libraries. The NDK never tries to strip these, so I guess
> > using the flag is useful.
> > In short, try replacing --strip-debug by --strip-unneeded in this
> > definition. I'll consider this for a later NDK release.
> > Hope this helps
>
Reply all
Reply to author
Forward
0 new messages