Discussion:
Curl Aggressive Optimize for size
Emanuel Patern
2012-09-18 02:02:48 UTC
Permalink
Hi;

I have built libcurl with openssl all in static mode. In My C++ project, I added the required libcurl.a, libssl.a and libcrypto.a to my project and creates a symple curl session for testing.
My project requires also the following static libs that I have linked with :
* libgdi32.a
* libws2_32.a

After compile, the executable size jump from 8KB into 2.16 MB !!
This is a huge size, especially and what surprise me is that I have added optimization options to minimize for size :

-fno-rtti
-fno-exceptions
-ffunction-sections
-fdata-sections
-Os

But that doesn't seem that curl or openssl takes that optimization options in mind. I am not sure but did I miss to compile either curl or openssl with optimization options, if in case how to rebuild either curl or openssl with size optimization enabled ?

Regards
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Jie He
2012-09-18 06:58:51 UTC
Permalink
why would you use the dynamic link to these library?
Post by Emanuel Patern
Hi;
I have built libcurl with openssl all in static mode. In My C++ project, I
added the required libcurl.a, libssl.a and libcrypto.a to my project and
creates a symple curl session for testing.
* libgdi32.a
* libws2_32.a
After compile, the executable size jump from 8KB into 2.16 MB !!
This is a huge size, especially and what surprise me is that I have added
-fno-rtti
-fno-exceptions
-ffunction-sections
-fdata-sections
-Os
But that doesn't seem that curl or openssl takes that optimization options
in mind. I am not sure but did I miss to compile either curl or openssl
with optimization options, if in case how to rebuild either curl or openssl
with size optimization enabled ?
Regards
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
--
Best Regards
He Jie ºÎœÜ
Daniel Stenberg
2012-09-18 07:22:15 UTC
Permalink
Post by Emanuel Patern
I have built libcurl with openssl all in static mode. In My C++ project, I
added the required libcurl.a, libssl.a and libcrypto.a to my project and
creates a symple curl session for testing.
If you really want to shrink size you should probably consider switching to a
more minimalistic SSL library than OpenSSL. After that, you could opt to
disable a couple of protocols libcurl supports by default but that will be a
much smaller gain.
Post by Emanuel Patern
But that doesn't seem that curl or openssl takes that optimization options
in mind.
You can easily just verify which flags are used when the compile commands run.
A source code can't just ignore compiler optmization options at will.
Post by Emanuel Patern
I am not sure but did I miss to compile either curl or openssl with
optimization options, if in case how to rebuild either curl or openssl with
size optimization enabled ?
We have a section in docs/INSTALL discussing how Dan builds libcurl to a
~100KB lib on x86 that should be possbile to use as inspiration.
--
/ daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Emanuel Patern
2012-09-19 21:54:56 UTC
Permalink
Hello;

I tried to build curl with polarssl instead of openssl. Here what I did :

Libcurl version : 7.27.0
Polar ssl version : 1.1.4

To build polar ssl I did :

make CC=gcc APPS=
make DESTDIR=/c/pssl install

To build curl I did :
perl Configure CFLAGS="-Os -ffunction-sections -fdata-sections -flto" LDFLAGS="-Wl,-s -Wl,-Bsymbolic -Wl,--gc-sections -flto -Os" --without-libidn,zlib,ldap-lib --disable-ipv6,manual,shared,verbose,debug,gopher --enable-hidden-symbols --enable-static --prefix=/c/curl --with-polarssl=/c/polarssl

Now Everything looks okay, I have added licurl.a, libpolarssl.a into my project with link option -DCURL_STATICLIB. After Compile I get those errors during linking :

=================================================
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_step2+0x4b)||undefined reference to `ssl_handshake'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_step2+0xd6)||undefined reference to `ssl_get_ciphersuite'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_step2+0xf8)||undefined reference to `ssl_get_verify_result'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_step2+0x1e1)||undefined reference to `x509parse_cert_info'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_common+0xb4)||undefined reference to `havege_init'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_common+0x103)||undefined reference to `x509parse_crtfile'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_common+0x148)||undefined reference to `x509parse_crtfile'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_common+0x18e)||undefined reference to `x509parse_keyfile'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_common+0x1ed)||undefined reference to `x509parse_crlfile'|
...
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$Curl_polarssl_close+0x5f)||undefined reference to `ssl_free'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$Curl_polarssl_version+0x7)||undefined reference to `version_get_number'|
||=== Build finished: 31 errors, 0 warnings (0 minutes, 10 seconds)
=================================================

