<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Aptos;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Aptos",sans-serif;
        mso-ligatures:standardcontextual;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#467886;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        font-size:11.0pt;
        font-family:"Aptos",sans-serif;
        mso-ligatures:standardcontextual;
        mso-fareast-language:EN-US;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Aptos",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:2001424337;
        mso-list-type:hybrid;
        mso-list-template-ids:-931249726 -1283019024 536870915 536870917 536870913 536870915 536870917 536870913 536870915 536870917;}
@list l0:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;
        mso-fareast-font-family:Aptos;
        mso-bidi-font-family:"Times New Roman";}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="en-DE" link="#467886" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<ul type="disc">
<li style="mso-list:l0 level1 lfo1">I thought I recognized this issue, and started searching the mail archive. Seems the same question was asked last year by ... you. :-)<span style="font-size:12.0pt;mso-ligatures:none;mso-fareast-language:#2000"><o:p></o:p></span></li></ul>
<p class="MsoNormal"><span lang="en-DE">Yeah I looked into msan some time ago and wanted to look into it again  now .<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE"><o:p> </o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1">I don't understand how the msan internal functions are supposed to work, if there is no library to link to. Are they added by the compiler?<span lang="en-DE"><o:p></o:p></span></li></ul>
<p class="MsoNormal"><span lang="en-DE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">I think so !  When I build a simple (working) example with msan   (clang++ -fsanitize=memory    in complie and link step, no libs added), I get a LOT of msan symbols in the resulting binary  :<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">nm msan_umr  | grep _msan  | more<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">00000000000221a0 t _GLOBAL__sub_I_msan_chained_origin_depot.cpp<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">0000000000057520 T __msan_allocated_memory<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">000000000004c5c0 T __msan_chain_origin<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">000000000004c2b0 T __msan_check_mem_is_initialized<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">0000000000093200 T __msan_clear_and_unpoison<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">000000000004c020 T __msan_clear_on_return<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">0000000000057600 T __msan_copy_shadow<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">000000000004cb50 W __msan_default_options<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">000000000004c150 T __msan_dump_shadow<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">000000000004ca60 T __msan_finish_switch_fiber<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">000000000004c3c0 T __msan_get_origin<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">000000000004ade0 T __msan_get_track_origins<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">000000000004c710 T __msan_get_umr_origin<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">   ....<o:p></o:p></span></p>
<ul type="disc">
<li style="mso-list:l0 level1 lfo1">Maybe you can try patching out -fvisibility=hidden from the compile command line to see if that makes any difference.
<o:p></o:p></li></ul>
<p class="MsoListParagraph"><span lang="en-DE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">Sounds like a good idea to start with, I will try this!   Seems the visibility stuff plays a role here.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-DE">Best regards, Matthias<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="en-DE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="en-DE"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-family:"Calibri",sans-serif;mso-ligatures:none;mso-fareast-language:#2000">From:</span></b><span lang="EN-US" style="font-family:"Calibri",sans-serif;mso-ligatures:none;mso-fareast-language:#2000"> Magnus
 Ihse Bursie <magnus.ihse.bursie@oracle.com> <br>
<b>Sent:</b> Monday, 28 April 2025 22:06<br>
<b>To:</b> Baesken, Matthias <matthias.baesken@sap.com>; build-dev@openjdk.org<br>
<b>Subject:</b> Re: clang Memory sanitizer (msan) and OpenJDK<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>I thought I recognized this issue, and started searching the mail archive. Seems the same question was asked last year by ... you. :-)<span style="font-size:12.0pt;mso-ligatures:none;mso-fareast-language:#2000"><o:p></o:p></span></p>
<p><a href="https://mail.openjdk.org/pipermail/build-dev/2024-August/046011.html">https://mail.openjdk.org/pipermail/build-dev/2024-August/046011.html</a><o:p></o:p></p>
<p>I guess nobody still has a simple answer to give you. I don't understand how the msan internal functions are supposed to work, if there is no library to link to. Are they added by the compiler?<o:p></o:p></p>
<p>Maybe you can try patching out -fvisibility=hidden from the compile command line to see if that makes any difference.
<o:p></o:p></p>
<p>/Magnus<o:p></o:p></p>
<div>
<p class="MsoNormal">On 2025-04-25 16:28, Baesken, Matthias wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span lang="EN-US">Hi,  Memory sanitizer</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"><a href="https://clang.llvm.org/docs/MemorySanitizer.html">https://clang.llvm.org/docs/MemorySanitizer.html</a></span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">is supported with the clang toolchain  (e.g. on Linux) ;  “</span><span lang="en-DE">MemorySanitizer is a detector of uninitialized memory use</span><span lang="EN-US">”  .</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">For small examples it is rather easy to use,   you just compile and link   with  
</span>-fsanitize=memory      (and for better results maybe additionally  -fno-omit-frame-pointer )   .<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">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 ).<o:p></o:p></p>
<p class="MsoNormal">As far as compiling single  compilation units this seems to be okay .<o:p></o:p></p>
<p class="MsoNormal">But when it comes to executing the new generated binaries in the build process  we unfortunately  get  lookup errors / undefined symbols   :<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">/builddir/jdk/bin/javac: symbol lookup error:  /builddir/jdk/bin/../lib/libjli.so: undefined symbol: __msan_param_tls<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Is there something special in our OpenJDK  build that causes trouble here ?<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Here I found an somewhat similar looking issue :<o:p></o:p></p>
<p class="MsoNormal"><a href="https://groups.google.com/g/memory-sanitizer/c/xV3OZZCiL9A">https://groups.google.com/g/memory-sanitizer/c/xV3OZZCiL9A</a><o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">where re-exporting symbols is mentioned -  is this maybe something that hits us in OpenJDK too ?<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">For address sanitizer, we set  -shared-libasan in the OpenJDK : 
<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"><a href="https://github.com/openjdk/jdk/blob/5c067232bf21aaca2b7addd2a862e15a8696ffb8/make/autoconf/jdk-options.m4#L449">https://github.com/openjdk/jdk/blob/5c067232bf21aaca2b7addd2a862e15a8696ffb8/make/autoconf/jdk-options.m4#L449</a><o:p></o:p></p>
<p class="MsoNormal">ASAN_LDFLAGS="$ASAN_LDFLAGS -shared-libasan"<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">But I could not find something similar for msan .<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">(btw. I use clang 15.0.7 on SUSE Linux x86_64 in case this matters)
<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Best regards, Matthias<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
</blockquote>
</div>
</body>
</html>