Link update_engine with --gc-sections to remove unused code.
This patch adds -Wl,--gc-sections to LDFLAGS to instruct the linker
to remove all the unused functions. It also adds -ffuntion-sections
to CFLAGS in order to have each function on its own section and thus
allowing the linker to remove them. Finally, libxml2 include
directory is derived from pkg-config and other minor formating is
adjusted.
This reduces the update_engine size from 1.1MB to 800KB and the
update_engine_client from 755KB to only 119KB. This is because we
include all the delta generation code on the link step, altough we
only need parts of it, also the update_engine_client doesn't use
much of the update_engine code.
The flags are added before the environment provided flags, so this
can be disabled passing:
LDFLAGS=-Wl,--no-gc-sections emerge-${BOARD} update_engine
BUG=chromium:359343
TEST=emerge-link update_engine (with and without the LDFLAGS passed)
TEST=gmerged on link, restarted, run update from it to my desktop.
Change-Id: Ic185a3c46bdc4b1c5f97e16f3ae520a44a9307da
Reviewed-on: https://chromium-review.googlesource.com/196379
Reviewed-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/SConstruct b/SConstruct
index 86ff836..5688690 100644
--- a/SConstruct
+++ b/SConstruct
@@ -132,21 +132,25 @@
env['ENV'][key] = os.environ[key]
-env['LINKFLAGS'] = env.get('LDFLAGS', '')
-env['CCFLAGS'] = ' '.join("""-g
- -fno-exceptions
- -fno-strict-aliasing
- -std=gnu++11
- -Wall
- -Wextra
- -Werror
- -Wno-unused-parameter
- -Wno-deprecated-register
- -D__STDC_FORMAT_MACROS=1
- -D_FILE_OFFSET_BITS=64
- -D_POSIX_C_SOURCE=199309L
- -I/usr/include/libxml2""".split());
-env['CCFLAGS'] += (' ' + ' '.join(env['CFLAGS']))
+env['LINKFLAGS'] = Split("""
+ -Wl,--gc-sections""")
+env['LINKFLAGS'] += env.get('LDFLAGS', [])
+
+env['CCFLAGS'] = Split("""
+ -g
+ -ffunction-sections
+ -fno-exceptions
+ -fno-strict-aliasing
+ -std=gnu++11
+ -Wall
+ -Wextra
+ -Werror
+ -Wno-unused-parameter
+ -Wno-deprecated-register
+ -D__STDC_FORMAT_MACROS=1
+ -D_FILE_OFFSET_BITS=64
+ -D_POSIX_C_SOURCE=199309L""")
+env['CCFLAGS'] += env['CFLAGS']
BASE_VER = os.environ.get('BASE_VER', '242728')
env['LIBS'] = Split("""bz2
@@ -181,7 +185,7 @@
env.ParseConfig(pkgconfig + ' --cflags --libs '
'dbus-1 dbus-glib-1 gio-2.0 gio-unix-2.0 glib-2.0 libchrome-%s '
- 'libchromeos-%s' % (BASE_VER, BASE_VER))
+ 'libchromeos-%s libxml-2.0' % (BASE_VER, BASE_VER))
env.ProtocolBuffer('update_metadata.pb.cc', 'update_metadata.proto')
env.PublicKey('unittest_key.pub.pem', 'unittest_key.pem')
env.PublicKey('unittest_key2.pub.pem', 'unittest_key2.pem')