<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 12, 2016, at 5:48 PM, Jon Slenk via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I'm trying to learn about LTO. I have a static variable that I try to give a non-compile-time-constant value to. With LTO turned off, the sprintf happens i.e. a breakpoint set on that line does get triggered. With LTO turned on (either Monolithic or Incremental), the code appears to be removed/elided/deleted/forgotten/dropped/lost/ignored and the breakpoint is never tripped. <br class=""><br class="">What can I do to make my code survive through LTO? The variable makes it through but the sprinf() line doesn't. Can I somehow tell LTO to not apply to this function or line of code or file of code? (In reality this is something I am trying to do via Xcode for iOS targets.)<div class=""><br class=""></div><div class="">thank you.<br class=""><div class=""><br class=""></div><div class=""><ol start="1" class="gmail-dp-j" style="box-sizing:border-box;padding:0px;border:none;font-size:12px;font-family:consolas,"courier new",courier,mono,serif;vertical-align:baseline;list-style-position:initial;color:rgb(92,92,92);margin:0px 0px 1px 45px"><li class="gmail-alt" style="box-sizing:border-box;border-top:none;border-right:none;border-bottom:none;border-left:3px solid rgb(255,255,255);font-style:inherit;font-size:1em;font-family:inherit;vertical-align:baseline;line-height:12pt;list-style:decimal-leading-zero outside;color:inherit;height:12pt;white-space:nowrap;margin:0px;padding:0px 3px 0px 10px"><span style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; vertical-align: baseline; background-color: inherit; font-size: 9pt;" class=""><span class="gmail-keyword" style="box-sizing:border-box;margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(0,102,153);font-stretch:normal;line-height:normal;background-color:inherit;font-size:9pt">static</span><span style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;background-color:inherit;font-size:9pt" class=""> </span><span class="gmail-keyword" style="box-sizing:border-box;margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(0,102,153);font-stretch:normal;line-height:normal;background-color:inherit;font-size:9pt">void</span><span style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;background-color:inherit;font-size:9pt" class=""> __attribute__((constructor))_initv1 () { </span></span></li><li class="gmail-" style="box-sizing:border-box;border-top:none;border-right:none;border-bottom:none;border-left:3px solid rgb(255,255,255);font-style:inherit;font-size:1em;font-family:inherit;vertical-align:baseline;line-height:12pt;list-style:decimal-leading-zero outside;background-color:rgb(248,248,248);height:12pt;white-space:nowrap;margin:0px;padding:0px 3px 0px 10px"><span style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; vertical-align: baseline; background-color: inherit; font-size: 9pt;" class=""> <span class="gmail-keyword" style="box-sizing:border-box;margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(0,102,153);font-stretch:normal;line-height:normal;background-color:inherit;font-size:9pt">static</span><span style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;background-color:inherit;font-size:9pt" class=""> </span><span class="gmail-keyword" style="box-sizing:border-box;margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(0,102,153);font-stretch:normal;line-height:normal;background-color:inherit;font-size:9pt">char</span><span style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;background-color:inherit;font-size:9pt" class=""> default_[] = </span><span class="gmail-string" style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;color:blue;background-color:inherit;font-size:9pt">"0000000000000000000000000000000000000000000000000000000000000000"</span><span style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;background-color:inherit;font-size:9pt" class="">; </span></span></li><li class="gmail-alt" style="box-sizing:border-box;border-top:none;border-right:none;border-bottom:none;border-left:3px solid rgb(255,255,255);font-style:inherit;font-size:1em;font-family:inherit;vertical-align:baseline;line-height:12pt;list-style:decimal-leading-zero outside;color:inherit;height:12pt;white-space:nowrap;margin:0px;padding:0px 3px 0px 10px"><span style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; vertical-align: baseline; background-color: inherit; font-size: 9pt;" class=""> sprintf( default_, <span class="gmail-string" style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;color:blue;background-color:inherit;font-size:9pt">"%lu"</span><span style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;background-color:inherit;font-size:9pt" class="">, (unsigned </span><span class="gmail-keyword" style="box-sizing:border-box;margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(0,102,153);font-stretch:normal;line-height:normal;background-color:inherit;font-size:9pt">long</span><span style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;background-color:inherit;font-size:9pt" class="">)</span><span class="gmail-number" style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;color:rgb(192,0,0);background-color:inherit;font-size:9pt">5</span><span style="box-sizing:border-box;margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;vertical-align:baseline;background-color:inherit;font-size:9pt" class=""> ); </span></span></li><li class="gmail-" style="box-sizing:border-box;border-top:none;border-right:none;border-bottom:none;border-left:3px solid rgb(255,255,255);font-style:inherit;font-size:1em;font-family:inherit;vertical-align:baseline;line-height:12pt;list-style:decimal-leading-zero outside;background-color:rgb(248,248,248);height:12pt;white-space:nowrap;margin:0px;padding:0px 3px 0px 10px"><span style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; vertical-align: baseline; background-color: inherit; font-size: 9pt;" class="">}</span></li></ol></div></div></div></div></blockquote><div><br class=""></div></div><br class=""><div class="">So:</div><div class=""><br class=""></div><div class="">1) I don’t see what prevents us from deleting this code, even without LTO? It is not doing anything observable.</div><div class=""><br class=""></div><div class="">2) I can’t reproduce: the code is not deleted by LTO on MacOS.</div><div class=""><br class=""></div><div class="">$ clang test.cpp -O3 -Wl,-save-temps -g -flto</div><div class="">$ lldb -- a.out<br class="">(lldb) target create "a.out"<br class="">Current executable set to 'a.out' (x86_64).<br class="">(lldb) b _initv1<br class="">Breakpoint 1: where = a.out`_initv1() + 4 at test.cpp:4, address = 0x0000000100000f64<br class="">(lldb) r<br class="">Process 15278 launched: '/private/tmp/a.out' (x86_64)<br class="">a.out was compiled with optimization - stepping may behave oddly; variables may not be available.<br class="">Process 15278 stopped<br class="">* thread #1: tid = 0xb82628, 0x0000000100000f64 a.out`_initv1() + 4 at test.cpp:4, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1<br class=""> frame #0: 0x0000000100000f64 a.out`_initv1() + 4 at test.cpp:4 [opt]<br class=""> 1 <span class="Apple-tab-span" style="white-space:pre"> </span>#include <stdio.h><br class=""> 2 <span class="Apple-tab-span" style="white-space:pre"> </span>static void __attribute__((constructor))_initv1 () { <br class=""> 3 <span class="Apple-tab-span" style="white-space:pre"> </span> static char default_[] = "0000000000000000000000000000000000000000000000000000000000000000"; <br class="">-> 4 <span class="Apple-tab-span" style="white-space:pre"> </span> sprintf( default_, "%lu", (unsigned long)5 ); <br class=""> 5 <span class="Apple-tab-span" style="white-space:pre"> </span>}<br class=""> 6 <span class="Apple-tab-span" style="white-space:pre"> </span>int main() {<br class=""> 7 <span class="Apple-tab-span" style="white-space:pre"> </span><br class="">(lldb) <br class=""><br class=""></div><div class="">— </div><div class="">Mehdi</div><div class=""><br class=""></div></body></html>