-
Notifications
You must be signed in to change notification settings - Fork 465
[Fix] Symbol mapping issue when we have multiple executable segment #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Can you please share the libpython binary or a way to reproduce / obtain it? |
Nit: It would be nice to have a regression test. |
I actually don't think this is library specific. It tends to happen on the spawned subprocess. It's just the binaries go remapped and the segments are reordered in terms of memory address vs offset. |
FWIW I ran into this issue with latest py-spy, saw similar segments as are described above, and confirmed that @yinghai's branch worked perfectly. |
@yinghai I wanted to check out your branch on Windows OS and get a compile error:
|
@fleimgruber yeah sorry probably I only covered the linux case. |
Pushed a change to keep the behavior unchanged for windows. |
@yinghai thanks for the quick change, py-spy compiles fine now, but I still get "Error: Failed to find python version from target process" on Python 3.10.11 |
If it's windows, then I don't know how to solve it but maybe it's in the same line of idea. |
It turns out that we can have multiple executable segment for python binaries
Note that both segement
7b9d5718a000
and7b9d58311000
are executable but first segment has a lower address but a higher offset than the second one. In the code to parse binary, we find the first executable with lowerest address but in symbol map resolution, we use elf in linux to find the first executable with lowest offset to get absolute address of a symbol.py-spy/src/binary_parser.rs
Lines 139 to 145 in 1fa3a6d
This inconsistency causes the symbol address to wrong. Hence py-spy will fail to find python context of the process. Typical error message is
We have a few of such issues (#756, #550), which could be related although there are other reasons that can lead to this.
The fix here is to scan all the executable segments and pick the lowest offset one to parse binary so that we are consistent.