Current Minimal Binary Size
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 23 lines
Out of curiosity, how are you generating these results? For instance using the Ubuntu ARM GCC cross compiler I have a smallest executable of less than half the size of what you list above:
$ arm-linux-gnueabi-gcc --version arm-linux-gnueabi-gcc (Ubuntu/Linaro 8.3.0-6ubuntu1) 8.3.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.$ cat empty.c int main(void) { return 0; } $ make empty CC=arm-linux-gnueabi-gcc CFLAGS=-Os && arm-linux-gnueabi-strip empty && ls -l empty arm-linux-gnueabi-gcc -Os -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed empty.c -o empty -rwxr-xr-x 1 andrew andrew 5544 Sep 16 13:08 empty $ size empty text data bss dec hex filename 759 276 4 1039 40f empty
Quoted 5 lines
Admittedly it's not the SDK cross-compiler, but some more clarity on how you came to those numbers would be helpful.
Andrew
Andrew,
So glad you replied.
I’m doing a Bitbake build for a recipe that uses CMAKE:
add_executable( sizetest.bin source/sizebin.cpp) target_compile_options( sizetest.bin PUBLIC -Os -s)
I don’t know if it matters, but I’m compiling in CentOS 7 with the OpenBMC/OpenBMC tree and my TemplateConf set to meta-facebook/meta-tiogapass.
arm-openbmc-linux-gnueabi-gcc (GCC) 9.2.0
I need to run an errand this morning, but will replicate your precise sequence a bit later today.
I’m always open to the possibility that I’m doing something wrong or missing something, but last time I checked, -Os generates the smallest possible code and -s strips symbols.
Wilfred
Hi Wilfred,
Quoted 42 lines · Wilfred Smith
Quoted 23 lines
Out of curiosity, how are you generating these results? For instance using the Ubuntu ARM GCC cross compiler I have a smallest executable of less than half the size of what you list above:
$ arm-linux-gnueabi-gcc --version arm-linux-gnueabi-gcc (Ubuntu/Linaro 8.3.0-6ubuntu1) 8.3.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.$ cat empty.c int main(void) { return 0; } $ make empty CC=arm-linux-gnueabi-gcc CFLAGS=-Os && arm-linux-gnueabi-strip empty && ls -l empty arm-linux-gnueabi-gcc -Os -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed empty.c -o empty -rwxr-xr-x 1 andrew andrew 5544 Sep 16 13:08 empty $ size empty text data bss dec hex filename 759 276 4 1039 40f emptyQuoted 5 lines
Admittedly it's not the SDK cross-compiler, but some more clarity on how you came to those numbers would be helpful.
Andrew
Andrew,
So glad you replied.
I’m doing a Bitbake build for a recipe that uses CMAKE:
add_executable( sizetest.bin source/sizebin.cpp)target_compile_options( sizetest.bin PUBLIC -Os -s)I don’t know if it matters, but I’m compiling in CentOS 7 with the OpenBMC/OpenBMC tree and my TemplateConf set to meta-facebook/meta-tiogapass.
Quoted 8 lines
arm-openbmc-linux-gnueabi-gcc (GCC) 9.2.0
I need to run an errand this morning, but will replicate your precise sequence a bit later today.
I’m always open to the possibility that I’m doing something wrong or missing something, but last time I checked, -Os generates the smallest possible code and -s strips symbols.
Okay. Maybe :) Here are some results. The summary is that there's no real benefit to -Ox for x > 0 for your test cases beyond a slight saving for the iostream case, because there's effectively no code to optimise. Not stripped vs stripped contributes the biggest change as expected, and it looks like your results are may not have been stripped.
$ ls -l *.O?* -rwxr-xr-x 1 andrew andrew 12068 Sep 17 10:10 iostream.O0 -rwxr-xr-x 1 andrew andrew 5588 Sep 17 10:10 iostream.O0.stripped -rwxr-xr-x 1 andrew andrew 11848 Sep 17 10:10 iostream.O1 -rwxr-xr-x 1 andrew andrew 5540 Sep 17 10:10 iostream.O1.stripped -rwxr-xr-x 1 andrew andrew 11848 Sep 17 10:10 iostream.O2 -rwxr-xr-x 1 andrew andrew 5540 Sep 17 10:10 iostream.O2.stripped -rwxr-xr-x 1 andrew andrew 11848 Sep 17 10:10 iostream.O3 -rwxr-xr-x 1 andrew andrew 5540 Sep 17 10:10 iostream.O3.stripped -rwxr-xr-x 1 andrew andrew 11848 Sep 17 10:10 iostream.Os -rwxr-xr-x 1 andrew andrew 5540 Sep 17 10:10 iostream.Os.stripped -rwxr-xr-x 1 andrew andrew 11308 Sep 17 10:10 printf.O0 -rwxr-xr-x 1 andrew andrew 5528 Sep 17 10:10 printf.O0.stripped -rwxr-xr-x 1 andrew andrew 11308 Sep 17 10:10 printf.O1 -rwxr-xr-x 1 andrew andrew 5528 Sep 17 10:10 printf.O1.stripped -rwxr-xr-x 1 andrew andrew 11308 Sep 17 10:10 printf.O2 -rwxr-xr-x 1 andrew andrew 5528 Sep 17 10:10 printf.O2.stripped -rwxr-xr-x 1 andrew andrew 11308 Sep 17 10:10 printf.O3 -rwxr-xr-x 1 andrew andrew 5528 Sep 17 10:10 printf.O3.stripped -rwxr-xr-x 1 andrew andrew 11308 Sep 17 10:10 printf.Os -rwxr-xr-x 1 andrew andrew 5528 Sep 17 10:10 printf.Os.stripped -rwxr-xr-x 1 andrew andrew 11240 Sep 17 10:10 return.O0 -rwxr-xr-x 1 andrew andrew 5524 Sep 17 10:10 return.O0.stripped -rwxr-xr-x 1 andrew andrew 11240 Sep 17 10:10 return.O1 -rwxr-xr-x 1 andrew andrew 5524 Sep 17 10:10 return.O1.stripped -rwxr-xr-x 1 andrew andrew 11240 Sep 17 10:10 return.O2 -rwxr-xr-x 1 andrew andrew 5524 Sep 17 10:10 return.O2.stripped -rwxr-xr-x 1 andrew andrew 11240 Sep 17 10:10 return.O3 -rwxr-xr-x 1 andrew andrew 5524 Sep 17 10:10 return.O3.stripped -rwxr-xr-x 1 andrew andrew 11240 Sep 17 10:10 return.Os -rwxr-xr-x 1 andrew andrew 5524 Sep 17 10:10 return.Os.stripped
These results were generated from a patch like:
From 9661cfd8a299d35c7a834720a537ade62e0637d2 Mon Sep 17 00:00:00 2001
From: Andrew Jeffery <[email protected]>
Date: Tue, 17 Sep 2019 10:02:45 +0930
Subject: [PATCH] binsize
--- binsize.bb | 28 ++++++++++++++++++++++++++++ binsize/iostream.cpp | 8 ++++++++ binsize/printf.c | 8 ++++++++ binsize/return.c | 4 ++++ 4 files changed, 48 insertions(+) create mode 100644 binsize.bb create mode 100644 binsize/iostream.cpp create mode 100644 binsize/printf.c create mode 100644 binsize/return.c
binsize.bb new file +28 -0
@@ -0,0 +1,28 @@ +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://${IBMBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658" + +FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" +SRC_URI = "" +SRC_URI += "file://return.c" +SRC_URI += "file://printf.c" +SRC_URI += "file://iostream.cpp" + +buildit () { + OUT="${WORKDIR}/$1" + OPT="$2" + make CFLAGS=-O${OPT} CXXFLAGS=-O${OPT} ${OUT} + cp ${OUT} ${OUT}.O${OPT}.stripped + mv ${OUT} ${OUT}.O${OPT} + arm-openbmc-linux-gnueabi-strip ${OUT}.O${OPT}.stripped +} + +do_compile () { + + for app in 'return' 'printf' 'iostream' + do + for O in 0 1 2 3 s + do + buildit "$app" $O + done + done +}
binsize/iostream.cpp new file +8 -0
@@ -0,0 +1,8 @@ +#include <iostream> + +int main(int argc, const char *argv[]) +{ + std::cout << argv[0] << "\n"; + + return 0; +}
binsize/printf.c new file +8 -0
@@ -0,0 +1,8 @@ +#include <stdio.h>> + +int main (int argc,const char *argv[]) +{ +printf ("%s" , argv[0 ]); + +return 0 ; +}
binsize/return.c new file +4 -0
@@ -0,0 +1,4 @@ +int main (void ) +{ +return 0 ; +}
Signature · 1 line
2.20.1