<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 Jun 1, 2015, at 7:47 PM, Chris Bieneman <<a href="mailto:beanz@apple.com" class="">beanz@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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" class=""><div class=""><br class="Apple-interchange-newline">On Jun 1, 2015, at 6:26 PM, Jonathan Roelofs <<a href="mailto:jonathan@codesourcery.com" class="">jonathan@codesourcery.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class=""><br class="">On 6/1/15 6:42 PM, Chris Bieneman wrote:<br class=""><blockquote type="cite" class="">Looping in cfe-dev because I should have send this there too from the<br class="">start.<br class=""><br class="">-Chris<br class=""><br class=""><blockquote type="cite" class="">On Jun 1, 2015, at 3:21 PM, Chris Bieneman <<a href="mailto:beanz@apple.com" class="">beanz@apple.com</a>><br class="">wrote:<br class=""><br class="">LLVMDev,<br class=""><br class="">PR 15732 is the umbrella tracking the progress of making the CMake<br class="">build system feature equivalent to the autotools one. One of the<br class="">biggest outstanding tasks is PR 21562, which I've been viewing more<br class="">as a "We really need to fix how we build Compiler-RT."<br class=""></blockquote></blockquote><br class="">+1<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><br class="">I've thought about this quite a bit, and I wanted to send out some<br class="">of my ideas to get some feedback and have some discussions about<br class="">the way forward.<br class=""><br class="">The complication with Compiler-RT is that it is inherently a<br class="">cross-compile. When you build LLVM, Clang and Compiler-RT, you<br class="">really want to build LLVM, Clang, and n Compiler-RTs where n is the<br class="">valid combinations of target architectures and/or platforms your<br class="">clang supports.<br class=""><br class="">There are three basic configurations for building Compiler-RT.<br class=""><br class="">(1) Building a "pure" Clang supporting targeting your host (2)<br class="">Building a cross-targeting Clang that runs on one OS or<br class="">architecture and targets another (3) Building a Clang that both<br class="">self-targets and cross-targets<br class=""><br class="">The overall change I want to make to Compiler-RT is that I want to<br class="">handle case 1 as an in-tree build similar to how it is today, case<br class="">2 as a cross-compile, and case 3 as a combination of cases 1 & 2.<br class=""></blockquote></blockquote><br class="">Why treat $host as a special case? IM-not-so-humble-O, $host is just another $target.<br class=""></div></blockquote><div class=""><br class=""></div><div class="">Conceptually I agree, but treating host differently here is a build-time optimization. Treating it as a cross-compile bears CMake-induced build time overhead, which can be avoided in the simple case.</div></div></div></blockquote><div><br class=""></div><div>Interesting. Maybe start by treating everything as cross compile and then come back to optimizing for $host==$target later if it’s worthwhile?</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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=""><br class=""><blockquote type="cite" class=""><div class=""><br class="">I think the ideal case is to have a table of:<br class=""><br class=""> (triple, compiler, flags, sysroot)<br class=""><br class="">tuples that say which configurations of the library to build.<br class=""></div></blockquote><div class=""><br class=""></div><div class="">Basing this off tuples is fine. I don’t think you want a table of (triple, compiler, flags, sysroot) though. I think you want a mapping of tuple->toolchain, and the toolchain file defines compiler, flags and sysroot. Using the CMAKE_TOOLCHAIN_FILE mechanism makes leveraging CMake’s cross targeting support easier. We also really don’t want a 1:1 mapping of triples to toolchains because that would be too much redundancy. We should define flavors of toolchains. For example, the iOS toolchain that exists in LLVM today could be generalized to a Darwin toolchain with minimal changes.</div><br class=""><blockquote type="cite" class=""><div class=""><br class="">If Clang is compiler-rt's compiler, then all of the compiler entries in that table can point to the same binary. For in-tree builds, we *should* be using the "just built" Clang anyway (but are not currently, without enabling the flag to do so). Either way, I think we ought to move away from thinking that a native build is in some way "special".<br class=""><br class="">If GCC is compiler-rt's compiler, then there would have to have a different binary per triple.<br class=""><br class="">If we drop support for building compiler-rt with GCC, this gets even simpler. Compiler-rt is *Clang's* runtime library, after all.<br class=""></div></blockquote><div class=""><br class=""></div><div class="">I don’t know if it is on the table to drop supporting compiler-rt with GCC, but that would dramatically simplify things.</div></div></div></blockquote><div><br class=""></div><div>Start a thread about that question specifically and see? Nothing ventured… :)</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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=""><br class=""><blockquote type="cite" class=""><div class=""><br class="">The plus side of treating *every* build as a cross build is that then there will be less risk of builds differing between native builds and cross builds when the target is the same (for example, linux targeting linux vs darwin targeting linux).<br class=""></div></blockquote><div class=""><br class=""></div><div class="">I think there are other things we can do to mitigate risk in this regard. I’m not opposed to making all compiler-rt builds cross-builds, but it does carry some downsides.</div><br class=""><blockquote type="cite" class=""><div class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><br class="">Let me walk through an example of how I think this should work.<br class=""><br class="">If my host is OS X and I'm building Clang to target OS X and iOS,<br class="">when I configure my build directory there will be an in-tree build<br class="">of Compiler-RT (via add_llvm_external_project) to generate the OS X<br class="">runtime libraries, and an out-of-tree-style cross-compile generated<br class="">for building the iOS runtime libraries for all supported<br class="">architectures. This would all be driven via command line settings<br class="">like:<br class=""><br class="">LLVM_COMPILER_RT_IOS_ARCHS="armv7;armv7s;arm64"<br class="">LLVM_COMPILER_RT_OSX_ARCHS="x86;x86_64"<br class=""><br class="">This would generate universal binary outputs in the format:<br class="">libclangrt_<lib>.<os>.<ext><br class=""><br class="">As a second example, if you were on Windows building a Clang to<br class="">target only FreeBSD when you configured your build directory there<br class="">would only be an out-of-tree-style cross-compile generated for your<br class="">target architecture against FreeBSD. The command line setting here<br class="">would be:<br class=""><br class="">LLVM_COMPILER_RT_FREEBSD_ARCHS="x86;x86_64"<br class=""><br class="">This would generate binary outputs in the format:<br class="">libclangrt_<lib>.<arch>.<ext><br class=""><br class="">Similarly if you were on linux targeting linux you’d only get an<br class="">in-tree build with outputs: libclangrt_<lib>.<arch>.<ext><br class=""><br class="">The cross-compile builds will be driven via CMake's toolchain file<br class="">settings, so if you were cross-targeting and need to set compiler<br class="">options like -isysroot there will need to be a toolchain file<br class="">defined for your target platform.<br class=""><br class="">Using toolchain files and cross-compile configurations solves one<br class="">of the problems with our current CMake system where the Compiler-RT<br class="">builds don't re-run the CMake checks. Not re-running the CMake<br class="">checks causes significant problems if your host and target OS are<br class="">different.<br class=""></blockquote></blockquote><br class="">Can you elaborate on that last sentence? I'm not very familiar with CMake, and that's a bit of a surprise to me.<br class=""></div></blockquote><div class=""><br class=""></div><div class="">CMake acts like a configure script determining what libraries, APIs, compiler features, etc are available. One of the limitations in our CMake system today is if you wanted to build compiler-rt for Linux on Darwin… good luck. The problem is that when you configure your build it runs all the availability checks against the OS X toolchain capabilities, which may be very different from the Linux you are targeting. For that matter, it can be different even in the much more common case of OS X targeting iOS.</div><div class=""><br class=""></div><div class="">Treating compiler-rt builds as single platform cross-targeted builds allows us to have CMake re-run the checks for every triple that you want to build compiler-rt for. Thus smoothing all that away.</div><div class=""><br class=""></div><div class="">For added context. When I talk about toolchain files I’m referring to the CMake variable CMAKE_TOOLCHAIN_FILE (<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.cmake.org_cmake_help_v3.0_variable_CMAKE-5FTOOLCHAIN-5FFILE.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=-DiU9OBDq0jcx4L6drE5mD4Mq8k1s1r3FL1KKuQ6OAU&s=UXsbaQG3rsmgHX8fG7sehlL7CcZtis2J1iduZ2dWeBA&e=" class="">http://www.cmake.org/cmake/help/v3.0/variable/CMAKE_TOOLCHAIN_FILE.html</a>). It is basically a little blurb of CMake that gets processed before any of the CMake platform checks or any other CMake file in your project. It can be used to define settings that need to influence the try_compile invocations that CMake uses for availability checks.</div><div class=""><br class=""></div><div class=""><div class="">Thanks,</div><div class="">-Chris</div></div><br class=""><blockquote type="cite" class=""><div class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><br class="">So, how do we get to this state?<br class=""><br class="">Honestly I don't have a complete plan, but I have some parts of a<br class="">plan.<br class=""><br class="">The first thing I'd like to do is try to make a bunch of the<br class="">Darwin-specific code go away. Obviously there will always need to<br class="">be some at a lower level because Darwin is different, but some of<br class="">the lower-level functions like<br class="">add_compiler_rt_darwin_object_library probably don't need to<br class="">exist.<br class=""><br class="">One example of the type of thing I want to get rid of is the ASan<br class="">CMakeLists.txt. The top-level CMake files for libraries and<br class="">executables shouldn't need to care about the targets. Today we loop<br class="">over OSs for darwin and call add_compiler_rt_darwin_object_library,<br class="">and for other operating systems we loop over archs and call<br class="">add_compiler_rt_object_library. I want to push the looping as low<br class="">down into the utility functions as possible. Doing this will reduce<br class="">the amount of Darwin-specific code because we replicate this exact<br class="">looping behavior all over Compiler-RT's build.<br class=""><br class="">The second thing I want to do is make the Darwin build able to<br class="">generate binaries for just OSX or just iOS. Today the Darwin build<br class="">tries to build everything all the time, and that really isn't the<br class="">behavior we need if we're going to treat iOS as a cross-compile.<br class=""><br class="">The third step is to make the Darwin llvm/clang/compiler-rt<br class="">combined build use cross-compilation for building the iOS runtime<br class="">libraries. I want to do this on Darwin only because that's the<br class="">platform I'm most familiar with. At some point if we want to move<br class="">other targets to cross-compiling I will need help from other people<br class="">in the community who are more familiar with the specific targets.<br class=""><br class="">With each step I'll be trying to remove more OS-specific code and<br class="">trying to streamline building.<br class=""><br class="">Questions/Comments/Concerns/Cries of insanity?<br class=""></blockquote></blockquote><br class="">Thanks for taking the driver's seat on the discussions of all this CMake transition stuff, BTW.<br class=""><br class=""><br class="">Cheers,<br class=""><br class="">Jon<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><br class="">Thanks, -Chris _______________________________________________ LLVM<br class="">Developers mailing list<span class="Apple-converted-space"> </span><a href="mailto:LLVMdev@cs.uiuc.edu" class="">LLVMdev@cs.uiuc.edu</a><br class=""><a href="http://llvm.cs.uiuc.edu/" class="">http://llvm.cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br class=""></blockquote><br class=""><br class="">_______________________________________________ LLVM Developers<br class="">mailing list<span class="Apple-converted-space"> </span><a href="mailto:LLVMdev@cs.uiuc.edu" class="">LLVMdev@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>        <a href="http://llvm.cs.uiuc.edu/" class="">http://llvm.cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br class=""><br class=""></blockquote><br class="">--<span class="Apple-converted-space"> </span><br class="">Jon Roelofs<br class=""><a href="mailto:jonathan@codesourcery.com" class="">jonathan@codesourcery.com</a><br class="">CodeSourcery / Mentor Embedded<br class=""><br class="">--<span class="Apple-converted-space"> </span><br class="">Jon Roelofs<br class=""><a href="mailto:jonathan@codesourcery.com" class="">jonathan@codesourcery.com</a><br class="">CodeSourcery / Mentor Embedded<br class=""></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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; line-height: 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="">LLVM Developers mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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=""><a href="mailto:LLVMdev@cs.uiuc.edu" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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="">LLVMdev@cs.uiuc.edu</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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=""><span class="Apple-converted-space"> </span>        </span><a href="http://llvm.cs.uiuc.edu/" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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="">http://llvm.cs.uiuc.edu</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></div></blockquote></div><br class=""></body></html>