#6676 in the past helped make ReleaseSmall smaller by default.
However there is more that can be done when ReleaseSmall is enabled.
When you use ReleaseSmall you're asking for a small binary size, not debuggability.
Here are some things that could help achieve smaller binary size:
Additionally, here are some things that should help users achieve smaller binary size on their own:
#6676 in the past helped make ReleaseSmall smaller by default.
However there is more that can be done when ReleaseSmall is enabled.
When you use ReleaseSmall you're asking for a small binary size, not debuggability.
Here are some things that could help achieve smaller binary size:
unwind_tablesto.noneby default. This should consistently result in smaller binary size. Unwind tables seem to be used for stack traces (debuggability) which I'm not asking for when I'm compiling with ReleaseSmall. Would be nice to fix Unable to omit unwind tables from binary when using ReleaseSmall + LLVM #21942 before doing this.This is purely a case-by-case thing and doesn't always apply so I think it's fine to omit frame pointers for most architectures except for some exceptions like x86_64 where in many (again, not all) cases keeping the frame pointer results in smaller binary size. The user can always fine-tune this if they feel the need to so I think a rough "estimate" here would be an improvement over the default in many cases.
The current default seems to be to always omit the frame pointer if the optimize mode is not Debug.
.commentsection) for binaries in the self-hosted ELF linker. As far as I understand in most cases section headers are not required for execution of the program itself and are usually useful for debugging and to figure out what a section's name is etc.objcopy(see below also) to remove the undesired sections after the binary is emitted.builtin.stack_sizeto know the stack size at compile time so that there's no need to read the ELF itself. Either that or using@stackSize(_start)or something...? This could also be implemented before Builtin function to tell you the maximum stack size of a given function #157 by simply changing the default stack size from 16 MiB to 8 MiB and exposing the stack size usingbuiltin.stack_size. I don't think programs need 16 MiB by default.std.os.linux.elf_aux_maybein lib/std/start.zig configurable using a@import("builtin")flag. (See also: linux: omit getauxval from binary if not needed #22276 (comment))Additionally, here are some things that should help users achieve smaller binary size on their own:
--strip-section-headersfrom GNU objcopy in Zig objcopy. This option seems to remove section name strings as well as the.commentsection from a binary.--remove-sectionfrom GNU objcopy in Zig objcopy. It should be possible to remove only specific sections from a binary and keep all others. This should be useful in specific cases where undesirable sections are being emitted. Can also be used to omit only.commentand keep section names, etc.