clang Memory sanitizer (msan) and OpenJDK

Baesken, Matthias matthias.baesken at sap.com
Fri Apr 25 14:28:19 UTC 2025


Hi,  Memory sanitizer
https://clang.llvm.org/docs/MemorySanitizer.html

is supported with the clang toolchain  (e.g. on Linux) ;  “MemorySanitizer is a detector of uninitialized memory use”  .

For small examples it is rather easy to use,   you just compile and link   with   -fsanitize=memory      (and for better results maybe additionally  -fno-omit-frame-pointer )   .

So I gave it a try with OpenJDK too and added   -fsanitize=memory      to the  C/CXX and LD flags  (--with-extra-cflags=-fsanitize=memory --with-extra-cxxflags=-fsanitize=memory --with-extra-ldflags=-fsanitize=memory ).
As far as compiling single  compilation units this seems to be okay .
But when it comes to executing the new generated binaries in the build process  we unfortunately  get  lookup errors / undefined symbols   :

/builddir/jdk/bin/javac: symbol lookup error:  /builddir/jdk/bin/../lib/libjli.so: undefined symbol: __msan_param_tls


Is there something special in our OpenJDK  build that causes trouble here ?


Here I found an somewhat similar looking issue :
https://groups.google.com/g/memory-sanitizer/c/xV3OZZCiL9A

where re-exporting symbols is mentioned -  is this maybe something that hits us in OpenJDK too ?


For address sanitizer, we set  -shared-libasan in the OpenJDK :

https://github.com/openjdk/jdk/blob/5c067232bf21aaca2b7addd2a862e15a8696ffb8/make/autoconf/jdk-options.m4#L449
ASAN_LDFLAGS="$ASAN_LDFLAGS -shared-libasan"

But I could not find something similar for msan .


(btw. I use clang 15.0.7 on SUSE Linux x86_64 in case this matters)


Best regards, Matthias







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


More information about the build-dev mailing list