Commit Graph
113 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5 8594592f9c Pair HI16 relocations with the right LO16 when loading a PRX
CrossCraft Classic jumps to 0xae870000 a few seconds in, after a couple of
button presses, and dies. It runs fine on a real PSP.

The jump is a Zig interface call - std.mem.Allocator is {ptr, vtable} and the
crash is `lw t9, 0(vtable); jalr t9`. The vtable pointer had come out as
0x089191E0 instead of 0x089291E0, exactly 64KB low, so t9 was loaded from the
middle of compiler_rt.udivmod and the "function pointer" was really the
instruction word `sw a3,0(s4)`.

That pointer is built by a lui/addiu pair, and which LO16 completes a given
HI16 decides one thing: whether the high half carries. We were pairing each
HI16 with the next non-HI16 relocation in the table, which can't work in
general. A PRX relocation carries no symbol index - r_info holds segment
numbers - so the table cannot express the pairing. prxgen does order it so a
HI16 is followed by a LO16 for the same symbol, but not necessarily by *its*
LO16: LLVM schedules several luis together and their addius come back
permuted, here even earlier in the table than the lui they belong to. Two
LO16s for one symbol usually yield the same high half, which is why this has
gone unnoticed for so long - it only bites when their low halves land on
opposite sides of 0x8000. This game has two .rodata references in one
function that do exactly that, and the loader swapped them.

Pair the way the compiler generated it instead: the lui loads a register, and
the instruction completing it is the next one using that register as a base -
unless another lui reloads that register first, in which case the candidate
belongs to that one. Falls back to the old scan when the register trail goes
cold (the value gets copied before use), so nothing that worked before stops.

Checked exhaustively against an oracle: the pre-link ELF still has a symbol,
and thus a section, for every relocation, so any pairing whose result lands
outside that section is wrong. Over this module's 8589 HI16 relocations the
old rule puts 22 outside their section; the new one puts 0, and never picks a
LO16 belonging to a different symbol. Both the register match and the reload
guard are needed - without the guard it scores worse than the old rule.

Impact is narrow. On GCC-built PRXs (pspautotests) the chosen LO16 differs for
2-4 relocations per module and the emitted instruction changes in none of
them. On this LLVM-built module 449 pairings differ and 46 emitted addresses
change, i.e. 46 pointers that were quietly 64KB off.

pspautotests 314/314, unit tests 51/51.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-17 18:47:26 +02:00
Henrik Rydgård c5e4d0d90d Rename the get-memory-pointer functions to make it clear where CPU exceptions can happen. 2026-08-12 14:06:16 +02:00
Henrik Rydgård 3bd41376da More memory cleanup 2026-08-11 20:12:10 +02:00
Henrik Rydgård abb57c620f Adjust some log levels 2026-08-09 22:10:54 +02:00
Henrik Rydgård 4bf36fc7f8 Add command line option --vsh to try to boot the VSH. Logspam reduction, improve printf logs. 2026-07-27 14:58:59 +02:00
Henrik Rydgård 0c4563c253 Throw in a check for the additional issue commented in #21073 2025-12-15 23:43:17 +01:00
Henrik Rydgård ed6ec0517b Fix #21073, plus an additional OOB read 2025-12-15 23:35:07 +01:00
Henrik Rydgård fab709af57 ELF loading: Shouldn't use ReadInstruction here, relocs might be unaligned. 2025-05-19 20:41:33 +02:00
Henrik Rydgård fba2489c79 Remove dubious parallelization in ELF loading, initialize a var, add some checks 2025-05-15 09:48:23 +02:00
Henrik Rydgård 41b77bf1ae More log cleanup 2025-04-14 22:27:51 +02:00
Henrik Rydgård 0f840e6240 Move JPEG error codes to the big enum, some include cleanup 2025-03-21 20:44:46 +01:00
Henrik Rydgård 3e198c53b2 More include cleanup 2024-12-18 13:57:26 +01:00
Henrik Rydgård 6a7435341e Some reporting cleanups 2024-10-28 17:25:40 +01:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00
Henrik Rydgård fae1f4acd3 A null check and a locking simplification 2024-01-30 19:15:19 +01:00
Unknown W. Brackets b2b61d58d4 Loader: Support HI16/16 pairs, not just LO16.
Motorstorm: Arctic Edge US uses these pairs for some VFPU loads.
Without relocating these, strange shadows show underneath vehicles.

It appears as if actual firmware pairs with any non-HI16 relocation.
2023-06-18 19:06:29 -07:00
Unknown W. Brackets a9668bdb60 Debugger: More useful tag for section suballocs. 2023-06-18 19:04:18 -07:00
Henrik Rydgård 4dd4bf24fc Merge pull request #17561 from unknownbrackets/elf-reloc
Loader: Report on HI16/LO16 r_info mismatch
2023-06-11 23:59:52 +02:00
Unknown W. Brackets 4108eaca42 Loader: Add additional data to missing LO16 report. 2023-06-11 14:41:50 -07:00
Unknown W. Brackets ef59b60aac Loader: Report on HI16/LO16 r_info mismatch.
Referenced in some LLVM code which checks the index specifically:
https://github.com/llvm/llvm-project/blob/c72dea88b635bfd7856fa22bcaf388fa72c9fe86/lld/ELF/Relocations.cpp#L491

