<div dir="ltr">Hi milsegv,<div><br></div><div>The command line options look like this -x86-slh[suffix] and you pass them to clang with -mllvm -x86-slh[suffix]. <br><br>So for example: clang <file.cpp> -mllvm --x86-slh-ip</div><div><br></div><div>Here's an example using llc and the -x86-slh-lfence flag: <a href="https://github.com/llvm/llvm-project/blob/master/llvm/test/CodeGen/X86/speculative-load-hardening.ll#L3">https://github.com/llvm/llvm-project/blob/master/llvm/test/CodeGen/X86/speculative-load-hardening.ll#L3</a></div><div><br></div><div>If you look at <font face="monospace">llc -help-hidden</font>, that's another way to find all the SLH flags you can pass. (Use -mllvm before the flag if you are passing the flag to clang.)</div><div><br></div><div>Let's discuss this on the mailing list so future Google searches can find the info in the LLVM Dev List archives. :)</div><div><br></div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Zola Bridges</div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 29, 2020 at 3:11 AM milsegv <<a href="mailto:milsegv@protonmail.com">milsegv@protonmail.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>Hello !<br></div><div><br></div><div>I have checked the speculative-load-hardening source code, especially the file lib/Target/X86/X86SpeculativeLoadHardening.cpp . At the beginning of the file, I see that a bunch of parameters are registered from the command line, but I couldn't manage to make it work. I checked with 'clang --help-hidden', they don't appear in it. I tried something like '-mspeculative-load-hardening-ip' and '-mspeculative-load-hardening-args=-ip' but none of it worked, and I didn't find any documentation on how to send arguments to a pass (this page didn't told it <a href="http://llvm.org/docs/CommandLine.html" target="_blank">http://llvm.org/docs/CommandLine.html</a> ). <br></div><div>Do you know how to tell the speculative load hardening pass to trigger some command line arguments ?<br></div><div><br></div><div>Thanks for any answer,<br></div><div>milsegv<br></div><div>‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐<br></div><div> On Monday, April 27, 2020 5:14 PM, Zola Bridges <<a href="mailto:zbrid@google.com" target="_blank">zbrid@google.com</a>> wrote:<br></div><div> <br></div><blockquote type="cite"><div dir="ltr"><div>You're welcome! Take care,<br></div><div><div><br></div><div><div dir="ltr"><div dir="ltr">Zola Bridges<br></div></div></div><div><br></div></div></div><div><br></div><div class="gmail_quote"><div dir="ltr">On Mon, Apr 27, 2020 at 2:02 AM milsegv <<a href="mailto:milsegv@protonmail.com" target="_blank">milsegv@protonmail.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>Hello Zola,<br></div><div><br></div><div>Thanks a lot four your help and your time, <br></div><div>Have a nice day,<br></div><div><br></div><div>milsegv<br></div><div><br></div><div><br></div><div>‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐<br></div><div>On Friday, April 24, 2020 7:43 PM, Zola Bridges <<a href="mailto:zbrid@google.com" target="_blank">zbrid@google.com</a>> wrote:<br></div><div><br></div><blockquote type="cite"><div dir="ltr"><div>Hi milsegv,<br></div><div><br></div><div>Gotcha. Makes sense. <br></div><div><br></div><div>Another option would be to compare the assembly output of a program built with and without the SLH flag. Adding <span style="font-family:monospace">-S</span> to your build command will output the assembly.<br></div><div><br></div><div>A few other Spectre gadget detectors I've seen are: <br></div><div><ul><li>Red Hat Spectre v1 Scanning tool: <a href="https://access.redhat.com/blogs/766093/posts/3510331" target="_blank">https://access.redhat.com/blogs/766093/posts/3510331</a><br></li><li>SMatch: <a href="https://lwn.net/Articles/752408/" target="_blank">https://lwn.net/Articles/752408/</a><br></li></ul></div><div>In case you haven't come across them yet.<br></div><div><br></div><div>Good luck on your search! Feel free to ask any additional questions.<br></div><div><div><br></div><div><div dir="ltr"><div dir="ltr">Zola Bridges<br></div></div></div><div><br></div></div></div><div><br></div><div class="gmail_quote"><div dir="ltr">On Fri, Apr 24, 2020 at 5:45 AM Robinson, Paul <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.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><p>For reporting from the backend, the “optimization remarks” feature might be what you are looking for. I have not used it myself so I should not provide details, but it is enabled from the clang command line with the `-R` option I believe.<u></u><br></p><p>--paulr<u></u><br></p><p><u></u> <u></u><br></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><br></p><div><b>From:</b> cfe-dev <<a href="mailto:cfe-dev-bounces@lists.llvm.org" target="_blank">cfe-dev-bounces@lists.llvm.org</a>> <b>On Behalf Of </b>Zola Bridges via cfe-dev<br></div><div><b>Sent:</b> Thursday, April 23, 2020 4:43 PM<br></div><div><b>To:</b> Praveen Velliengiri <<a href="mailto:praveenvelliengiri@gmail.com" target="_blank">praveenvelliengiri@gmail.com</a>><br></div><div><b>Cc:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>; <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>; milsegv <<a href="mailto:milsegv@protonmail.com" target="_blank">milsegv@protonmail.com</a>><br></div><div><b>Subject:</b> Re: [cfe-dev] More verbose -mspeculative-load-hardening<u></u><br></div><p><br></p></div></div><p><u></u> <u></u><br></p><div><p>Another thing to consider about your feature idea is that the output may be noisy depending on what you were hoping for.<u></u><br></p><div><p><u></u> <u></u><br></p></div><div><p>SLH tries to mitigate anything that could potentially be a problem and thus it instruments almost every branch, load, and function entry, for example. There isn't a lot of signal about what is really a gadget among the code instrumented
by SLH. It really tries to be comprehensive and to avoid missing anything even when that means protecting things that can't realistically be used for a Spectre v1 gadget.<u></u><br></p><div><p><u></u><br></p><div><div><div><p>Zola Bridges<u></u><br></p></div></div></div><p><u></u> <u></u><br></p></div></div></div><p><u></u> <u></u><br></p><div><div><p>On Thu, Apr 23, 2020 at 12:59 PM Zola Bridges <<a href="mailto:zbrid@google.com" target="_blank">zbrid@google.com</a>> wrote:<u></u><br></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in"><div><p>Hi milsegv,<u></u><br></p><div><p><u></u> <u></u><br></p></div><div><p>I work on SLH. I haven't thought about the feature you'd like to see. It sounds pretty interesting. What would you like to use it for? Are you trying to learn more about how SLH works or are you hoping to use this feature for your project?
I'm also interested in what you're working on for Spectre v1 detection if you'd like to share!<u></u><br></p></div><div><p><u></u> <u></u><br></p></div><div><p>I'm not sure how to go from the Machine IR that the SLH pass works on to the original C++ source code, so I can't give you advice on implementing that in LLVM. Hopefully someone else can chime in who understands the LLVM stack better than
me.<u></u><br></p></div><div><p><u></u> <u></u><br></p></div><div><p><b>If you'd like to get a better understanding of how SLH works:</b><u></u><br></p><div><p><u></u> <u></u><br></p></div><div><p><br></p><div>Have you looked into using the LLVM_DEBUG macro? You can use it to print where you want from the SLH pass.<br></div><div>Check it out here: <a href="https://urldefense.com/v3/__https:/llvm.org/docs/ProgrammersManual.html*the-llvm-debug-macro-and-debug-option__;Iw!!JmoZiZGBv3RvKRSx!tbubacyoXA98g75-qd_gdiwivwPZQbA83yxyhEEPEmkXk00FiBjyCrq4FRJAuCEjMw$" target="_blank">https://llvm.org/docs/ProgrammersManual.html#the-llvm-debug-macro-and-debug-option</a> You'll
have to add it where you want to see what SLH is doing in the X86SpeculativeLoadHardening.cpp file and rebuild from source to get the new error messages.<u></u><br></div><p><br></p></div><div><p><u></u> <u></u><br></p></div><div><p>Another useful thing for you might be to pass either of these to clang when you enable -mspeculative-load-hardening<u></u><br></p></div><div><ul type="disc"><li>-mllvm -print-after-all<u></u><br></li><li>-mllvm -print-after="x86-slh"<u></u><br></li></ul></div><div><p>This will let you look at the code before and after the SLH transformations.<u></u><br></p></div><div><p><u></u> <u></u><br></p></div><div><p><b>If you want to implement this new feature that you want to build on:</b><u></u><br></p></div><div><p><u></u> <u></u><br></p></div><div><p>One thing about your question to print where SLH applies the mitigation. I'd say the mitigation has multiple parts and it may be easier to understand your problem if you get more granular about what you mean. Do you want to know which loads
in the C++ source get hardened? Or which conditions had instrumentation added? There are the instruction sequences that are added to track the predicate state and there are the instruction sequences that are added to mask data dependent loads and probably
other parts that I can't think of off the top of my head. To figure out what you want to print it might be helpful to read this design doc if you haven't seen it: <a href="https://urldefense.com/v3/__https:/llvm.org/docs/SpeculativeLoadHardening.html__;!!JmoZiZGBv3RvKRSx!tbubacyoXA98g75-qd_gdiwivwPZQbA83yxyhEEPEmkXk00FiBjyCrq4FRIIf6umiA$" target="_blank">https://llvm.org/docs/SpeculativeLoadHardening.html</a>.<u></u><br></p></div><div><p><u></u> <u></u><br></p></div><div><div><div><div><p>Zola Bridges<u></u><br></p></div></div></div><p><u></u> <u></u><br></p></div></div></div><p><u></u> <u></u><br></p><div><div><p>On Wed, Apr 22, 2020 at 9:52 AM Praveen Velliengiri via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<u></u><br></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in"><div><p>Hi<u></u><br></p><div><p>I think llvm-dev list (CC'ed) have more visibility in this.<u></u><br></p></div></div><p><u></u> <u></u><br></p><div><div><p>On Wed, 22 Apr 2020 at 22:18, milsegv via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<u></u><br></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in"><div><p>Hello everyone,<u></u><br></p></div><div><p><u></u> <u></u><br></p></div><div><p>It may not be the best place to ask this but I found nothing on the internet about it. <u></u><br></p></div><div><p>I'm working on Spectre V1 detection and stumbled upon the mitigation provided by clang, the "-mspeculative-load-hardening" option. I found it really interesting, and my question is the following: is there a way to tweak the compiler to
print a message whenever it applies the mitigation, telling the user at which line of its code it applied the patch ?<u></u><br></p></div><div><p>I have no idea of the difficulty of such a feature, but I'm ready to learn how to do it myself if anybody has time to tell me how to !<u></u><br></p></div><div><p><u></u> <u></u><br></p></div><div><p>Thanks for any help,<u></u><br></p></div><div><p>milsegv<u></u><br></p></div><p><br></p><div>_______________________________________________<br></div><div>cfe-dev mailing list<br></div><div><a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br></div><div><a href="https://urldefense.com/v3/__https:/lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev__;!!JmoZiZGBv3RvKRSx!tbubacyoXA98g75-qd_gdiwivwPZQbA83yxyhEEPEmkXk00FiBjyCrq4FRI9sjCFiA$" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><u></u><br></div><p><br></p></blockquote></div><p><br></p><div>_______________________________________________<br></div><div>cfe-dev mailing list<br></div><div><a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br></div><div><a href="https://urldefense.com/v3/__https:/lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev__;!!JmoZiZGBv3RvKRSx!tbubacyoXA98g75-qd_gdiwivwPZQbA83yxyhEEPEmkXk00FiBjyCrq4FRI9sjCFiA$" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><u></u><br></div><p><br></p></blockquote></div></blockquote></div></div></div></div></blockquote></div></blockquote><div><br></div></blockquote></div></blockquote><div><br></div></blockquote></div>