-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smaller ReleaseSmall by default #22270
Comments
I'm not sure yet if I'm on board with this. Remember, unwind tables as emitted by I'm not outright saying no to this, I'm just saying that this point needs to be carefully considered. It's not for nothing that C compilers default to emitting unwind tables even with
Not anymore: #22180 If you'd like to add some targeted exceptions to omitting the FP for |
This is a good point. I guess it might also make sense to document flag defaults based on the optimize mode somewhere to make users more aware of it.
Oh, I was looking at an old fork.
Yes I was thinking about taking a few applications for metrics and if the changes make binary size decrease for most of those, go with that as a slightly better default. |
@alexrp just in case you happen to be knowledgeable on this: Lines 556 to 568 in 0ff0bdb
if (builtin.sanitize_thread) ? I doubt that's it though.
|
It's known at link time whether that logic is needed. When a compilation is pure Zig code, then that logic is never needed. Additionally, there could be a flag added to disallow constructors in object files, causing a link error to occur if these sections are discovered in linker inputs. So, I could see there being a corresponding |
#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_tables
tofalse
by 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.
.comment
section) 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.Additionally, here are some things that should help users achieve smaller binary size on their own:
--strip-section-headers
from GNU objcopy in Zig objcopy. This option seems to remove section name strings as well as the.comment
section from a binary.--remove-section
from 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.comment
and keep section names, etc.The text was updated successfully, but these errors were encountered: