<div dir="ltr"><a class="gmail_plusreply" id="plusReplyChip-3" href="mailto:eugenis@google.com" tabindex="-1">+Evgeniy Stepanov</a> <a class="gmail_plusreply" id="plusReplyChip-4" href="mailto:vitalybuka@google.com" tabindex="-1">+Vitaly Buka</a> <br><div><br></div><div>Hi Igor, </div><div>yes, please send the patches for the clang driver and compiler-rt.</div><div>It might require some refactoring to get minimal ubsan-rt working with asan. </div><div><br></div><div>As for vptr UBSAN: I guess that vptr checking does actually require very non-trivial run-time support and is not included into the minimal one.  </div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Oct 21, 2018 at 11:46 AM Igor Sugak via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">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">




<div dir="ltr">
<div id="m_1899074660806550434divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Hello, </p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">In my organization, we've been using ASAN and most of UBSAN checks in the default developers mode with a big success. I'd like to enable a few remaining UBSAN checks too but noticed that they cause significant (up to
 2x in some cases) binary size overhead (mostly .rodata and .data). These checks are: null, function, vptr, object-size.  </p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Inspecting .rodata, it looks like there are a lot of strings with file and type names. <span style="font-size:12pt">I tried to use `<span>-fsanitize-undefined-strip-path-components=-1` from [1]. It appeared to have
 no effect when `-fsanitize=function` and `-fsanitize=address` are used at the same time (filed bug [2]). Disabling `-fsanitize=function` and using  <span style="font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">`</span><span style="font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">-fsanitize-undefined-strip-path-components=-1`
 reduces the size overhead to 1.4x. </span></span></span>This is quite already significant.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">I've considered -fsanitize=trap, it causes very little size overhead but it in some cases is hard to work with. </p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">I noticed that [3] added minimal runtime for UBSAN. It works similar to `<span>-fsanitize-trap`, but prints a bit more informative message, which would suffice. Out of the box, I didn't notice a measurable binary size
 reduction as mentioned on that change, but if used with `<span>-fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--print-gc-sections`, the size bloat of .rodata and .data is almost eliminated. Note, in this case, those flags don't help without `-<span>fsanitize-minimal-runtime`.</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span><span><span><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span><span><span>Unfortunately, there is a restriction in the driver preventing this minimal UBSAN runtime to be used when ASAN is also enabled. I don't completely understand the reasons for having this restriction.
 When I removed that restriction, both ASAN and UBSAN still seem functioning in my tests. </span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span><span><span><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span><span><span>I'd like to allow using minimal UBSAN runtime with ASAN. Are there reasons against it? I'd volunteer to do the work here.</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span><span><span><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span><span><span>Also, v<span>ptr UBSAN check is disallowed when minimal UBSAN runtime is used. Would someone clarify why?</span></span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span><span><span><span><br>
