<div dir="ltr">I'm a little confused about how said aformentioned freestanding implementation would work. We (GWP-ASan + Scudo) can't depend on having libcxx (we actually <a href="https://reviews.llvm.org/D62048">explicitly disable</a> using of the c++ standard library for these libraries), and I don't know where we could have a shared implementation live (that could be used by both us and libcxx).<div><br></div><div>Would we have a spinlock implementation in libcxx and have that guarded by a macro definition before the include of <mutex>, and then keep a synchronised version in compiler-rt?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 20, 2019 at 10:10 AM Ben Craig <<a href="mailto:ben.craig@ni.com">ben.craig@ni.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div lang="EN-US">
<div class="gmail-m_-1501418984181503871WordSection1">
<p class="MsoNormal">Wouldn’t all the Scudo and sanitizer things count as part of the toolchain implementation though?  Having pieces of the toolchain use an alternative name seems pretty reasonable to me.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">If the goal is to have a freestanding std::mutex that is implemented as a spin lock, well, that’s different.  I could be convinced that’s a good thing to have, but I’m still a bit uneasy about it.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0in 0in 0in 4pt">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> <a href="mailto:jfbastien@apple.com" target="_blank">jfbastien@apple.com</a> <<a href="mailto:jfbastien@apple.com" target="_blank">jfbastien@apple.com</a>> <br>
<b>Sent:</b> Monday, May 20, 2019 11:27 AM<br>
<b>To:</b> Ben Craig <<a href="mailto:ben.craig@ni.com" target="_blank">ben.craig@ni.com</a>><br>
<b>Cc:</b> Olivier Giroux <<a href="mailto:OGiroux@nvidia.com" target="_blank">OGiroux@nvidia.com</a>>; Mitch Phillips <<a href="mailto:mitchphillips@outlook.com" target="_blank">mitchphillips@outlook.com</a>>; <a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a>; <a href="mailto:kostyak@google.com" target="_blank">kostyak@google.com</a><br>
<b>Subject:</b> [EXTERNAL] Re: [libcxx-dev] Is a compiler-rt shared spinlock implementation of any use to libcxx?<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I think what developers *use* should definitely be named std::mutex. We indeed want to consider how the ABI is exposed, that’s a good question for libc++ maintainers.<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><br>
<br>
<u></u><u></u></p>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<div>
<p class="MsoNormal">On May 20, 2019, at 6:23 AM, Ben Craig <<a href="mailto:ben.craig@ni.com" target="_blank">ben.craig@ni.com</a>> wrote:<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">I think it’s fine to give such a class the same interface as std::mutex, just please don’t actually name it std::mutex.  I would be pretty concerned about ABI compatibility in that situation, as well as subtle interactions with things like
 condition_variable::wait.  cxxabi::__mutex, or almost any other identifier would be fine.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0in 0in 0in 4pt">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<div>
<p class="MsoNormal"><b>From:</b><span class="gmail-m_-1501418984181503871apple-converted-space"> </span>libcxx-dev <<a href="mailto:libcxx-dev-bounces@lists.llvm.org" target="_blank">libcxx-dev-bounces@lists.llvm.org</a>><span class="gmail-m_-1501418984181503871apple-converted-space"> </span><b>On Behalf Of<span class="gmail-m_-1501418984181503871apple-converted-space"> </span></b>Olivier
 Giroux via libcxx-dev<br>
<b>Sent:</b><span class="gmail-m_-1501418984181503871apple-converted-space"> </span>Friday, May 17, 2019 7:55 PM<br>
<b>To:</b><span class="gmail-m_-1501418984181503871apple-converted-space"> </span>JF Bastien <<a href="mailto:jfbastien@apple.com" target="_blank">jfbastien@apple.com</a>>; Mitch Phillips <<a href="mailto:mitchphillips@outlook.com" target="_blank">mitchphillips@outlook.com</a>><br>
<b>Cc:</b><span class="gmail-m_-1501418984181503871apple-converted-space"> </span><a href="mailto:kostyak@google.com" target="_blank">kostyak@google.com</a>;
<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a><br>
<b>Subject:</b><span class="gmail-m_-1501418984181503871apple-converted-space"> </span>[EXTERNAL] Re: [libcxx-dev] Is a compiler-rt shared spinlock implementation of any use to libcxx?<u></u><u></u></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">That’s what makes the most sense to me, include <mutex> with a macro that freestanding would also use. Inside of that, I would have an implementation of standard mutex backed by atomics and the atomic_wait/atomic_notify_* functions, themselves
 configured with a macro to not rely on the OS in freestanding implementations.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Olivier<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<div>
<p class="MsoNormal"><b><span style="font-size:12pt">From:<span class="gmail-m_-1501418984181503871apple-converted-space"> </span></span></b><span style="font-size:12pt">libcxx-dev <<a href="mailto:libcxx-dev-bounces@lists.llvm.org" target="_blank"><span style="color:purple">libcxx-dev-bounces@lists.llvm.org</span></a>>
 on behalf of JF Bastien via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank"><span style="color:purple">libcxx-dev@lists.llvm.org</span></a>><br>