Did I miss something ?
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Dan Fandrich
2012-09-20 20:36:12 UTC
Permalink
Post by Emanuel Patern
Libcurl version : 7.27.0
Polar ssl version : 1.1.4
make CC=gcc APPS=
make DESTDIR=/c/pssl install
perl Configure CFLAGS="-Os -ffunction-sections -fdata-sections -flto" LDFLAGS="-Wl,-s -Wl,-Bsymbolic -Wl,--gc-sections -flto -Os" --without-libidn,zlib,ldap-lib --disable-ipv6,manual,shared,verbose,debug,gopher --enable-hidden-symbols --enable-static --prefix=/c/curl --with-polarssl=/c/polarssl
I don't know what "perl Configure" does but --without- and --disable-
arguments can't be separated by commas like this with autoconf. The
directory specified with the --with-polarssl= option is not the same as
that you show for the PolarSSL build above. If PolarSSL uses an
autoconf-like build system, then DESTDIR isn't going to produce the
right output directory structure; in autoconf-based builds, the --prefix
option does that. Rather than adding all those optimization options
right away, try getting a standard build working first. If one of those
optimizations isn't compatible with your build, it's just going to get
in the way.
To your project? I don't know what kind of build system you're using,
but clearly, it's not libcurl's, which increases the chance dramatically
that the problem is not in curl but rather your environment.
Post by Emanuel Patern
=================================================
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_step2+0x4b)||undefined reference to `ssl_handshake'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_step2+0xd6)||undefined reference to `ssl_get_ciphersuite'|
What does the link command-line look like? It looks like the PolarSSL
library isn't being linked. It may be the order of the library given on
the link command-line is wrong.
Post by Emanuel Patern
Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Paul Bakker
2012-09-26 20:43:42 UTC
Permalink
Hi Emanuel,

Did you use --without-ssl?
That is required as far as I know!

If I do:
./configure --without-ssl --with-polarssl
make

then:
src/curl -V

says:

curl 7.27.0 (i686-pc-linux-gnu) libcurl/7.27.0 PolarSSL/1.1.4 zlib/1.2.7
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s
rtsp smtp smtps telnet tftp
Features: IPv6 Largefile SSL libz

Best regards,
Paul Bakker
Post by Emanuel Patern
Hello;
Libcurl version : 7.27.0
Polar ssl version : 1.1.4
make CC=gcc APPS=
make DESTDIR=/c/pssl install
perl Configure CFLAGS="-Os -ffunction-sections -fdata-sections -flto" LDFLAGS="-Wl,-s -Wl,-Bsymbolic -Wl,--gc-sections -flto -Os" --without-libidn,zlib,ldap-lib --disable-ipv6,manual,shared,verbose,debug,gopher --enable-hidden-symbols --enable-static --prefix=/c/curl --with-polarssl=/c/polarssl
=================================================
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_step2+0x4b)||undefined reference to `ssl_handshake'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_step2+0xd6)||undefined reference to `ssl_get_ciphersuite'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_step2+0xf8)||undefined reference to `ssl_get_verify_result'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_step2+0x1e1)||undefined reference to `x509parse_cert_info'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_common+0xb4)||undefined reference to `havege_init'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_common+0x103)||undefined reference to `x509parse_crtfile'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_common+0x148)||undefined reference to `x509parse_crtfile'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_common+0x18e)||undefined reference to `x509parse_keyfile'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$polarssl_connect_common+0x1ed)||undefined reference to `x509parse_crlfile'|
...
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$Curl_polarssl_close+0x5f)||undefined reference to `ssl_free'|
...\libcurl.a(libcurl_la-polarssl.o):polarssl.c:(.text$Curl_polarssl_version+0x7)||undefined reference to `version_get_number'|
||=== Build finished: 31 errors, 0 warnings (0 minutes, 10 seconds)
=================================================
Did I miss something ?
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

Loading...