</span></span></span></span></p>
<p style="margin-top:0;margin-bottom:0">-- Igor</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"></p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"></p>
<ol style="margin-bottom:0px;margin-top:0px">
<li><a href="https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#additional-configuration" class="m_1899074660806550434OWAAutoLink" id="m_1899074660806550434LPlnk224361" target="_blank">https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#additional-configuration</a></li><li><span style="font-size:12pt"></span><a href="https://bugs.llvm.org/show_bug.cgi?id=39347" class="m_1899074660806550434OWAAutoLink" id="m_1899074660806550434LPlnk663307" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=39347</a></li><li><a href="https://reviews.llvm.org/D36810" class="m_1899074660806550434OWAAutoLink" id="m_1899074660806550434LPlnk471537" target="_blank">https://reviews.llvm.org/D36810</a>
<div id="m_1899074660806550434LPBorder_GT_15399093196730.2558932204692528" style="margin-bottom:20px;overflow:auto;width:100%;text-indent:0px">
<table id="m_1899074660806550434LPContainer_15399093196720.2638047386862139" cellspacing="0" style="width:90%;background-color:rgb(255,255,255);overflow:auto;padding-top:20px;padding-bottom:20px;margin-top:20px;border-top:1px dotted rgb(200,200,200);border-bottom:1px dotted rgb(200,200,200)">
<tbody>
<tr valign="top" style="border-spacing:0px">
<td id="m_1899074660806550434TextCell_15399093196720.6118055161042004" colspan="2" style="vertical-align:top;padding:0px;display:table-cell">
<div id="m_1899074660806550434LPRemovePreviewContainer_15399093196720.4167337012904666"></div>
<div id="m_1899074660806550434LPTitle_15399093196720.6843494300108914" style="color:rgb(93,178,255);font-weight:400;font-size:21px;font-family:wf_segoe-ui_light,"Segoe UI Light","Segoe WP Light","Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;line-height:21px">
<a id="m_1899074660806550434LPUrlAnchor_15399093196720.8406941018844281" href="https://reviews.llvm.org/D36810" style="text-decoration:none" target="_blank">D36810 Minimal runtime for UBSan. - LLVM</a></div>
<div id="m_1899074660806550434LPMetadata_15399093196720.14031362546793513" style="margin:10px 0px 16px;color:rgb(102,102,102);font-weight:400;font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;font-size:14px;line-height:14px">
<a href="http://reviews.llvm.org" target="_blank">reviews.llvm.org</a></div>
<div id="m_1899074660806550434LPDescription_15399093196730.44365991749594613" style="display:block;color:rgb(102,102,102);font-weight:400;font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;font-size:14px;line-height:20px;max-height:100px;overflow:hidden">
Not worried about that. If it allocates or prints too much, we can add in a custom allocator or printing strategy. If it requires too much metadata to be inserted into user programs, we can devise a new, smaller encoding for the metadata.</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
<br>
</li></ol>
<p></p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><a href="https://reviews.llvm.org/D36810" class="m_1899074660806550434OWAAutoLink" id="m_1899074660806550434LPlnk510871" target="_blank">https://reviews.llvm.org/D36810</a></p>
<div id="m_1899074660806550434LPBorder_GT_15399077390180.4556167263663371" style="margin-bottom:20px;overflow:auto;width:100%;text-indent:0px">
<table id="m_1899074660806550434LPContainer_15399077390150.3628391387566361" cellspacing="0" style="width:90%;background-color:rgb(255,255,255);overflow:auto;padding-top:20px;padding-bottom:20px;margin-top:20px;border-top:1px dotted rgb(200,200,200);border-bottom:1px dotted rgb(200,200,200)">
<tbody>
<tr valign="top" style="border-spacing:0px">
<td id="m_1899074660806550434TextCell_15399077390170.9356204513907331" colspan="2" style="vertical-align:top;padding:0px;display:table-cell">
<div id="m_1899074660806550434LPRemovePreviewContainer_15399077390170.15590685974231056"><a id="m_1899074660806550434LPlnk536017" class="m_1899074660806550434ms-Icon--x m_1899074660806550434ms-icon-font-size-14 m_1899074660806550434OWAAutoLink" style="font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;font-weight:normal;padding:8px;float:right;color:rgb(102,102,102);background-color:rgb(238,247,255);margin-left:10px"></a></div>
<div id="m_1899074660806550434LPTitle_15399077390170.8512445827367043" style="color:rgb(93,178,255);font-weight:400;font-size:21px;font-family:wf_segoe-ui_light,"Segoe UI Light","Segoe WP Light","Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;line-height:21px">
<a id="m_1899074660806550434LPUrlAnchor_15399077390170.8827673418982735" href="https://reviews.llvm.org/D36810" style="text-decoration:none" target="_blank">D36810 Minimal runtime for UBSan. - LLVM</a></div>
<div id="m_1899074660806550434LPMetadata_15399077390170.34360392979186627" style="margin:10px 0px 16px;color:rgb(102,102,102);font-weight:400;font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;font-size:14px;line-height:14px">
<a href="http://reviews.llvm.org" target="_blank">reviews.llvm.org</a></div>
<div id="m_1899074660806550434LPDescription_15399077390180.6919949750220125" style="display:block;color:rgb(102,102,102);font-weight:400;font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;font-size:14px;line-height:20px;max-height:100px;overflow:hidden">
Not worried about that. If it allocates or prints too much, we can add in a custom allocator or printing strategy. If it requires too much metadata to be inserted into user programs, we can devise a new, smaller encoding for the metadata.</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
<p></p>
</div>
</div>

_______________________________________________<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>