fix: Properly merge .ctors/.dtors sections into .init_array/.fini_array#1479
Merged
Conversation
0313b5c to
963bf49
Compare
marxin
approved these changes
Jan 25, 2026
marxin
left a comment
Collaborator
There was a problem hiding this comment.
LGTM apart from the nits.
6704b52 to
6a6810f
Compare
6a6810f to
44d2cc3
Compare
marxin
reviewed
Jan 25, 2026
marxin
approved these changes
Jan 25, 2026
| part_id: PartId, | ||
| ) -> Result<Section> { | ||
| let size = object_state.object.section_size(header)?; | ||
| let section_name = object_state.object.section_name(header)?; |
Member
There was a problem hiding this comment.
Note that fetching a C string is somewhat expensive and we're doing it here for all sections.
Benchmark 1 (337 runs): /home/david/save/zed/run-with /home/d/wild-builds/2026-02-09.ctor-dtor-order-revert --no-fork
measurement mean ± σ min … max outliers delta
wall_time 534ms ± 12.9ms 497ms … 567ms 0 ( 0%) 0%
peak_rss 3.47GB ± 1.24MB 3.47GB … 3.47GB 2 ( 1%) 0%
cpu_cycles 21.9G ± 179M 21.3G … 22.5G 5 ( 1%) 0%
instructions 20.2G ± 72.2M 20.1G … 20.7G 10 ( 3%) 0%
cache_references 476M ± 3.50M 467M … 489M 12 ( 4%) 0%
cache_misses 124M ± 710K 123M … 127M 4 ( 1%) 0%
branch_misses 39.3M ± 203K 38.3M … 40.2M 13 ( 4%) 0%
Benchmark 2 (328 runs): /home/david/save/zed/run-with /home/d/wild-builds/2026-02-09 --no-fork
measurement mean ± σ min … max outliers delta
wall_time 549ms ± 14.2ms 503ms … 576ms 1 ( 0%) 💩+ 2.8% ± 0.4%
peak_rss 3.47GB ± 1.20MB 3.47GB … 3.47GB 1 ( 0%) + 0.0% ± 0.0%
cpu_cycles 23.1G ± 178M 22.6G … 23.6G 1 ( 0%) 💩+ 5.2% ± 0.1%
instructions 20.6G ± 62.1M 20.5G … 20.8G 7 ( 2%) 💩+ 1.9% ± 0.1%
cache_references 492M ± 3.15M 486M … 504M 9 ( 3%) 💩+ 3.5% ± 0.1%
cache_misses 133M ± 613K 131M … 135M 11 ( 3%) 💩+ 6.7% ± 0.1%
branch_misses 41.0M ± 199K 39.9M … 41.4M 4 ( 1%) 💩+ 4.4% ± 0.1%
Fixed by #1522
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
.ctors/.dtorsare fundamentally different from.init_array/.fini_arrayin their execution order..ctors/.dtorsexecute function pointers in reverse order (last to first), while.init_array/.fini_arrayexecute them in forward order (first to last). Additionally, their priority numbering is inverted -.ctors/.dtorsuse descending priority (u16::MAX= lowest, 0 = highest), whereas.init_array/.fini_arrayuse ascending priority (0 = highest,u16::MAX= lowest).Until now, Wild has not properly integrated
.ctors/.dtorssections into.init_array/.fini_array. This change implements the integration by inverting the priority of.ctors/.dtorssections (u16::MAX.saturating_sub(p)) to match the.init_array/.fini_arrayordering system and reversing the pointer array contents during write operations to preserve correct execution order.For testing, simply removing the
DiffIgnores fromctors.cshould be sufficient.