Skip to content

Add precompiled headers for framework and RELs#2597

Merged
hatal175 merged 1 commit intozeldaret:mainfrom
caseif:dolzel
Aug 24, 2025
Merged

Add precompiled headers for framework and RELs#2597
hatal175 merged 1 commit intozeldaret:mainfrom
caseif:dolzel

Conversation

@caseif
Copy link
Copy Markdown
Contributor

@caseif caseif commented Aug 22, 2025

This PR adds a precompiled header (dolzel.pch) for use in RELs to match the original build process. This has a huge effect on weak function ordering and as a result many TUs are now matching as a result of these changes. This also seems to solve (at least partly) the Z2Calc::cNullVec, lit_1787, and lbl_*_data_10 .data entries and lit_1109-lit_1009 .bss entries seen across the codebase.

This PR also removes nosyminline on from the default REL flags (and from many individual framework objects) since it is no longer necessary in the majority of cases.

One issue with the changeset in its current state involves the handling of the sqrtf constants. The PCH needs to be built with .sdata and .sdata2 enabled in order for d_kankyo and d_resorce to match; however, this causes the constants to be placed in .sdata2 even in RELs such as in d_a_b_yo or d_a_L7op_demo_dr (where they should be in .rodata). This not only breaks matches, but also breaks linking entirely with this message:

#   Small data sections must have their own output sections specified in the 
#   linker command file.
#   No linker command file output section '.sdata2'.

The solution to this for now is to build the PCH twice: once with framework flags, and once with REL flags. Each object links one version or the other as appropriate. This may or may not be a fakematch and should be replaced if a better solution is found in the future.

This PR includes the changes from encounter/dtk-template#60 in order to support building the PCHs. objdiff isn't yet capable of understanding the weak data stripping going on here, so there are a LOT of false data regressions reported as a result.

See zeldaret/tww#860 for the corresponding Wind Waker PR for PCH changes.

@decomp-dev
Copy link
Copy Markdown

decomp-dev bot commented Aug 22, 2025

Report for GZ2E01 (8a30030 - ffd010d)

📈 Matched code: 79.56% (+0.02%, +2208 bytes)
📈 Linked code: 47.14% (+16.81%, +1930772 bytes)

✅ 5 new matches
Unit Function Bytes Before After
d_a_e_pm/d/actor/d_a_e_pm cM3dGPla::~cM3dGPla() +72 0.00% 100.00%
framework/d/d_camera dCamera_c::lineCollisionCheckBush(cXyz*, cXyz*) +18 89.64% 100.00%
d_a_e_rb/d/actor/d_a_e_rb daE_RB_Create(fopAc_ac_c*) +17 98.35% 100.00%
d_a_e_pm/d/actor/d_a_e_pm daE_PM_c::SearchFarP() +2 99.76% 100.00%
d_a_e_pm/d/actor/d_a_e_pm daE_PM_c::At_Check() +2 99.65% 100.00%
💔 3 broken matches
Unit Function Bytes Before After
d_a_obj_hata/d/actor/d_a_obj_hata csXyz::~csXyz() -60 100.00% 0.00%
d_a_obj_hata/d/actor/d_a_obj_hata csXyz::csXyz() -4 100.00% 0.00%
framework/d/d_map dMap_c::getColor(int) -1 100.00% 99.88%

@caseif caseif marked this pull request as draft August 22, 2025 04:29
@caseif caseif force-pushed the dolzel branch 6 times, most recently from 21b386c to f25f454 Compare August 22, 2025 20:24
@caseif caseif changed the title Add a precompiled header for RELs Add precompiled headers for framework and RELs Aug 22, 2025
@caseif caseif force-pushed the dolzel branch 3 times, most recently from 23dfef7 to 2934b5f Compare August 23, 2025 22:43
@caseif caseif marked this pull request as ready for review August 23, 2025 22:46
@caseif caseif force-pushed the dolzel branch 2 times, most recently from 0b69ac6 to d684b62 Compare August 23, 2025 23:14
return l_dzbName;
}

static const char* dummy() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the dummy necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's there to force it to be placed earlier in .rodata, not sure if there's a more elegant way to do this though.

Object(MatchingFor("GZ2E01", "GZ2J01"), "d/d_map.cpp"),
Object(MatchingFor("GZ2E01", "GZ2J01"), "d/d_com_inf_game.cpp", extra_cflags=['-pragma "nosyminline on"']),
Object(MatchingFor("GZ2E01", "GZ2J01"), "d/d_stage.cpp"),
Object(Equivalent, "d/d_map.cpp"), # weak func order
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these ones that were changed from matching to equivalent not compatible with this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For d_map including the PCH completely messes up the function order - I think that this object may actually not have included it. For d_select_cursor I think the PCH is correct, but it messes up the vtable padding which was previously solved with a fakematch (which I think ultimately comes down to a vtable ordering issue). I'll revert the first change for now and add a comment that it might be fake - let me know if you want me to revert the second change as well.

@caseif caseif force-pushed the dolzel branch 2 times, most recently from c9d412a to 3c310ef Compare August 24, 2025 04:05
@hatal175 hatal175 merged commit 513816c into zeldaret:main Aug 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants