<div dir="ltr"><div dir="ltr"><div dir="ltr">We already do this for Fuchsia. We've added support for building sanitized runtimes (<a href="https://github.com/llvm-mirror/llvm/blob/master/runtimes/CMakeLists.txt#L501">https://github.com/llvm-mirror/llvm/blob/master/runtimes/CMakeLists.txt#L501</a>) and we use it to build ASan instrumented libc++/libc++abi/libunwind (<a href="https://github.com/llvm-mirror/clang/blob/master/cmake/caches/Fuchsia-stage2.cmake#L115">https://github.com/llvm-mirror/clang/blob/master/cmake/caches/Fuchsia-stage2.cmake#L115</a>) which end up in lib/clang/.../$triple/asan (if using the multiarch runtime layout which is the default for us). We hope to use other sanitizers in the future as well.</div><div dir="ltr"><br></div><div>Since the instrumented and uninstrumented libc++/libc++abi/libunwind should have the same ABI, there should be no need to change which library you link against, the only thing  that's important is which library you load at runtime. On Fuchsia this is handled by our dynamic linker. On Linux we'll likely need to use -rpath or some other solution.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 31, 2018 at 11:30 AM Evgenii Stepanov via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This would be nice.<br>
So, to be clear, there would be libc++.so / libc++.a somewhere under<br>
lib/clang/.../$triple/msan, and the driver would link that if libc++<br>
is not specified explicitly on the command line? Would it also add<br>
-rpath? This could be weird because toolchain may not be present when<br>
the binary is run.<br>
<br>
On Fri, Aug 31, 2018 at 11:14 AM, Vitaly Buka <<a href="mailto:vitalybuka@google.com" target="_blank">vitalybuka@google.com</a>> wrote:<br>
> +Evgenii Stepanov<br>
> sgtm<br>
><br>
> On Fri, Aug 31, 2018 at 6:49 AM Brian Cain <<a href="mailto:brian.cain@gmail.com" target="_blank">brian.cain@gmail.com</a>> wrote:<br>
>><br>
>> Aside: would it be useful to execute a build of the libc++/libc++abi with<br>
>> msan normally during release, and change the driver to look for these<br>
>> msan-built C++ libs when "-fsanitize=memory"?  That would drastically cut<br>
>> down on the complexity of using msan.<br>
>><br>
>> On Fri, Aug 31, 2018 at 5:43 AM Dean Michael Berris via llvm-dev<br>
>> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
>>><br>
>>> Thanks Vitaly and Peter,<br>
>>><br>
>>> I went with a modified version of the instructions from<br>
>>> <a href="https://github.com/google/sanitizers/wiki/MemorySanitizerBootstrappingClang" rel="noreferrer" target="_blank">https://github.com/google/sanitizers/wiki/MemorySanitizerBootstrappingClang</a><br>
>>> — that’s a very helpful set of instructions!<br>
>>><br>
>>> Cheers<br>
>>><br>
>>> > On 31 Aug 2018, at 02:55, Vitaly Buka <<a href="mailto:vitalybuka@google.com" target="_blank">vitalybuka@google.com</a>> wrote:<br>
>>> ><br>
>>> > Another option is just to run corresponding script from<br>
>>> > <a href="https://llvm.org/svn/llvm-project/zorg/trunk/zorg/buildbot/builders/sanitizers/" rel="noreferrer" target="_blank">https://llvm.org/svn/llvm-project/zorg/trunk/zorg/buildbot/builders/sanitizers/</a><br>
>>> > in empty directory.<br>
>>> ><br>
>>> > On Thu, Aug 30, 2018 at 5:00 AM Peter Smith via llvm-dev<br>
>>> > <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
>>> > Hello Dean,<br>
>>> ><br>
>>> > I've not done this myself for a while, I seem to remember it taking a<br>
>>> > while to get right. When I did I found the page:<br>
>>> ><br>
>>> > <a href="https://github.com/google/sanitizers/wiki/MemorySanitizerBootstrappingClang" rel="noreferrer" target="_blank">https://github.com/google/sanitizers/wiki/MemorySanitizerBootstrappingClang</a><br>
>>> > useful. The other thing that might work is following the individual<br>
>>> > cmake steps from<br>
>>> > <a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-msan" rel="noreferrer" target="_blank">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-msan</a><br>
>>> > . These aren't in the same structure as the monorepo but they may be<br>
>>> > adaptable.<br>
>>> ><br>
>>> > My apologies if you've tried these already.<br>
>>> ><br>
>>> > Peter<br>
>>> ><br>
>>> > On 30 August 2018 at 12:42, Dean Michael Berris via llvm-dev<br>
>>> > <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
>>> > > Hi llvm-dev,<br>
>>> > ><br>
>>> > > I'm trying to reproduce an msan failure in one of the bots, but I<br>
>>> > > can't seem to get the right incantation of building LLVM with msan.<br>
>>> > > Here's what I've been doing:<br>
>>> > ><br>
>>> > > 1) Build the toolchain in one build directory, including<br>
>>> > > `compiler-rt`.<br>
>>> > ><br>
>>> > > 2) Build the toolchain again with the just built toolchain in step 1,<br>
>>> > > but this time with `-DLLVM_USE_SANITIZER=MemoryWithOrigins`.<br>
>>> > ><br>
>>> > > I get some msan errors, but of this kind instead of the one I'm<br>
>>> > > expecting:<br>
>>> > ><br>
>>> > > ====<br>
>>> > > $ ./unittests/XRay/XRayTests<br>
>>> > > ==236769==WARNING: MemorySanitizer: use-of-uninitialized-value<br>
>>> > >     #0 0x70eef8<br>
>>> > ><br>
>>> > > (/usr/local/google/home/dberris/xray/llvm-project-build-msan/unittests/XRay/XRayTests+0x70eef8)<br>
>>> > >     #1 0x70d2dc<br>
>>> > ><br>
>>> > > (/usr/local/google/home/dberris/xray/llvm-project-build-msan/unittests/XRay/XRayTests+0x70d2dc)<br>
>>> > >     #2 0x721044<br>
>>> > ><br>
>>> > > (/usr/local/google/home/dberris/xray/llvm-project-build-msan/unittests/XRay/XRayTests+0x721044)<br>
>>> > >     #3 0x6e2a37<br>
>>> > ><br>
>>> > > (/usr/local/google/home/dberris/xray/llvm-project-build-msan/unittests/XRay/XRayTests+0x6e2a37)<br>
>>> > >     #4 0x3722aa<br>
>>> > ><br>
>>> > > (/usr/local/google/home/dberris/xray/llvm-project-build-msan/unittests/XRay/XRayTests+0x3722aa)<br>
>>> > >     #5 0x372868<br>
>>> > ><br>
>>> > > (/usr/local/google/home/dberris/xray/llvm-project-build-msan/unittests/XRay/XRayTests+0x372868)<br>
>>> > >     #6 0x775a4c<br>
>>> > ><br>
>>> > > (/usr/local/google/home/dberris/xray/llvm-project-build-msan/unittests/XRay/XRayTests+0x775a4c)<br>
>>> > >     #7 0x7f85b6c7e23f  (/lib/x86_64-linux-gnu/libc.so.6+0x2023f)<br>
>>> > >     #8 0x2f4029<br>
>>> > ><br>
>>> > > (/usr/local/google/home/dberris/xray/llvm-project-build-msan/unittests/XRay/XRayTests+0x2f4029)<br>
>>> > ><br>
>>> > >   Uninitialized value was created by an allocation of 'ref.tmp' in<br>
>>> > > the<br>
>>> > > stack frame of function<br>
>>> > ><br>
>>> > > '_ZN7testing8internal12UnitTestImpl11AddTestInfoEPFvvES3_PNS_8TestInfoE'<br>
>>> > >     #0 0x720f10<br>
>>> > ><br>
>>> > > (/usr/local/google/home/dberris/xray/llvm-project-build-msan/unittests/XRay/XRayTests+0x720f10)<br>
>>> > ><br>
>>> > > SUMMARY: MemorySanitizer: use-of-uninitialized-value<br>
>>> > ><br>
>>> > > (/usr/local/google/home/dberris/xray/llvm-project-build-msan/unittests/XRay/XRayTests+0x70eef8)<br>
>>> > > Exiting<br>
>>> > ><br>
>>> > > ====<br>
>>> > ><br>
>>> > > Is there something else I'm missing here? I'm doing this on Linux. I<br>
>>> > > tried building with libc++ from the first toolchain, but somehow the<br>
>>> > > linker from the same toolchain in step 1 couldn't find the libc++<br>
>>> > > with<br>
>>> > > msan instrumentation.<br>
>>> > ><br>
>>> > > Here's the CMake command I'm using:<br>
>>> > ><br>
>>> > > ====<br>
>>> > > cmake -GNinja<br>
>>> > > -DCMAKE_C_COMPILER=$HOME/xray/llvm-project-build/bin/clang<br>
>>> > > -DCMAKE_CXX_COMPILER=$HOME/xray/llvm-project-build/bin/clang++<br>
>>> > > -DCMAKE_BUILD_TYPE=Debug -DLLVM_OPTIMIZED_TABLEGEN=On<br>
>>> > > -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_USE_SANITIZER=MemoryWithOrigins<br>
>>> > > -DLLVM_ENABLE_LLD=On -DLLVM_INCLUDE_TESTS=On<br>
>>> > > -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_LINK_FLAGS=-stdlib=libc++<br>
>>> > > ../llvm-project/llvm<br>
>>> > > ====<br>
>>> > ><br>
>>> > > And I'm running the tests like so:<br>
>>> > ><br>
>>> > > ====<br>
>>> > > ninja check-llvm<br>
>>> > > ====<br>
>>> > ><br>
>>> > > I'm doing this with the monorepo, if that's relevant.<br>
>>> > ><br>
>>> > > Help?<br>
>>> > ><br>
>>> > > --<br>
>>> > > Dean<br>
>>> > > _______________________________________________<br>
>>> > > LLVM Developers mailing list<br>
>>> > > <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
>>> > > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>>> > _______________________________________________<br>
>>> > LLVM Developers mailing list<br>
>>> > <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
>>> > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>>><br>
>>> -- Dean<br>
>>><br>
>>> _______________________________________________<br>
>>> LLVM Developers mailing list<br>
>>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>><br>
>><br>
>><br>
>> --<br>
>> -Brian<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>