<div dir="ltr">I totally support solving this problem, but please don't use dynamic initialization to do it. :) That's everyone's least favorite feature of libstdc++ iostream.<div><br></div><div>At least on Windows, we can solve this with #pragma detect_mismatch. <a href="https://msdn.microsoft.com/en-us/library/ee956429.aspx">https://msdn.microsoft.com/en-us/library/ee956429.aspx</a></div><div><br></div><div>On platforms without such a feature, I'd rather mangle NDEBUG into one of the core LLVM initialization routines than suffer the runtime and code size penalty of initializers.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 16, 2016 at 10:48 AM, Mehdi Amini 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi all,<div><br></div><div>An issue that come up from time to time and has cost hours for debug for many of us and users of LLVM is that an assert build isn’t ABI compatible with a release build.</div><div><br></div><div>The CMake flags that controls this behavior is LLVM_ABI_BREAKING_CHECKS (</div><div><br></div><div><dt style="font-family:'Lucida Grande','Lucida Sans Unicode',Geneva,Verdana,sans-serif;font-size:14px"><strong>LLVM_ABI_BREAKING_CHECKS</strong>:<wbr>STRING</dt><dd style="margin-top:3px;margin-bottom:10px;margin-left:30px;font-family:'Lucida Grande','Lucida Sans Unicode',Geneva,Verdana,sans-serif;font-size:14px">Used to decide if LLVM should be built with ABI breaking checks or not. Allowed values are <cite style="font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em">WITH_ASSERTS</cite> (default), <cite style="font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em">FO<wbr>RCE_ON</cite> and <cite style="font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em">FORCE_OFF</cite>.  <cite style="font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em">WITH_<wbr>ASSERTS</cite> turns on ABI breaking checks in an assertion enabled build.  <cite style="font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em">FORCE_ON</cite> (<cite style="font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em">FORCE_OFF</cite>) turns them on (off) irrespective of whether normal (<cite style="font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em">NDEBUG</cite>-based) assertions are enabled or not. A version of LLVM built with ABI breaking checks is not ABI compatible with a version built without it.</dd></div><div><br></div><div><br></div><div>I propose to add a runtime check to detect when we have incorrectly setup build.</div><div><br></div><div>The idea is that every translation unit that includes such header will get a weak definition of a symbol with an initializer calling the runtime check. The symbol name would be different if the ABI break is enabled or not.</div><div><br></div><div>The runtime check maintains two boolean to track if it there is in the image at least a translation unit for each value of this flag. If both flags are set the process is aborted.</div><div><br></div><div>The cost is *one* static initializer per DSO (or per image I believe).</div><div><br></div><div>A straw-man patch (likely not windows compatible because of weak) is:</div><div><br></div><div><div>diff --git a/llvm/include/llvm/Config/<wbr>llvm-config.h.cmake b/llvm/include/llvm/Config/<wbr>llvm-config.h.cmake</div><div>index 4121e865ea00..4274c942d3b6 100644</div><div>--- a/llvm/include/llvm/Config/<wbr>llvm-config.h.cmake</div><div>+++ b/llvm/include/llvm/Config/<wbr>llvm-config.h.cmake</div><div>@@ -80,4 +80,18 @@</div><div> /* LLVM version string */</div><div> #define LLVM_VERSION_STRING "${PACKAGE_VERSION}"</div><div> </div><div>+</div><div>+#ifdef __cplusplus</div><div>+namespace llvm {</div><div>+bool setABIBreakingChecks(bool Enabled);</div><div>+__attribute__((weak)) </div><div>+#if LLVM_ENABLE_ABI_BREAKING_<wbr>CHECKS</div><div>+bool</div><div>+ABICheckEnabled = setABIBreakingChecks(true);</div><div>+#else</div><div>+bool ABICheckDisabled = setABIBreakingChecks(true);</div><div>+#endif</div><div>+}</div><div>+#endif</div><div>+</div><div> #endif</div><div>diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp</div><div>index 7436a1fd38ee..151fcdcbfb27 100644</div><div>--- a/llvm/lib/Support/Error.cpp</div><div>+++ b/llvm/lib/Support/Error.cpp</div><div>@@ -112,3 +112,17 @@ void report_fatal_error(Error Err, bool GenCrashDiag) {</div><div> }</div><div> </div><div> }</div><div>+</div><div>+</div><div>+bool llvm::setABIBreakingChecks(<wbr>bool Enabled) {</div><div>+  static char abi_breaking_checks_enabled = 0;</div><div>+  static char abi_breaking_checks_disabled = 0;</div><div>+  if (Enabled)</div><div>+    abi_breaking_checks_enabled = 1;</div><div>+  else</div><div>+    abi_breaking_checks_disabled = 1;</div><div>+  if (abi_breaking_checks_enabled && abi_breaking_checks_disabled)</div><div>+    report_fatal_error("Error initializing LLVM: mixing translation units built"</div><div>+                       "with and without LLVM_ABI_BREAKING_CHECKS");</div><div>+  return true;</div><div>+}</div></div><div><br></div><div><br></div><div><br></div><div>— </div><span class="HOEnZb"><font color="#888888"><div>Mehdi</div><div><br></div></font></span></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">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/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>