This is definitely a concern. That’s why I had proposed not treating “host” as a cross-target. Handling building compiler-rt for host differently makes one of the common cases better. WRT Ninja. Ninja’s pooling capabilities actually should solve some of the problems you’re voicing. In particular, we can make the cross-builds fall into the “console” pool to prevent ninja from over-saturating the system (https://martine.github.io/ninja/manual.html#_the_literal_console_literal_pool <https://martine.github.io/ninja/manual.html#_the_literal_console_literal_pool>). I also expect that we could engage with the CMake community to come up with better tooling for cross-compiling to help mitigate some of this. In particular I would really love to have a way import a configured project into the project you’re configuring, and have it generate a single build configuration that doesn’t just call out to CMake to build the other project. I honestly don’t know a whole lot about the compiler-rt codebase. I’ve stepped into this project largely just as an extension of my hatred for autoconf. I don’t know how much we’ll get from CMake’s cross-compilation, but I do know that the way we handle cross-targeting CMake today for iOS leaves a lot to be desired. One of my concerns is actually that the custom rules we have for the sanitizer test suite doesn’t work at all on Darwin unless you have the OS headers installed to / (which isn’t the default anymore). I think that teaching CMake to be smart enough about how it invokes the compiler to be able to support all our platforms will be a lot of work duplicating things CMake itself already does. -Chris> On Jun 4, 2015, at 2:25 PM, Reid Kleckner <rnk at google.com> wrote: > > I'm actually pretty leery of using the CMake cross-compiling support because it requires using multiple build directories with split build systems. We end up a situation where the parent build shells out to cmake and then recursively reinvokes the parent build system on the new build directory. Running cmake again in the first place is really slow (lots of test compiles in serial), and recursively invoking the build system leads to really bad job scheduling on all build systems other than 'make'. In particular, ninja shelling out to ninja will oversaturate the system, and I don't expect it to ever add job server functionality like make has. > > How much are we really getting from using the upstream cmake cross-compiling support? Most of the header and symbol checks that we have are for the sanitizer test suite, which I doubt needs generalized cross-compilation support. Only the <unwind.h> check appears to matter for lib/builtins. Maybe we should roll our own custom rules for invoking the just-built clang compiler like we already do for the sanitizer test suite? I cc'd Alexey, who I believe wrote that support. > > Anyway, thanks for tackling this, you're the one doing the work, and I'm not volunteering. :) Do what you think is best. I mostly wanted to present a possible alternative approach. > > On Mon, Jun 1, 2015 at 3:21 PM, Chris Bieneman <beanz at apple.com <mailto:beanz at apple.com>> wrote: > LLVMDev, > > PR 15732 is the umbrella tracking the progress of making the CMake build system feature equivalent to the autotools one. One of the biggest outstanding tasks is PR 21562, which I've been viewing more as a "We really need to fix how we build Compiler-RT." > > I've thought about this quite a bit, and I wanted to send out some of my ideas to get some feedback and have some discussions about the way forward. > > The complication with Compiler-RT is that it is inherently a cross-compile. When you build LLVM, Clang and Compiler-RT, you really want to build LLVM, Clang, and n Compiler-RTs where n is the valid combinations of target architectures and/or platforms your clang supports. > > There are three basic configurations for building Compiler-RT. > > (1) Building a "pure" Clang supporting targeting your host > (2) Building a cross-targeting Clang that runs on one OS or architecture and targets another > (3) Building a Clang that both self-targets and cross-targets > > The overall change I want to make to Compiler-RT is that I want to handle case 1 as an in-tree build similar to how it is today, case 2 as a cross-compile, and case 3 as a combination of cases 1 & 2. > > Let me walk through an example of how I think this should work. > > If my host is OS X and I'm building Clang to target OS X and iOS, when I configure my build directory there will be an in-tree build of Compiler-RT (via add_llvm_external_project) to generate the OS X runtime libraries, and an out-of-tree-style cross-compile generated for building the iOS runtime libraries for all supported architectures. This would all be driven via command line settings like: > > LLVM_COMPILER_RT_IOS_ARCHS="armv7;armv7s;arm64" > LLVM_COMPILER_RT_OSX_ARCHS="x86;x86_64" > > This would generate universal binary outputs in the format: > libclangrt_<lib>.<os>.<ext> > > As a second example, if you were on Windows building a Clang to target only FreeBSD when you configured your build directory there would only be an out-of-tree-style cross-compile generated for your target architecture against FreeBSD. The command line setting here would be: > > LLVM_COMPILER_RT_FREEBSD_ARCHS="x86;x86_64" > > This would generate binary outputs in the format: > libclangrt_<lib>.<arch>.<ext> > > Similarly if you were on linux targeting linux you’d only get an in-tree build with outputs: > libclangrt_<lib>.<arch>.<ext> > > The cross-compile builds will be driven via CMake's toolchain file settings, so if you were cross-targeting and need to set compiler options like -isysroot there will need to be a toolchain file defined for your target platform. > > Using toolchain files and cross-compile configurations solves one of the problems with our current CMake system where the Compiler-RT builds don't re-run the CMake checks. Not re-running the CMake checks causes significant problems if your host and target OS are different. > > So, how do we get to this state? > > Honestly I don't have a complete plan, but I have some parts of a plan. > > The first thing I'd like to do is try to make a bunch of the Darwin-specific code go away. Obviously there will always need to be some at a lower level because Darwin is different, but some of the lower-level functions like add_compiler_rt_darwin_object_library probably don't need to exist. > > One example of the type of thing I want to get rid of is the ASan CMakeLists.txt. The top-level CMake files for libraries and executables shouldn't need to care about the targets. Today we loop over OSs for darwin and call add_compiler_rt_darwin_object_library, and for other operating systems we loop over archs and call add_compiler_rt_object_library. I want to push the looping as low down into the utility functions as possible. Doing this will reduce the amount of Darwin-specific code because we replicate this exact looping behavior all over Compiler-RT's build. > > The second thing I want to do is make the Darwin build able to generate binaries for just OSX or just iOS. Today the Darwin build tries to build everything all the time, and that really isn't the behavior we need if we're going to treat iOS as a cross-compile. > > The third step is to make the Darwin llvm/clang/compiler-rt combined build use cross-compilation for building the iOS runtime libraries. I want to do this on Darwin only because that's the platform I'm most familiar with. At some point if we want to move other targets to cross-compiling I will need help from other people in the community who are more familiar with the specific targets. > > With each step I'll be trying to remove more OS-specific code and trying to streamline building. > > Questions/Comments/Concerns/Cries of insanity? > > Thanks, > -Chris > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu <http://llvm.cs.uiuc.edu/> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150604/c544c7f8/attachment.html>
On Thu, Jun 4, 2015 at 3:02 PM, Chris Bieneman <beanz at apple.com> wrote:> > One of my concerns is actually that the custom rules we have for the > sanitizer test suite doesn’t work at all on Darwin unless you have the OS > headers installed to / (which isn’t the default anymore). I think that > teaching CMake to be smart enough about how it invokes the compiler to be > able to support all our platforms will be a lot of work duplicating things > CMake itself already does. >Right, for problems like this, we'd end up writing lots of cmake code to go and find headers and libraries like this, effectively replacing the toolchain knowledge that we could get from cmake. It's a tradeoff that may or may not be worth it, and I'm not sure what the answer is. =/ Maybe if we use the standard cmake cross-compilation approach someone will come along later and solve this problem at the cmake level. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150604/552578f7/attachment.html>
Alexey Samsonov
2015-Jun-05 01:18 UTC
[LLVMdev] [RFC] Ideas on improving Compiler-RT CMake
Sorry for the late response. You should check out CMAKE_TOOLCHAIN_FILE logic for Android platform - IIRC build rules for Android are much simpler than for Darwin/Linux, and assume that build tree will be properly configured to build a single compiler-rt runtime for a specific triple. Probably this is the approach you want to eventually use for another platforms. Also check out LLVM_BUILD_EXTERNAL_COMPILER_RT flag, which is an attempt to use ExternalProject to recursively call CMake from LLVM/Clang build tree. It doesn't iterate over all the target triples we want/can support, though. It had some problems with Ninja, though. I'd also prefer to not move host==target to a special case, at least at the beginning. I definitely support the effort of simplifying things and generalizing the OS-specific code in CMake. Patches are more than welcome here =) We want to support building (at least part of) compiler-rt libraries with GCC. I'm mostly speaking about sanitizers here: sanitizer runtimes shipped with GCC are built from the same sources we have in compiler-rt. However, I agree that it should not be the default (just-built Clang should be the default) - we can just setup a buildbot that would build standalone compiler-rt with GCC. On Thu, Jun 4, 2015 at 3:45 PM, Reid Kleckner <rnk at google.com> wrote:> On Thu, Jun 4, 2015 at 3:02 PM, Chris Bieneman <beanz at apple.com> wrote: >> >> One of my concerns is actually that the custom rules we have for the >> sanitizer test suite doesn’t work at all on Darwin unless you have the OS >> headers installed to / (which isn’t the default anymore). I think that >> teaching CMake to be smart enough about how it invokes the compiler to be >> able to support all our platforms will be a lot of work duplicating things >> CMake itself already does. >> > > Right, for problems like this, we'd end up writing lots of cmake code to > go and find headers and libraries like this, effectively replacing the > toolchain knowledge that we could get from cmake. It's a tradeoff that may > or may not be worth it, and I'm not sure what the answer is. =/ > > Maybe if we use the standard cmake cross-compilation approach someone will > come along later and solve this problem at the cmake level. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-- Alexey Samsonov vonosmas at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150604/4ca1d971/attachment.html>