Simply GUI programs such as my calculator are 9.2MB! Non GUI programs are ~700KB.
I compile with:
Code: Select all
x86_64-elf-gcc -fverbose-asm -m64 -ffreestanding -nostdlib -nostdinc++ -mno-red-zone -c -std=c++20 -MD -MF <dep file> -DPERCEPTION -Doptimized_BUILD_ -fdata-sections -ffunction-sections -g -O3 -fomit-frame-pointer -isystem ../third_party/Libraries/libcxx/public -isystem <libraries> -D_GNU_SOURCE -D_LIBCPP_HAS_THREAD_API_C11 -DLIBCXXRT -D_LIBCPP_HAS_THREAD_API_PTHREAD -o <output> <source>
Code: Select all
x86_64-elf-gcc-ar rvs -o <output> <object files>
Code: Select all
x86_64-elf-gcc -Wl,--gc-sections -O3 -g -s -nostdlib -nodefaultlibs -nolibc -nostartfiles -z max-page-size=1 -T userland.ld -o <output> -Wl,--start-group <object files and library archives> -Wl,--end-group -Wl,-lgcc
Does anyone have suggestions on how I can optimize my binary sizes further?
I think it's because I link with libcxx and musl, and GUI programs link with Skia which adds a dependency on libxml2, harfbuzz, freetype, libjpeg. I would have thought whole program optimization would be able to eliminate most of the dead code.