<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 Nov 2, 2015, at 9:42 AM, Justin Bogner <<a href="mailto:mail@justinbogner.com" class="">mail@justinbogner.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Chris Bieneman via llvm-dev <</span><a href="mailto:llvm-dev@lists.llvm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">llvm-dev@lists.llvm.org</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> writes:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">In the effort to flesh out the CMake build system a problematic issue<br class="">has come up, and I’d like some feedback on how to best handle it.<br class=""><br class="">For reference this issue has been reported by a few users, one<br class="">proposed patches that don’t really address the underlying problem<br class="">here:<br class=""><a href="http://reviews.llvm.org/D13131" class="">http://reviews.llvm.org/D13131</a><br class=""><br class="">The problem comes when bootstrapping a cross-compiler toolchain. In<br class="">order to have a cross-compiling toolchain that can build a “hello<br class="">world” application you need four basic components:<br class=""><br class="">(1) clang<br class="">(2) ld<br class="">(3) libclang_rt (builtins)<br class="">(4) runtime libraries<br class=""><br class="">Today building this toolchain with CMake is impossible because you<br class="">cannot configure the cross-compiled builtins. The failure is a result<br class="">of CMake’s try_compile function always testing a full compile then<br class="">link operation. When bootstrapping a cross-compiler this will always<br class="">fail because linking even the simplest applications fails when you<br class="">don’t have libclang_rt prebuilt.<br class=""><br class="">So, how do we fix this? I have a couple ideas, and am open to more.<br class=""><br class="">(1) Roll our own CMake checks<br class=""><br class="">We could roll our own replacement to try_compile and the various check<br class="">macros that we need. In my opinion this is probably the right<br class="">solution, but it does have downsides.<br class=""><br class="">The big downside is that when bootstrapping compiler-rt it will need<br class="">to build differently. In particular, it is probable that a bootstrap<br class="">build of compiler-rt will not be able to perform the necessary checks<br class="">to build the runtimes, so when bootstrapping we’ll need to disable<br class="">building all the runtime libraries. We can probably find clever ways<br class="">to hide a bunch of the complexity here, but it is not going to be<br class="">clean.<br class=""><br class="">(2) Provide a way to bootstrap the builtins without CMake<br class=""><br class="">Another alternative would be to provide a way to bootstrap the builtin<br class="">libraries without CMake. The builtin libraries are actually very<br class="">simple to compile. It is possible to roll a custom build script for<br class="">use only bootstrapping the builtins that could run on any platform and<br class="">just get to a functional compiler. The biggest downside here is that<br class="">bootstrapping on all supported platforms with all supported compilers<br class="">is actually a non-trivial matrix, and supporting and maintaining that<br class="">could be a real pain. This is my least favorite option.<br class=""><br class="">(3) Split the builtins and the runtime libraries<br class=""><br class="">This is the most complicated approach, but I also think it is the best<br class="">approach. One of the underlying problems here is that the builtin<br class="">libraries and the runtime libraries have very different requirements<br class="">for building. The builtins really only require a functional compiler<br class="">and archiver, and the runtime libraries require a full linker +<br class="">runtime libraries (libc & libcxx). These additional build-time<br class="">requirements actually make things very complicated because when<br class="">bootstrapping a cross toolchain compiler-rt needs to build in two<br class="">different places in the build order; once before libcxx, and once<br class="">after.<br class=""><br class="">I believe that the cleanest solution to this problem is going to be to<br class="">separate the builtins and the sanitizers.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">To be clear, you mean split the builtins (as in lib/builtins) and all of</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">the runtime libraries (as in everything else under lib: sanitizers,</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">profiling runtimes, etc). Correct?</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>Yes. lib/builtins is the part that causes all the problems.</div><div><br class=""></div><div>-Chris</div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Doing this and rolling our own CMake checks would allow us to have a<br class="">fully CMake solution for building a cross-targeting toolchain. We<br class="">might even be able to get support for try_compile checks that don’t<br class="">link from CMake which would allow us to get rid of the hand-rolled<br class="">checks in the future (I have already started a thread on the<br class="">cmake-developers list).<br class=""><br class="">Logistically this solution could take many forms. We could break<br class="">compiler-rt out into two repositories, which would be a huge<br class="">undertaking, or we could leave it as a single repository and have the<br class="">builtins be able to build as a sub-project. I think we can make it<br class="">work such that compiler-rt can be built either from the top-level<br class="">directory to build it all, or from the builtins sub directory to<br class="">support bootstrapping cross-compilers.<br class=""><br class="">Either way, supporting this approach will require significant cleanup<br class="">and refactoring because we’ll need to separate out the build system<br class="">functionality into three categories: things that apply to builtins,<br class="">things that apply to runtimes, things that apply to both. That<br class="">separation will need to be somewhat clearly maintained so that we can<br class="">prevent inadvertent stream crossing, because that is almost always<br class="">bad.<br class=""><br class="">Thoughts? Additional suggestions?<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">ISTM that (3) essentially includes the work from (1), but ends up in a</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">more maintainable state. (3) feels like the right approach to me, as (1)</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">will be error prone and hard to maintain, and (2) is kludgy and complex</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">in a way that could scare people away from contributing.</span></div></blockquote></div><br class=""></body></html>