| author | |
| committer | |
| log | 0ff0bdb4a71d8fd055272abfdadea2f23f99574a |
| tree | 264695e89691b93355dd795ce9fc060521966e23 |
| parent | e2e3633612be656177512873a9de6524082d04dd |
On x86 and x86_64 keeping the frame pointer usually reduces binary size, even for simple programs:
```
~$ cat x.zig
pub fn main() void {
@import("std").debug.print("hello", .{});
}
~$ zig build-exe x.zig -target x86_64-linux -OReleaseSmall -fno-omit-frame-pointer && wc -c x
5168 x
~$ zig build-exe x.zig -target x86_64-linux -OReleaseSmall -fomit-frame-pointer && wc -c x
5216 x
```
```
~$ cat x.zig
pub fn main() void {
@import("std").debug.print("hello", .{});
}
~$ zig build-exe x.zig -target x86-linux -OReleaseSmall -fno-omit-frame-pointer && wc -c x
3400 x
~$ zig build-exe x.zig -target x86-linux -OReleaseSmall -fomit-frame-pointer && wc -c x
3556 x
```
A bigger benchmark is the Zig compiler:
With no changes to anything on master branch:
```
$ zig build -Dno-lib -Dno-langref --zig-lib-dir lib -Doptimize=ReleaseSmall
$ wc -c zig-out/bin/zig
10698792 zig-out/bin/zig
```
Adding `.omit_frame_pointer = false` in `addCompilerStep` in `build.zig`:
```
$ zig build -Dno-lib -Dno-langref --zig-lib-dir lib -Doptimize=ReleaseSmall
$ wc -c zig-out/bin/zig
10155744 zig-out/bin/zig
```1 files changed, 6 insertions(+), 1 deletions(-)
src/Package/Module.zig+6-1| ... | ... | @@ -205,7 +205,12 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { |
| 205 | 205 | const omit_frame_pointer = b: { |
| 206 | 206 | if (options.inherited.omit_frame_pointer) |x| break :b x; |
| 207 | 207 | if (options.parent) |p| break :b p.omit_frame_pointer; |
| 208 | if (optimize_mode == .ReleaseSmall) break :b true; | |
| 208 | if (optimize_mode == .ReleaseSmall) { | |
| 209 | // On x86, in most cases, keeping the frame pointer usually results in smaller binary size. | |
| 210 | // This has to do with how instructions for memory access via the stack base pointer register (when keeping the frame pointer) | |
| 211 | // are smaller than instructions for memory access via the stack pointer register (when omitting the frame pointer). | |
| 212 | break :b !target.cpu.arch.isX86(); | |
| 213 | } | |
| 209 | 214 | break :b false; |
| 210 | 215 | }; |
| 211 | 216 |