OpenWrt Forum Archive

Topic: Reduce bin file size - one order of magnitude

The content of this topic has been archived on 19 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi all,
I successfully compiled knockd 0.7 source (http://www.zeroflux.org/projects/knock) with Attitude Adjustment toolchain. This included compilation of libpcap and knockd itself.
To compile I leveraged the original configure/make scripts in the tarball (ie. ./configure -host=mipsel-openwrt-linux-uclibc --build=i686-pc-linux-gnu).

output binary works, but it's definitely oversized. using stripping, I cant make it smaller than 280kB. Original knockd package (version 0.5) available on openwrt repository is way smaller, around 30kB. And if I compile the same source for x86, it's around 30kB as well.
Now the question is: what am I missing to reduce binary size in case of crosscompiling version 0.7? I tried to play with -O options in makefile, but still can't go lower than 280kB. I'm no compilation/x-compilation expert, is there anything I should optimize on libpcap as well? any other hints?

thanks

After further investigation, the problem seems to be libpcap libraries. In fact, if I compile knockd source using libpcap library included in Openwrt SDK instead of compiling it myself, the knockd binary size drops to 100kB, which turn into 40KB with stripping.

But there is a trade-off. I wanted to move away from knockd-0.5 version readily available with opkg in openwrt because it consumed 4MB+ of RAM at runtime, and I thought the last version, 0.7, would have been more efficient.
If compiled with openwrt SDK libpcap, 0.7 behaves exactly the same. When compiled with self-compiled libpcap, the biary is bigger, but the RAM footprint is way lower, although still big (2MB instead of 4MB+).

So in my scenario I'll do as follow: I'll keep the self-compiled 280KB binary and make it available on a webserver, fetch it from there and store it in RAM, launch it and then delete it.

just in case anyone hits the same issue smile
cheers

sturia wrote:

output binary works, but it's definitely oversized.
thanks

Is it possible that you use static libpcap.a instead of dynamic libpcap.so?

wow it worked, thanks!! I don't know how to force usage of dynamic libraries but just removed libpcap.a and created a softlink libpcap.a->libpcap.so.
now the only issue remaining is that when I run that binary on the ar7 box it says "can't load library 'libpcap.so.1'".
In lib directory there is libpcap.so.1.1 and libpcap.so.1.1.1 instead.
any hints about how to tell the binary to look for libpcap.so.1.1 instead of libpcap.so.1?

thanks a lot

That is usually achived by symlinks, they're usually laid out like this:

libpcap.so   -> libpcap.so.1
libpcap.so.1 -> libpcap.so.1.1

The discussion might have continued from here.