JDK-8247515 : OSX pc_to_symbol() lookup does not work with core files
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc-agent
  • Affected Version: 16
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-06-12
  • Updated: 2024-11-13
  • Resolved: 2020-07-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 16
11.0.15Fixed 16 b08Fixed
Related Reports
Blocks :  
Blocks :  
Blocks :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
As part of the work for JDK-8247514 and also investigation for JDK-8247272, I came to the realization that pc_to_symbol() lookup on OSX is very broken. There are many bugs, and I doubt it ever worked. symbol_to_pc() works fine, but that uses the completely separate OSX Symbolicator support, and it's implementation is not in any way related to pc_to_symbol().

Note the OSX pc_to_symbol() lookup is not even implemented when working on a live process. I'm not attempting to remedy that with this CR. This CR only focuses on fixing the existing pc_to_symbol() support for core files.

Note that pc_to_symbol() is not really needed as part of SA core functionality (symbol_to_pc() is critical for vtable lookups). It is used by clhsdb "whatis" command, and also the clhsdb "mem" command, which will try to display any native symbol near a given address. Note that neither of these commands currently work since they were written in javascript, which has been removed. However, "whatis" functionality is being added to "findpc" by JDK-8247514, and that is when I noticed this issue. I'll also eventually convert "mem" to java, so it would also run into this issue.

The main bug is in build_symtab(), where it tries to compute the size of the data that the symbol represents by looking at the offset for the next symbol in the symbols array, and comparing with the offset the current symbol. Basically "size of current symbol" == "offset of next symbol" - "offset of current symbol". This is faulty due to symbols not being sorted by offset. Because of this many symbols had extremely large or negative sizes. Then when a lookup was done, the lookup code often incorrectly thought the address fell within the bounds of the symbol when it did not. In fact most addresses matched on the first symbol of the first library, which was actually a symbol that represented a source file name, and due to some bad math had a negative size, which just messed things up even more.

nearest_symbol() is also not aware that the symbol table is not sorted, also resulting in it usually finding the wrong symbol. 

symbol_for_pc() also needs to be fixed to make sure it doesn't try to find a symbol in the wrong library. It doesn't know the size of a library, and as a result the code was trying to find the symbol in the first library checked, and if the symbol wasn't actually in that library it would match on the last symbol since there was no next symbol to check and see if the offset is greater. It needs to be fixed by first finding which library the symbol is in by taking advantage of the fact that libraries are sorted by address.


Comments
Yes https://bugs.openjdk.java.net/browse/JDK-8250750 is related; was running into jtreg HS test issues handling core files (serviceability/sa/TestJmapCore.java) when switching to a new Xcode + Mac build server.
21-02-2022

Hi Matthias, same here, can you elaborate a bit more why you request this backport? I believe it goes together with JDK-8247272 and JDK-8250750?
18-02-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk11u-dev/pull/832 Date: 2022-02-18 09:16:26 +0000
18-02-2022

jdk11u fix request I would like to have the fix in 11 because the issue is present there too. The patch applies cleanly with the exception of the copyright headers in src/jdk.hotspot.agent/macosx/native/libsaproc/libproc_impl.h:1 and src/jdk.hotspot.agent/macosx/native/libsaproc/ps_core.c:1 which were altered by other backports. PR is : https://github.com/openjdk/jdk11u-dev/pull/832
18-02-2022

URL: https://hg.openjdk.java.net/jdk/jdk/rev/2a4c6b72e5c3 User: cjplummer Date: 2020-07-28 16:55:02 +0000
28-07-2020