<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="">Hi all,<div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">The CMake flags that controls this behavior is LLVM_ABI_BREAKING_CHECKS (</div><div class=""><br class=""></div><div class=""><dt style="font-family: 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; font-size: 14px;" class=""><strong class="">LLVM_ABI_BREAKING_CHECKS</strong>:STRING</dt><dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; -webkit-hyphens: auto; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; font-size: 14px;" class="">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;" class="">WITH_ASSERTS</cite> (default), <cite style="font-family: Consolas, 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; font-size: 0.95em;" class="">FORCE_ON</cite> and <cite style="font-family: Consolas, 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; font-size: 0.95em;" class="">FORCE_OFF</cite>. <cite style="font-family: Consolas, 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; font-size: 0.95em;" class="">WITH_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;" class="">FORCE_ON</cite> (<cite style="font-family: Consolas, 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; font-size: 0.95em;" class="">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;" class="">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 class=""><br class=""></div><div class=""><br class=""></div><div class="">I propose to add a runtime check to detect when we have incorrectly setup build.</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">The cost is *one* static initializer per DSO (or per image I believe).</div><div class=""><br class=""></div><div class="">A straw-man patch (likely not windows compatible because of weak) is:</div><div class=""><br class=""></div><div class=""><div class="">diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake</div><div class="">index 4121e865ea00..4274c942d3b6 100644</div><div class="">--- a/llvm/include/llvm/Config/llvm-config.h.cmake</div><div class="">+++ b/llvm/include/llvm/Config/llvm-config.h.cmake</div><div class="">@@ -80,4 +80,18 @@</div><div class=""> /* LLVM version string */</div><div class=""> #define LLVM_VERSION_STRING "${PACKAGE_VERSION}"</div><div class=""> </div><div class="">+</div><div class="">+#ifdef __cplusplus</div><div class="">+namespace llvm {</div><div class="">+bool setABIBreakingChecks(bool Enabled);</div><div class="">+__attribute__((weak)) </div><div class="">+#if LLVM_ENABLE_ABI_BREAKING_CHECKS</div><div class="">+bool</div><div class="">+ABICheckEnabled = setABIBreakingChecks(true);</div><div class="">+#else</div><div class="">+bool ABICheckDisabled = setABIBreakingChecks(true);</div><div class="">+#endif</div><div class="">+}</div><div class="">+#endif</div><div class="">+</div><div class=""> #endif</div><div class="">diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp</div><div class="">index 7436a1fd38ee..151fcdcbfb27 100644</div><div class="">--- a/llvm/lib/Support/Error.cpp</div><div class="">+++ b/llvm/lib/Support/Error.cpp</div><div class="">@@ -112,3 +112,17 @@ void report_fatal_error(Error Err, bool GenCrashDiag) {</div><div class=""> }</div><div class=""> </div><div class=""> }</div><div class="">+</div><div class="">+</div><div class="">+bool llvm::setABIBreakingChecks(bool Enabled) {</div><div class="">+ static char abi_breaking_checks_enabled = 0;</div><div class="">+ static char abi_breaking_checks_disabled = 0;</div><div class="">+ if (Enabled)</div><div class="">+ abi_breaking_checks_enabled = 1;</div><div class="">+ else</div><div class="">+ abi_breaking_checks_disabled = 1;</div><div class="">+ if (abi_breaking_checks_enabled && abi_breaking_checks_disabled)</div><div class="">+ report_fatal_error("Error initializing LLVM: mixing translation units built"</div><div class="">+ "with and without LLVM_ABI_BREAKING_CHECKS");</div><div class="">+ return true;</div><div class="">+}</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">— </div><div class="">Mehdi</div><div class=""><br class=""></div></body></html>