clang Memory sanitizer (msan) and OpenJDK

Baesken, Matthias matthias.baesken at sap.com
Wed Apr 30 13:28:55 UTC 2025


I installed the llvm package to get the   /usr/bin/llvm-symbolizer   (this seems to be needed to get  meaningful stacks) .
Brought back the visibility=hidden settings, seems they do no harm  to msan  .   However the removal  of  -Wl,--exclude-libs,ALL      is needed.
With  the llvm-symbolizer added I get now a stack with file names and  line numbers   (in the build when the new javac is used) :

==81626==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f83267b8121 in JfrThreadLocal::JfrThreadLocal() make/hotspot/src/hotspot/share/jfr/support/jfrThreadLocal.cpp:81:22
    #1 0x7f8327d2e00d in Thread::Thread(MemTag) make/hotspot/src/hotspot/share/runtime/thread.cpp:64:9
    #2 0x7f8326606ef4 in JavaThread::JavaThread(MemTag) make/hotspot/src/hotspot/share/runtime/javaThread.cpp:415:3
    #3 0x7f8327d5347c in Threads::create_vm(JavaVMInitArgs*, bool*) make/hotspot/src/hotspot/share/runtime/threads.cpp:555:33
    #4 0x7f8326865cd2 in JNI_CreateJavaVM_inner(JavaVM_**, void**, void*) make/hotspot/src/hotspot/share/prims/jni.cpp:3587:12
    #5 0x7f8326865cd2 in JNI_CreateJavaVM make/hotspot/src/hotspot/share/prims/jni.cpp:3678:14
    #6 0x7f8329f16008 in InitializeJVM make/src/java.base/share/native/libjli/java.c:1506:9
    #7 0x7f8329f16008 in JavaMain make/src/java.base/share/native/libjli/java.c:494:10
    #8 0x7f8329f21088 in ThreadJavaMain make/src/java.base/unix/native/libjli/java_md.c:646:29
    #9 0x7f8329ecf6e9 in start_thread (/lib64/libpthread.so.0+0xa6e9) (BuildId: 938e42b7e407d175ee3ef9a89c038168101d330c)
    #10 0x7f8329c4458e in clone (/lib64/libc.so.6+0x11858e) (BuildId: 74f77bf013a66413c77197c121955e029c32d259)

Seems msan is unhappy about the thread != nullptr   in line 81  of  jfrThreadLocal.cpp

  Thread* thread = Thread::current_or_null();
  _parent_trace_id = thread != nullptr ? jvm_thread_id(thread) : (traceid)0;

Not sure why this is reported as  uninitialized ?


Best regards, Matthias



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

>Could it be that the  -Wl,--exclude-libs,ALL    “hides”  the  msan symbols like   __msan_param_tls    from exporting ?
>But I guess we set this for a reason so removing it might cause other trouble ?

Seems the -Wl,--exclude-libs,ALL     is the setting that caused the msan build issue, when I remove  it the build works until the first  “new” binary is executed and runs into  :

==64305==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7fbe17639b01  (/builddir/jdk/lib/server/libjvm.so+0x246bb01) (BuildId: b0fcd4709b54740840412c9e6ff0c9ce284848e5)
    #1 0x7fbe18ba4751  (/builddir/jdk/lib/server/libjvm.so+0x39d6751) (BuildId: b0fcd4709b54740840412c9e6ff0c9ce284848e5)
    #2 0x7fbe17489e64  (/builddir/jdk/lib/server/libjvm.so+0x22bbe64) (BuildId: b0fcd4709b54740840412c9e6ff0c9ce284848e5)
    #3 0x7fbe18bc90ab  (/builddir/jdk/lib/server/libjvm.so+0x39fb0ab) (BuildId: b0fcd4709b54740840412c9e6ff0c9ce284848e5)
    #4 0x7fbe176e695b  (/builddir/jdk/lib/server/libjvm.so+0x251895b) (BuildId: b0fcd4709b54740840412c9e6ff0c9ce284848e5)
    #5 0x7fbe1ae182d8  (/builddir/jdk/bin/../lib/libjli.so+0x112d8) (BuildId: 6ae5315fdc089fba90719ba08ab0373371f52bf5)
    #6 0x7fbe1ae23358  (/builddir/jdk/bin/../lib/libjli.so+0x1c358) (BuildId: 6ae5315fdc089fba90719ba08ab0373371f52bf5)
    #7 0x7fbe1add06e9  (/lib64/libpthread.so.0+0xa6e9) (BuildId: 938e42b7e407d175ee3ef9a89c038168101d330c)
    #8 0x7fbe1ab4558e  (/lib64/libc.so.6+0x11858e) (BuildId: 74f77bf013a66413c77197c121955e029c32d259)


Unfortunately the functions and line numbers from the backtrace are not (yet) nicely displayed , guess this needs some improvement .
When calling addr2line on  libjvm.so with the last address from the stack , I get   jfrThreadLocal.cpp:81  .






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/build-dev/attachments/20250430/3976379f/attachment-0001.htm>


More information about the build-dev mailing list