On Thu, 16 Oct 2025 13:32:28 GMT, Yasumasa Suenaga <[email protected]> wrote:

> `jhsdb jstack --mixed` with coredump cannot resolve function symbol which has 
> `.cold` attribute.
> 
> 
> ----------------- 120485 -----------------
> "Thread-0" #24 prio=5 tid=0x00007f50dc1aa7c0 nid=120485 waiting on condition 
> [0x00007f50c0d1a000]
>    java.lang.Thread.State: TIMED_WAITING (sleeping)
>    JavaThread state: _thread_blocked
> 0x00007f50e4710735 __GI_abort + 0x8b
> 0x00007f50e1e01f33 ????????
> 
> 
> 0x7f50e1e01f33 was `os::abort(bool, void const*, void const*) [clone .cold]` 
> and I could see it in GDB. However it has `.cold` suffix, it means the code 
> has been relocated as ["cold" 
> function](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-cold-function-attribute).
>  In GDB, we can see the code in another area from function body as following:
> 
> 
> (gdb) disas 0x7f50e1e01f2e, 0x7f50e1e01f34
> Dump of assembler code from 0x7f50e1e01f2e to 0x7f50e1e01f34:
>    0x00007f50e1e01f2e <_ZN2os5abortEbPKvS1_.cold+0>: call 0x7f50e1e01010 
> <abort@plt>
> => 0x00007f50e1e01f33: nop
> End of assembler dump.
> 
> 
> libsaproc.so checks address range to resolve symbol whether the address is in 
> between `start` and `start + size - 1`. As you can see in assembler dump, the 
> code in `.cold` section is `call` instruction, thus IP points next `nop`, 
> thus we should allow address range between `start` and `start + size`.
> 
> After this PR, you can see the right symbol as following:
> 
> 
> ----------------- 120485 -----------------
> "Thread-0" #24 prio=5 tid=0x00007f50dc1aa7c0 nid=120485 waiting on condition 
> [0x00007f50c0d1a000]
>    java.lang.Thread.State: TIMED_WAITING (sleeping)
>    JavaThread state: _thread_blocked
> 0x00007f50e4710735      __GI_abort + 0x8b
> 0x00007f50e1e01f33      os::abort(bool, void const*, void const*) [clone 
> .cold] + 0x5

I realise this works, I'm just thinking it's more about functions that end on a 
call, so the saved RIP is outside the function's range.
Seeing .cold is a hint that we should add 1 to apparent function length?
There are plenty of other functions that end in a call, and we would not report 
them correctly.

I wondered if all ".cold" functions have padding.
This common abort func does have the nop.
Scanning objdump -d libjvm.so I see there are quite a few  .cold functions that 
end in a call and a new func starts immediately after.
So we would report the wrong function in some cases.

They are quite obscure and not likely to happen.
e.g. we name _ZL21base_of_encoded_valuehP15_Unwind_Context.cold instead of 
_ZL28read_encoded_value_with_basehmPKhPm.cold

Maybe it's better we get the common case correct. 8-)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/27846#issuecomment-3416524462

Reply via email to