<b>Reply-To:<span class="gmail-m_-1501418984181503871apple-converted-space"> </span></b>JF Bastien <<a href="mailto:jfbastien@apple.com" target="_blank"><span style="color:purple">jfbastien@apple.com</span></a>><br>
<b>Date:<span class="gmail-m_-1501418984181503871apple-converted-space"> </span></b>Friday, May 17, 2019 at 4:40 PM<br>
<b>To:<span class="gmail-m_-1501418984181503871apple-converted-space"> </span></b>Mitch Phillips <<a href="mailto:mitchphillips@outlook.com" target="_blank"><span style="color:purple">mitchphillips@outlook.com</span></a>><br>
<b>Cc:<span class="gmail-m_-1501418984181503871apple-converted-space"> </span></b>"<a href="mailto:kostyak@google.com" target="_blank"><span style="color:purple">kostyak@google.com</span></a>" <<a href="mailto:kostyak@google.com" target="_blank"><span style="color:purple">kostyak@google.com</span></a>>, "<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank"><span style="color:purple">libcxx-dev@lists.llvm.org</span></a>"
 <<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank"><span style="color:purple">libcxx-dev@lists.llvm.org</span></a>><br>
<b>Subject:<span class="gmail-m_-1501418984181503871apple-converted-space"> </span></b>Re: [libcxx-dev] Is a compiler-rt shared spinlock implementation of any use to libcxx?</span><u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal">I think it makes sense for libc++ to have a version of mutex which has the same API as the standard one, but for “freestanding” platforms such as yours. A flavor which mostly just spins and yields as in your review.<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">I’m not sure how to best turn it on, though. Should it be controlled by a macro, and otherwise it just looks like you’re using <mutex>?<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"> <u></u><u></u></p>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<div>
<div>
<p class="MsoNormal">On May 17, 2019, at 1:49 PM, Mitch Phillips via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank"><span style="color:purple">libcxx-dev@lists.llvm.org</span></a>> wrote:<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">Hi all,<span class="gmail-m_-1501418984181503871apple-converted-space"> </span><u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">In a recent<span class="gmail-m_-1501418984181503871apple-converted-space"> </span><a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D61923-231503272&d=DwMGaQ&c=I_0YwoKy7z5LMTVdyO6YCiE2uzI1jjZZuIPelcSjixA&r=y8mub81SfUi-UCZRX0Vl1g&m=yw9dJtPZSvMNi00nrRSUlnN4NTQzKvXzHbd5w8ShH8A&s=uW10gtroz30NxGIUU3BvNH5efGnzv2tds3P49eY5ri4&e=" target="_blank"><span style="color:purple">discussion</span></a><span class="gmail-m_-1501418984181503871apple-converted-space"> </span>from
 the reviews of<span class="gmail-m_-1501418984181503871apple-converted-space"> </span><a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D60593&d=DwMGaQ&c=I_0YwoKy7z5LMTVdyO6YCiE2uzI1jjZZuIPelcSjixA&r=y8mub81SfUi-UCZRX0Vl1g&m=yw9dJtPZSvMNi00nrRSUlnN4NTQzKvXzHbd5w8ShH8A&s=rKVj5vHVGEsEZRjMkiN2X6e0bAfdTY7iVW0laX2AO8o&e=" target="_blank"><span style="color:purple">GWP-ASan</span></a>,
 it was mentioned that I should probably consult with cxx-dev to see whether they'd be interested in a common spinlock implementation.<u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">The problem is:<u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> - Scudo hardened allocator (compiler-rt/lib/scudo) requires its own spinlock as it can't use the C++ standard library due to Fuchsia requirements.<u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> - GWP-ASan (as it's packaged into Scudo) also requires a spinlock.<u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> - Compiler-rt sanitizer_common also can't use c++ stdlib, and has its own spinlock. We can't reuse the sanitizer_common spinlock for Scudo/GWP-ASan as it's currently tightly coupled into sanitizer_common, and Scudo+Fuchsia can't afford
 the code size overhead of pulling the entire sanitizer_common library.<u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">The plan was to basically write a small standalone spinlock implementation that can be used by all three of these requirements. Would libcxx benefit by us making this an llvm-common spinlock rather than compiler-rt-common? If so, are there
 any requirements that we need to be aware of?<u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Cheers,<u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Mitch.<u></u><u></u></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal">_______________________________________________<br>
libcxx-dev mailing list<br>
<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank"><span style="color:purple">libcxx-dev@lists.llvm.org</span></a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_libcxx-2Ddev&d=DwQGaQ&c=I_0YwoKy7z5LMTVdyO6YCiE2uzI1jjZZuIPelcSjixA&r=y8mub81SfUi-UCZRX0Vl1g&m=yw9dJtPZSvMNi00nrRSUlnN4NTQzKvXzHbd5w8ShH8A&s=SLhw06SYT_9fwfHOjm_nzQZ0LuPvmMe_b2gjd-VEFcc&e=" target="_blank"><span style="color:purple">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</span></a><u></u><u></u></p>
</div>
</div>
</blockquote>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
<div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="100%" align="center">
</div>
</div>
<div>
<div>
<p class="MsoNormal">This email message is for the sole use of the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact
 the sender by reply email and destroy all copies of the original message.<span class="gmail-m_-1501418984181503871apple-converted-space"> </span><u></u><u></u></p>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</div>

</blockquote></div>