From f7f36d59f86816b6e893c045f8a78e75a79c3a9d Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 9 Oct 2026 09:27:07 -0500 Subject: [PATCH] decomp: pair array destructor, name StandData, real Queue push/pop (section scores 100%) (worker 674f53ed) (#1335) --- config/43U/symbols.txt | 4 +- include/scene/board/iplBoardObject.h | 2 +- include/scene/button/iplButton.h | 2 - include/utility/iplQueue.h | 54 +++++++------- src/scene/button/iplButton.cpp | 21 +----- .../channelEdit/iplNandSDCardManager.cpp | 3 - tools/decomp-assist/o-sections.attempts.md | 71 +++++++++++++++++++ 7 files changed, 106 insertions(+), 51 deletions(-) create mode 100644 tools/decomp-assist/o-sections.attempts.md diff --git a/config/43U/symbols.txt b/config/43U/symbols.txt index 01327bdd..0a1afd1f 100644 --- a/config/43U/symbols.txt +++ b/config/43U/symbols.txt @@ -2524,7 +2524,7 @@ __ct__Q33ipl3snd10tagSSeInfoFv = .text:0x8136C63C; // type:function size:0x30 __ct__Q34nw4r3snd11SoundHandleFv = .text:0x8136C66C; // type:function size:0xC __dt__Q34nw4r3snd11SoundHandleFv = .text:0x8136C678; // type:function size:0x54 __dt__Q33ipl3snd10tagSSeInfoFv = .text:0x8136C6CC; // type:function size:0x58 -__dt__Q33ipl3snd6UnkClsFv = .text:0x8136C724; // type:function size:0x1C scope:local +__arraydtor$15982 = .text:0x8136C724; // type:function size:0x1C scope:local __ct__Q33ipl3snd11tagSBgmInfoFv = .text:0x8136C740; // type:function size:0x30 scope:local __dt__Q33ipl3snd11tagSBgmInfoFv = .text:0x8136C770; // type:function size:0x58 __ct__Q33ipl3snd6SystemFv = .text:0x8136C7C8; // type:function size:0x4C @@ -3223,7 +3223,7 @@ __dt__Q33ipl5scene5BoardFv = .text:0x81393CA4; // type:function size:0x68 __ct__Q33ipl5scene11BoardObjectFv = .text:0x81393D1C; // type:function size:0x140 __dt__Q33ipl4math28LinearIntpFv = .text:0x81393E5C; // type:function size:0x40 __dt__Q33ipl4math31InterporationFv = .text:0x81393E9C; // type:function size:0x40 -init__Q43ipl5scene11BoardObject29@class$8157iplBoardObject_cppFv = .text:0x81393EDC; // type:function size:0x18 +init__Q43ipl5scene11BoardObject9StandDataFv = .text:0x81393EDC; // type:function size:0x18 make_icon_cb___Q23ipl5sceneFPQ33ipl6nigaoe6ObjectPv = .text:0x81393EF4; // type:function size:0x80 create__Q33ipl5scene11BoardObjectFPQ33ipl4nand10LayoutFilePUcUlRC6_CDBIdRC13_CDBRecordKeyRCQ33ipl7utility4Date = .text:0x81393F74; // type:function size:0x84 init__Q33ipl5scene11BoardObjectFv = .text:0x81393FF8; // type:function size:0xA4 diff --git a/include/scene/board/iplBoardObject.h b/include/scene/board/iplBoardObject.h index 4ee67977..e7a5fd6d 100644 --- a/include/scene/board/iplBoardObject.h +++ b/include/scene/board/iplBoardObject.h @@ -159,7 +159,7 @@ namespace ipl { RBRRecordType mRecordType; // 0xDC u32 mOptOutFlag; // 0xE0 - class { + class StandData { public: void init() { mAngleIdx = -1; diff --git a/include/scene/button/iplButton.h b/include/scene/button/iplButton.h index 65f0ae36..abd9dfe1 100644 --- a/include/scene/button/iplButton.h +++ b/include/scene/button/iplButton.h @@ -12,7 +12,6 @@ namespace ipl { namespace scene { - extern "C" BOOL push_button_queue(void*, const void*); class ButtonEventHandlerBase; class OptOutButtonEventHandlerBase; class SDMenuEventHandlerBase; @@ -315,7 +314,6 @@ namespace ipl { } protected: - friend BOOL push_button_queue(void*, const void*); typedef struct Command { enum { TYPE_ANIM = 0, diff --git a/include/utility/iplQueue.h b/include/utility/iplQueue.h index 892e22b3..0496b698 100644 --- a/include/utility/iplQueue.h +++ b/include/utility/iplQueue.h @@ -10,31 +10,9 @@ namespace ipl { public: inline Queue() : count(c), current(0), popped(0), pushed(0) {} - BOOL push(const T& item) { - if (count == current) { - return FALSE; - } - items[pushed] = item; - if (++pushed >= count) { - pushed = 0; - } - current++; - return TRUE; - } + BOOL push(const T& item); - BOOL pop() { - BOOL result = TRUE; - if (current == 0) { - result = FALSE; - goto done; - } - if (++popped >= count) { - popped = 0; - } - current--; - done: - return result; - } + BOOL pop(); int get_current_index() { return current; } T& get_current_item() { return items[get_current_index()]; } @@ -55,6 +33,34 @@ namespace ipl { int current; // (sizeof(items) * count) + 0x04 int popped, pushed; // (sizeof(items) * count) + 0x08 }; + + template + BOOL Queue::push(const T& item) { + if (count == current) { + return FALSE; + } + items[pushed] = item; + if (++pushed >= count) { + pushed = 0; + } + current++; + return TRUE; + } + + template + BOOL Queue::pop() { + BOOL result = TRUE; + if (current == 0) { + result = FALSE; + goto done; + } + if (++popped >= count) { + popped = 0; + } + current--; + done: + return result; + } } // namespace utility } // namespace ipl diff --git a/src/scene/button/iplButton.cpp b/src/scene/button/iplButton.cpp index a54e4ecc..0966bfc8 100644 --- a/src/scene/button/iplButton.cpp +++ b/src/scene/button/iplButton.cpp @@ -9,7 +9,6 @@ extern char scPaneName_B_Stop[7]; extern char scPaneName_T_Stop[]; -extern "C" BOOL push_button_queue(void*, const void*); namespace ipl { namespace scene { @@ -828,7 +827,7 @@ namespace ipl { Command command; command.type = Command::TYPE_ANIM; command.animId = animId; - push_button_queue(&mReservedCmd, &command); + mReservedCmd.push(command); } void Button::reserveText(int paneId, u32 msgId) { @@ -836,7 +835,7 @@ namespace ipl { command.type = Command::TYPE_TEXT; command.paneId = paneId; command.msgId = msgId; - push_button_queue(&mReservedCmd, &command); + mReservedCmd.push(command); } /* ============== */ @@ -968,22 +967,6 @@ namespace ipl { void OptOutButtonEventHandlerBase::onEventDerived(u32 compId, u32 event, const controller::Interface* con) { } - - extern "C" BOOL push_button_queue(void* storage, const void* item) { - typedef utility::Queue CommandQueue; - CommandQueue* queue = static_cast(storage); - const Button::Command* command = static_cast(item); - if (queue->count == queue->current) { - return FALSE; - } - queue->items[queue->pushed] = *command; - if (++queue->pushed >= queue->count) { - queue->pushed = 0; - } - queue->current++; - return TRUE; - } - } // namespace scene } // namespace ipl diff --git a/src/scene/channelEdit/iplNandSDCardManager.cpp b/src/scene/channelEdit/iplNandSDCardManager.cpp index 9347f7f9..d16ede74 100644 --- a/src/scene/channelEdit/iplNandSDCardManager.cpp +++ b/src/scene/channelEdit/iplNandSDCardManager.cpp @@ -3,9 +3,6 @@ #include "titledb.h" -// actually needed to match. -#pragma sym on - namespace ipl { namespace scene { #define COMMAND_FN(FUNCTION_HEADER, TAG, APP_BOX, SAVE_BOX, WII_TITLE_ID, SD_TITLE_ID) \ diff --git a/tools/decomp-assist/o-sections.attempts.md b/tools/decomp-assist/o-sections.attempts.md new file mode 100644 index 00000000..73411043 --- /dev/null +++ b/tools/decomp-assist/o-sections.attempts.md @@ -0,0 +1,71 @@ +# o-sections: linked units with .text section below 100% + +Task: `check_decomp_complete.py` failed on three linked units whose functions were +all 100% but whose `.text` section score was not: iplSound 99.49785, +iplBoardObject 99.73868, iplButton 98.53095. + +## Cause + +objdiff 3.4.5 scores a code section as the size-weighted mean of the target +symbols' match percent, with an unpaired target symbol counted as 0 +(`diff_generic_section` in objdiff-core/src/diff/data.rs). The per-function list +in the report hides this: for a `complete` unit, `report.rs` falls back to 100% +when a target symbol has no partner. Pairing is by exact name, plus +`name$` against `name$` (`symbol_name_matches`). The report +ignores objdiff.json `symbol_mappings` (it uses `MappingConfig::default()`). + +Each unit had exactly one unpaired target function, equal to the missing bytes: + +| unit | target symbol | built symbol | bytes | +|------|---------------|--------------|-------| +| iplSound | `__dt__Q33ipl3snd6UnkClsFv` | `__arraydtor$15981` | 0x1c | +| iplBoardObject | `init__Q43ipl5scene11BoardObject29@class$8157iplBoardObject_cppFv` | `...30@class$12470...` | 0x18 | +| iplButton | `push__Q33ipl7utility36QueueFRCQ43ipl5scene6Button7Command` | `push_button_queue` | 0x70 | + +Extra weak or dead-stripped functions in the built objects do not affect the +score (only target symbols count). + +## Fixes + +- iplSound: the target function is `__destroy_arr(_seBlk, ~tagSSeInfo, 0xc, 16)`, + the compiler's array destructor for `tagSSeInfo _seBlk[16]`; `UnkCls` was a + placeholder. Renamed in symbols.txt to `__arraydtor$15982`. The `$` + rule pairs it with any number, so header churn cannot break it. +- iplBoardObject: the `@class$NNNN` id is a TU-wide counter that moves + with any earlier header change (30039 -> 8157 upstream, now 12470; my + iplQueue.h change alone moved it to 12471). objdiff cannot pair it unless the + number is exact, so a symbols.txt resync would go stale on the next header + edit. Named the class `StandData` (identical code) and renamed the symbol to + `init__Q43ipl5scene11BoardObject9StandDataFv`. +- iplButton: `push_button_queue` was an extern "C" stand-in (first asm, then C) + for `mReservedCmd.push(command)`, added because the in-class `Queue::push` + instance is emitted right after `reserveAnm` (DOL mismatch). In the target, + `push` is the last function before the `@20@` dtor thunk, and in + NandSDCardManager all Queue instances sit at the end of the TU in first-use + order (push, pop, push), with single-caller + pop inlined. That is deferred template instantiation: `push` and + `pop` were defined outside the class. Moved both out of class in + `utility/iplQueue.h` and restored `mReservedCmd.push(command)`. +- iplNandSDCardManager: its `#pragma sym on` ("actually needed to match") was + the old workaround for the same placement. With out-of-class push/pop the + pragma splits three ordinary functions into a second `.text`; without it the + layout matches the target. Removed it. Same 72 functions, identical bytes. + +## Results + +- `.text`: iplSound 100, iplBoardObject 100, iplButton 100; NandSDCardManager, + iplBoard and iplSceneManager still 100 in every section. +- Pools identical in all five touched units; DOL SHA1 unchanged. +- check_decomp_complete.py: only remaining failure is main/src/keyboard/tiString + (`inputChar__Q39textinput8tistring9DecolatedFw` 93.55882, unit not linked). + +## Tried and rejected + +- Template `push` in-class (da7 queue-01): exact bytes but placed after + reserveAnm, DOL changes. +- Out-of-class push with `#pragma sym on` kept in NandSDCardManager: + on_get_thumbnail, clean_command_queue and getAsyncResult move into the + second `.text`; layout breaks. +- Out-of-class push only (pop in-class), no sym pragma: push instances at the + end but pop stays mid-file; target needs it between the pushes. +- symbols.txt resync to `@class$12470`: works now, breaks on the next header edit.