@@ -9,23 +9,27 @@ and `.comment` sections:
99objcopy -R .eh_frame -R .comment target/release/tiny even-smaller
1010```
1111
12- For details on the specific optimizations performed, see the options under
13- ` [profile.release] ` and the use of ` default-features = false ` , in Cargo.toml,
14- and the additional link flags passed in build.rs.
12+ On x86_64, this produces a executable with size 408 bytes.
13+
14+ How is this achieved?
1515
1616## The optimizations
1717
18- First, ` origin ` makes much of its functionality optional, so we add
19- ` default-features = false ` to disable things like ` .init_array ` /` .fini_array `
20- support, thread support, and other things. We only enable the features needed
21- for our minimal test program:
18+ First, to make this example really simple, we change it from printing a message
19+ to just returning the number 42.
20+
21+ Next, ` origin ` makes much of its functionality optional, so we add
22+ ` default-features = false ` when declaring the ` origin ` dependency, to disable
23+ things like ` .init_array ` /` .fini_array ` support, thread support, and other
24+ things that our simple example doesn't need. We only enable the features
25+ needed for our minimal test program:
2226
2327``` toml
2428origin = { path = " ../.." , default-features = false , features = [" origin-program" , " origin-start" ] }
2529```
2630
27- Then, we enable several optimizations in the ` #[profile.release] ` section of
28- Cargo.toml :
31+ Then, we add a ` #[profile.release] ` section to our Cargo.toml, to enable
32+ several optimizations :
2933
3034``` toml
3135# Give the optimizer more lattitude to optimize and delete unneeded code.
@@ -194,6 +198,8 @@ Those first 3 instructions are origin's `_start` function. The next 5
194198instructions are ` origin::program::entry ` and everything, including the user
195199` main ` function and the ` exit_group ` syscall inlined into it.
196200
201+ ## Optimizations not done
202+
197203In theory this code code be made even smaller.
198204
199205That first ` mov $rsp,%rdi ` is moving the incoming stack pointer we got from the
0 commit comments