Noted by Kingcom.
2023-06-11 14:37:43 -07:00
Unknown W. Brackets 46101581c0 Core: Cleanup disasm buffer usage. 2023-04-29 09:07:25 -07:00
Unknown W. Brackets 88ba003f46 ThreadManager: Add a simple priority field.
Currently, not actually respected.
2023-02-02 17:08:24 -08:00
Unknown W. Brackets dea9cac16c Core: Add range checks to some helpers and similar. 2023-01-09 16:56:18 -08:00
Unknown W. Brackets 9cfcbc46e6 Global: Cleanup initialization/pointer checks.
Cleaning up a lot of cases of uninitialized data, unchecked return values
for failures, and similar.
2022-12-10 21:13:36 -08:00
Henrik Rydgård 50285f6bf6 Revert "Revert "Loader: Validate offsets and truncation in ELF.""
This reverts commit 470edac18a.
2022-10-10 13:29:09 +02:00
Henrik Rydgård 6833589e38 Update elfSize to uncompressed elf size when needed. Fixes infinite loading in Wipeout.
Also minor cleanups.
2022-10-10 12:22:05 +02:00
Henrik Rydgård 470edac18a Revert "Loader: Validate offsets and truncation in ELF."
This reverts commit 4ecdce2a37.
2022-10-10 11:42:24 +02:00
Unknown W. Brackets 4ecdce2a37 Loader: Validate offsets and truncation in ELF. 2022-10-09 16:41:32 -07:00
Henrik Rydgård ac7ca963db Make valgrind happy 2022-09-23 12:24:43 +02:00
Henrik Rydgård e6403d7157 Split GetPointer into two versions, to help with const correctness 2022-07-24 13:26:19 +02:00
Unknown W. Brackets cdcd77a931 Core: Correct relocation error check. 2021-06-13 10:51:51 -07:00
Henrik Rydgård 77908cb9e5 atomic include buildfix 2021-06-12 23:20:47 +02:00
Henrik Rydgård 73871b9b7e Implement new thread manager, port stuff to it. 2021-06-12 13:03:53 +02:00
Unknown W. Brackets 4f6aaea1e8 Core: Correct thread dependency in relocations.
Didn't realize it was looking at the later value before relocation.
This still remains about as much faster as before and still beneficial to
thread.
2021-04-25 16:49:52 -07:00
Unknown W. Brackets 572c20b4cd Debugger: Mark ELF sections as suballocations.
Sometimes they're named, it's helpful to see where rodata starts, etc.
2021-04-21 19:45:58 -07:00
Unknown W. Brackets 6ee944a0a6 Module: Process relocations on threads.
There's usually quite some, and using threads can halve the load time.
ELF loading isn't terribly slow, but it adds up.
2021-04-16 00:41:56 -07:00
Unknown W. Brackets e7012f8f88 Module: Process relocations using unchecked reads.
No need to do checks twice.  Also switch the LO16 part to
Read_Instruction.
2021-04-16 00:32:42 -07:00
Unknown W. Brackets f6ad90fab8 Module: Correctly handle modules with -1 entry.
It should not try to run, options or not.
2021-03-14 16:52:48 -07:00
Unknown W. Brackets 9ead436069 Debugger: Specifically tag relocations.
This is useful info.
2021-02-15 15:01:23 -08:00
Unknown W. Brackets ca7d127adc Debugger: Notate more cases of memory clears. 2021-02-15 15:01:23 -08:00
Unknown W. Brackets f7740edc6d Debugger: Add more metadata for memory usage. 2021-02-15 15:01:21 -08:00
Unknown W. Brackets 1b00da2f3a Common: Sign extend w/func not chained casts.
Should be clearer to read and easier to get right.
2021-01-31 01:25:52 -08:00
shenweip 807de037bb IMP sceKernelFindModuleByUID and sceKernelFindModuleByName. 2020-10-27 20:48:34 +08:00
Unknown W. Brackets e21753bc93 Debugger: Add assembler to build. 2018-06-06 05:59:24 -07:00
Unknown W. Brackets 0e2a586c1b Global: Fix some type comparison/shadow warnings. 2018-02-11 07:03:23 -08:00
Unknown W. Brackets 30b2d05bac Module: Correct detection of executable sections. 2018-01-02 21:53:13 -08:00
Henrik Rydgård 42bdf3e19b ELF loading potential out-of-bounds fix 2017-06-07 00:22:37 +02:00
Henrik Rydgård 9ce874d2cf Typo fix, MOBILE_DEVICE 2017-05-25 00:31:00 +02:00
Henrik Rydgård 875e7f0372 Throw in a few more checks in ElfReader 2017-05-24 20:45:29 +02:00
Henrik Rydgård e981139e71 Some constification in ElfReader, sanity checks in sceKernelMutex. Might help #9718 a little bit, though probably not the Elf issue (and if the workarea pointer is bad, it's not likely the game will limp along for much longer) 2017-05-24 10:52:19 +02:00