Skip to content

Fix gprof profiling to work with both PBP and PRX executables#347

Merged
fjtrujy merged 2 commits intopspdev:masterfrom
fjtrujy:fix_pg
Jan 12, 2026
Merged

Fix gprof profiling to work with both PBP and PRX executables#347
fjtrujy merged 2 commits intopspdev:masterfrom
fjtrujy:fix_pg

Conversation

@fjtrujy
Copy link
Member

@fjtrujy fjtrujy commented Jan 9, 2026

The profiling library was storing addresses that didn't match the ELF
symbol table, causing psp-gprof to produce empty output.

Changes:

  • Store ELF-compatible addresses in gmon.out instead of offset-based
  • Add PRX vs PBP detection, now we check if module_start function exist and if it is the same than _start, given the case it means it is a PRX
  • Calculate relocation offset for PRX to convert runtime addresses back to link-time addresses that match ELF symbols
  • Update __mcount() and timer_handler() to use link-time addresses

The fix ensures psp-gprof can correctly match profiling data with
ELF symbols for both standard executables (PBP) and relocatable
modules (PRX).

@fjtrujy fjtrujy requested a review from sharkwouter January 9, 2026 22:38
@sharkwouter
Copy link
Member

I've been testing this with OceanPop and it works great when not building a prx, but when I do build a prx I get no output from psp-gprof.

@sharkwouter
Copy link
Member

With the samples, it works totally fine for a prx. I'm not sure what the difference is. I tried different levels of -g and removing -O2 from the examples, but that didn't make a difference either.

@sharkwouter
Copy link
Member

It seems the only scenario that doesn't work is a prx of a C++ application. I created this super basic example where I can reproduce this: https://github.com/sharkwouter/psp-hello-string/tree/test-gprof

Do make sure to use the test-gprof branch.

  The profiling library was storing addresses that didn't match the ELF
  symbol table, causing psp-gprof to produce empty output.

  Changes:
  - Store ELF-compatible addresses in gmon.out instead of offset-based
  - Add PRX vs PBP detection using page alignment heuristic:
    - PRX: loaded at page-aligned addresses, linked at 0
    - PBP: loaded at specific link address (not page-aligned)
  - Calculate relocation offset for PRX to convert runtime addresses
    back to link-time addresses that match ELF symbols
  - Update __mcount() and timer_handler() to use link-time addresses

  The fix ensures psp-gprof can correctly match profiling data with
  ELF symbols for both standard executables (PBP) and relocatable
  modules (PRX).

tmp
@fjtrujy
Copy link
Member Author

fjtrujy commented Jan 12, 2026

Fixed! Try again

Copy link
Member

@sharkwouter sharkwouter left a comment

Choose a reason for hiding this comment

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

Works well with C++ now, thanks!

@fjtrujy fjtrujy merged commit 6cc9698 into pspdev:master Jan 12, 2026
1 check passed
@fjtrujy fjtrujy deleted the fix_pg branch March 6, 2026 16:53
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.

2 participants