From 41fce8a8debf54f75251c7b190d7fa2e17a349b2 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 4 Oct 2021 13:19:19 +1100 Subject: [PATCH] Strip examples of unused data and functions Compile time: $ time ./build-example.sh Before: user 0m40.885s After: user 0m41.011s Binary size (for example-toy-genlib): $ ls -l gen/bin/example-toy-genlib) | awk '{print $5}' Before: 830168 After: 809896 Note that the majority of this is a statically linked libc. Binary size (excluding the statically linked example-toy-genlib): $ ls -l gen/bin/example-* | awk '{print $5 " " $9}' Before: 85280 gen/bin/example-cbor-to-json 242216 gen/bin/example-convert-to-nia 37112 gen/bin/example-crc32 53328 gen/bin/example-gifplayer 282840 gen/bin/example-imageviewer 95152 gen/bin/example-json-to-cbor 122720 gen/bin/example-jsonfindptrs 60448 gen/bin/example-jsonptr 267672 gen/bin/example-sdl-imageviewer 64792 gen/bin/example-zcat After: 73104 gen/bin/example-cbor-to-json 231560 gen/bin/example-convert-to-nia 34640 gen/bin/example-crc32 47632 gen/bin/example-gifplayer 269632 gen/bin/example-imageviewer 83032 gen/bin/example-json-to-cbor 118664 gen/bin/example-jsonfindptrs 58040 gen/bin/example-jsonptr 253424 gen/bin/example-sdl-imageviewer 58200 gen/bin/example-zcat Before total: 1311560 After total: 1227928 --- build-example.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-example.sh b/build-example.sh index f0f7fd28..da17f529 100755 --- a/build-example.sh +++ b/build-example.sh @@ -23,9 +23,9 @@ if [ ! -e release/c/wuffs-unsupported-snapshot.c ]; then fi CC=${CC:-gcc} -CFLAGS=${CFLAGS:--O3} +CFLAGS=${CFLAGS:--O3 -fdata-sections -ffunction-sections -Wl,--gc-sections} CXX=${CXX:-g++} -CXXFLAGS=${CXXFLAGS:--O3} +CXXFLAGS=${CXXFLAGS:--O3 -fdata-sections -ffunction-sections -Wl,--gc-sections} LDFLAGS=${LDFLAGS:-} mkdir -p gen/bin