<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 10, 2018 at 5:21 AM, James Y Knight <span dir="ltr"><<a href="mailto:jyknight@google.com" target="_blank">jyknight@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span class="gmail-"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 5, 2018 at 9:58 PM, Ryan Prichard via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>2. <b>Termination landing pads.</b><br></div><div><div><div><br></div><div>Clang sometimes uses a landing pad that calls <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">__clang_call_terminate to terminate the program</span>. GCC instead leaves a gap in the call site table, and the personality routine calls <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">std::</span>terminate. For the 4MB libQt5Core.so sample I'm looking at, I think it'd reduce the size of .text and .ARM.extab by maybe 7000 bytes (about 0.18%). (I see about 500 calls to __clang_call_terminate, and I estimate 14 bytes per call, assuming the call site table is using ULEB128 already.)</div><div><br></div><div>I tried to implement this in LLVM, but couldn't find a good way to represent the calls that must be omitted from the call site table.</div><div><br></div><div>Is there a reason LLVM doesn't handle this like GCC?</div><div><br></div><div>Examples:</div><div> - C++03: <a href="https://godbolt.org/g/7BYbdG" target="_blank">https://godbolt.org/g/7<wbr>BYbdG</a></div><div> - C++11: <a href="https://godbolt.org/g/bnHLvH" target="_blank">https://godbolt.org/g/b<wbr>nHLvH</a></div></div></div></div></blockquote><div></div></div></div><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div></span><div class="gmail_extra"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">See also my comment and Reid's reply here: </span><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><a href="http://lists.llvm.org/pipermail/llvm-dev/2017-February/109995.html" target="_blank">http://lists.llvm.org/<wbr>pipermail/llvm-dev/2017-<wbr>February/109995.html</a></div></div></div></blockquote><div><br></div><div>Reid Kleckner wrote:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">... I would say that we should just<br>pattern match away our calls to std::terminate in the backend and emit the<br>more compact tables, but that is actually a behavior change. It will cause<br>cleanups between the thrown exception and the noexcept function to stop<br>running.  ...</blockquote><div><br></div><div>It seems that some unwinders still run cleanups when the termination landing pad is omitted?</div><div><br></div><div>e.g. For this sample code, GCC emits an empty call site table for func3:</div><div><br></div><div><div>#include <stdio.h></div><div>struct A { ~A() { fprintf(stderr, "~A\n"); } };</div><div>void func1() { throw 0; }</div><div>void func2() { A a; func1(); }</div><div>void func3() noexcept { func2(); }</div><div>int main() { func3(); }</div></div><div><br></div><div>Compiling for either x86 or x86_64 Ubuntu, using g++ with libstdc++/libsupc++, the program still calls ~A. On the other hand, ~A isn't called if I build with g++ and libc++/libc++abi.</div><div><br></div><div>I think I'm not motivated enough to work on changing this LLVM behavior. The ULEB128 encoding change is more interesting to me. Right now, I think the biggest problem with that change is the existence of assemblers that can't cope with the GCC-style EH table assembly. This includes the current /usr/bin/as on macOS, which suffers from the LLVM runs-forever bug.</div><div><br></div><div>-Ryan</div><div><br></div></div></div></div>