On Wed, 13 Oct 2021 00:00:22 GMT, Magnus Ihse Bursie <i...@openjdk.org> wrote:
> This patch expands the newly added system for hsdis backends to include LLVM. > > The actual code in hsdis-llvm.cpp is based heavily on the work by @luhenry, > as published in the never integrated PR > https://github.com/openjdk/jdk/pull/392. (I have basically just ripped out > the binutils-based part of it.) > > Unfortunately I have not been able to make this work properly on Windows. > With some additional flags I made it compile without complaints, but it > caused hotspot to segfault in `LoadLibrary` (!) in `os::dll_load` when I > tried to load the library. This is somewhat ironic, since the initial > implementation was created by Ludovic for the very purpose of using it on > Windows. > > The lack of Windows support in this patch does not mean it is impossible to > get it to work, just that I need to co-operate with someone who has more > experience of compiling LLVM on Windows, and/or are more eager to get this > combination to work. The problem is `LLVMDisasmInstruction()` returns zero size as soon as it hits an instruction it doesn't understand. Something kludgy like this works: diff --git a/src/utils/hsdis/llvm/hsdis-llvm.cpp b/src/utils/hsdis/llvm/hsdis-llvm.cpp index a491082f14fa..3c50ee8e3b40 100644 --- a/src/utils/hsdis/llvm/hsdis-llvm.cpp +++ b/src/utils/hsdis/llvm/hsdis-llvm.cpp @@ -307,6 +307,10 @@ class hsdis_backend : public hsdis_backend_base { virtual size_t decode_instruction(uintptr_t p, uintptr_t start, uintptr_t end) { char buf[128]; size_t size = LLVMDisasmInstruction(_dcontext, (uint8_t*)p, (uint64_t)(end - start), (uint64_t)p, buf, sizeof(buf)); + if (size == 0 && end - start >= 4) { + snprintf(buf, sizeof(buf), "\t.word\t#0x%08x", *(uint32_t*)p); + size = 4; + } if (size > 0) { (*_printf_callback)(_printf_stream, "%s", buf); } 0x0000ffff94685454: br x8 0x0000ffff94685458: .word #0x93e3f4c0 0x0000ffff9468545c: udf #0xffff [Exception Handler] 0x0000ffff94685460: adrp x8, #-0x795000 ; {runtime_call handle_exception_from_callee Runtime1 stub} ------------- PR: https://git.openjdk.java.net/jdk/pull/5920