Regarding Brad King's CMake patches for LLVM:
http://thread.gmane.org/gmane.comp.compilers.llvm.cvs/173517
If compiler-rt could follow suit, the packaging for the toolchain
becomes a nice, clean package-manager-friendly DAG. Currently, the
compiler-rt CMake build depends on the just-built-clang to run its
test suite. It's more intuitive to me that either:
1) compiler-rt's sanitizer tests would live inside the clang project
2) compiler-rt would export a test suite that clang could optionally import
The former is simpler, but the latter allows the compiler-rt
developers to retain control over those tests, which are typically
updated alongside changes to compiler-rt's sanitizers. Thoughts?
Thanks,
Greg
The trouble is that the sanitizer tests are not really compiler-rt
tests. The original compiler-rt tests are, but not the sanitizer
tests. The sanitizer tests are "compiler-rt tests via clang". The
sanitizer runtime is a C++ library requiring only a C++ compiler to
build it (and to *unit* test it). The ASan lit tests, however,
require clang, because they are testing those C++ functions in the
context of a particular C/C++ compiler's instrumentation. I believe
these tests should not be called "compiler-rt tests". They are clang
tests.
In fact, they are just-built-clang tests. They don't, for
example, verify the C++ library is useful to another compiler, another
version of clang, or simply as a C++ library. They are integration
tests (tests clang+asan), as opposed to unit tests (tests only the
asan runtime).
I understand that the integration tests are more relevant to the
sanitizers than they are clang, and so it make sense to me that they
reside in the compiler-rt repo alongside the sanitizers. But rather
than build them in the compiler-rt build, I think the directory should
be exported so that clang can optionally import it. The clang build
can then add those tests to the clang tests suite, and install the
runtime in whatever location is most appropriate for clang.
Why is this important now? The CMake developers are trying to make
the LLVM toolchain easy to build for package managers. Compiler-rt's
dependency on the just-built-clang makes that difficult. Without that
dependency, Compiler-rt could be built and tested against only an LLVM
package.
And likewise, a Clang package would depend on Compiler-rt
(and do further testing on compiler-rt with those lit tests).
But
with the dependency on the just-built-clang, there needs to be an
additional top-level package, let's call it ClangAndFriends.
ClangAndFriends would depend on Clang and Compiler-rt. Compiler-rt
would depend on the Clang package as well. Once both are built,
ClangAndFriends would copy the Clang install directory and then copy
the Compiler-rt install directory into it.
This extra package and
extra copy would be unnecessary if the Compiler-rt build dropped its
dependency on the just-built-clang. After testing the sanitizers, the
Clang package would copy the runtime into its own install directory.
So what next? Wait for Brad King's LLVM patches to be integrated.
Then we tweak the compiler-rt build to optionally build against the
LLVM install directory (instead of in the context of the LLVM source
directory).
Next, we use CMake to export the Sanitizer lit tests.
Lastly, Clang optionally imports the test suite and adds the sanitizer
runtime to its install directory. What do you think? Squeaky clean?
Thanks,
Greg
Le 6 févr. 2014 à 16:20, Brad King <brad...@kitware.com> a écrit :
Look like what we need to build compiler-rt. Actually the makefile responsible to launch the compiler-rt build is in clang/runtime/compiler-rt.
> On 02/06/2014 08:12 AM, Alexey Samsonov wrote:
>> Please note that it makes a lot of sense to built compiler-rt (and sanitizers) with just-built
>> Clang. In fact, even though we should support building it with another compilers (gcc, MSVC),
>> using just-built-Clang should be a default scenario, like it is in configure+make build.
>
> This is possible with CMake using the ExternalProject module:
>
> http://www.cmake.org/cmake/help/v2.8.12/cmake.html#module:ExternalProject
>
> The add_llvm_external_project macro already in LLVM could be taught
> to call ExternalProject_Add instead of add_subdirectory. This could
> create a custom target with dependencies appropriately configured to
> build after Clang. The custom target would run CMake to configure the
> project like an outside build and then launch the build.
>
> IIUC there is a desire for Clang to be able to be built externally to
> LLVM rather than subsumed into its build process. The top-level
> CMakeLists.txt file of Clang already has code to do that, though it
> can be much cleaner after my patches to LLVM to provide LLVMConfig.cmake
> are integrated. Then it will even be possible to build Clang using
> CMake against a LLVM that was built and installed using configure+make.
>
> If one would like to drive compiler-rt as part of testing a Clang built
> outside of LLVM then the appropriate place for the ExternalProject_Add
> call would be inside the build of Clang.
Using ExternalProject_Add, we can probably add the CMake part beside that existing file, so everything will be at the same place.
> _______________________________________________
> Either way, from a quick glance at the top-level CMakeLists.txt file
> in compiler-rt it appears to want to know a bunch of information about
> Clang rather than LLVM. In this case having Clang export enough info
> for applications to write find_package(Clang) would make sense. This
> is possible to do an can be implemented using techniques similar to
> that in my proposed LLVMConfig.cmake patch series.
>
> -Brad
>
> LLVM Developers mailing list
> LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-- Jean-Daniel
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On 02/06/2014 01:02 PM, Alexey Samsonov wrote:It is the CMake equivalent to a configure+make build target that
> OK, I feel like I need to learn more about ExternalProject_Add magic.
runs configure+make for another project.
This will be possible once LLVM and Clang are taught to provide proper
> I have a few quick questions for people with knowledge - currently:
> 1) "compiler-rt"'s CMake needs to know about targets in the Clang build tree ("clang") and
> in LLVM build tree ("FileCheck", llvm-* command-line tools, googletest etc.), and uses common
> macro from LLVM's CMake modules like "configute_lit_site_cfg", "parse_arguments".
content in LLVMConfig.cmake and ClangConfig.cmake package configuration
files. The patch series I proposed in the thread Greg linked at the
start of this thread is the first step to do that.
This would not work with ExternalProject_Add because the CMake
> 2) top-level targets from compiler-rt's CMake files are visible at the root of LLVM's build tree,
> so that I can run "make check-asan" or even "make clang_rt.asan-x86_64" from the root of
> the build tree.
running on LLVM or Clang would not see the targets in compiler-rt
since the project will not even be processed until build (make) time.
In return the compiler-rt would be able to build using the just-built
Clang because it will now be available when CMake runs on compiler-rt.
(IIUC this is currently the case for configure+make.) Also compiler-rt
could now be built outside of a LLVM/Clang that was built unaware of
compiler-rt.
It is also possible to make project/compiler-rt build optionally
with add_subdirectory instead of ExternalProject_Add, as it does now,
with the cost of not using the just-built Clang.
-Brad
-Brad
On 02/21/2014 11:20 AM, Alexey Samsonov wrote:Just "build" should be sufficient because the generated build system
> We can even use "DEPENDERS configure" instead of "DEPENDERS build" here.
in compiler-rt knows how to re-run CMake if any of the inputs have
changed. This is just as you do not need to re-run "cmake ." by hand
after editing CMakeLists.txt and can just type "make".
-Brad
On 02/24/2014 08:53 AM, Alexey Samsonov wrote:
> On Fri, Feb 21, 2014 at 9:03 PM, Brad King wrote:> Suppose LLVMConfig.cmake has changed.
> Just "build" should be sufficient because the generated build system
> in compiler-rt knows how to re-run CMake if any of the inputs have
> changed.
>
Every file CMake processes as part of configuring the project ends up in
the build-time dependencies to re-run CMake.
It looks pretty good to me. I added some inline comments.
-Brad
On 02/24/2014 09:44 AM, Alexey Samsonov wrote:
> ExternalProject_Add_Step(compiler-rt force-rebuild
> DEPENDERS build
[snip]
> doesn't work for Ninja.What version of CMake did you use for this test? Also 2.8.10?
Yes, though there have been some changes related to this upstream
> Is it a CMake bug?
since 2.8.10, IIRC.
I think you can just go with your original "DEPENDERS configure"
approach for now.
-Brad
On 02/24/2014 10:02 AM, Alexey Samsonov wrote:Well, the upstream change I made to simplify this feature in
> Yes, 2.8.10.2 to be exact.
the future:
includes a test that touches a file in the external project
ExternalProject: Add option to always run the build step
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=73e5c6ae
source. It passes our test suite with the Ninja generator.
Please see if you can reproduce this with CMake 'master' from
Git:
git clone git://cmake.org/cmake.git CMake &&
mkdir CMake-build &&
cd CMake-build &&
../CMake/bootstrap --parallel=8 &&
make -j 8 &&
bin/cmake --version
Thanks,
-Brad
On 02/25/2014 03:28 AM, Alexey Samsonov wrote:I'm able to reproduce that, thanks. This is a subtle interaction
> Then I run
> $ ninja compiler-rt
> twice. The first run builds the libraries, the second shows only:
> "ninja: no work to do." message.
between always-out-of-date rules and order-only dependencies.
The problem is that the build.ninja file has the rule:
build projects/compiler-rt/src/compiler-rt-stamp/compiler-rt-force-reconfigure: phony || bin/clang bin/llvm-config
to express the always-out-of-date force-reconfigure rule. The Ninja
documentation says:
"If a phony build statement is written without any dependencies,
the target will be considered out of date if it does not exist."
However, the rule has dependencies because the Ninja generator implements
add_dependencies by adding order-only dependencies to every individual
rule in the dependent target on all dependencies.
It looks like the Ninja generator needs to write a rule is always out
of date but still has order-only dependencies. I think this will work:
build projects/compiler-rt/src/compiler-rt-stamp/compiler-rt-force-reconfigure: phony | always || bin/clang bin/llvm-config
build always: phony
I've recorded this issue in the CMake issue tracker:
http://www.cmake.org/Bug/view.php?id=14771
-Brad
On 02/26/2014 12:43 PM, Alexey Samsonov wrote:Since it is conditional on LLVM_BUILD_EXTERNAL_COMPILER_RT, yes.
> Do you think it makes sense to land my ExternalProject_Add patch
> so that others can experiment with it? I can add quit with a
> fatal_error/warning if the build tree rules are generated with Ninja.
Right. The ExternalProject module has a special case for the
> parallelism doesn't work when I run "make check-compiler-rt -j8"
> in the original build tree, presumably because we call
> "cd /path/to/compiler-rt/build/tree && make check-all" there.
Makefile generators to make with $(MAKE) instead of "make":
http://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/ExternalProject.cmake;hb=v2.8.12.2#l846
so that flags like -j propagate automatically. You could do
that too:
if(CMAKE_GENERATOR MATCHES "Make")
set(check_compiler_rt "$(MAKE)" "check-all")
else()
set(check_compiler_rt ${CMAKE_COMMAND} --build .
--target check-all --config $<CONFIGURATION>)
endif()
ExternalProject_Get_Property(compiler-rt BINARY_DIR)
add_custom_target(check-compiler-rt
COMMAND ${check_compiler_rt}
DEPENDS compiler-rt
WORKING_DIRECTORY ${BINARY_DIR}
VERBATIM
)
> ExternalProject_Add(compiler-rt ...)
So that was quite the experiment. Looking at
clang/runtime/CMakeLists.txt, I'm not seeing a lot of bang for buck
here, and it looks like this file is prone to bit rot.
I think we
should consider punting on this one and looking for a more incremental
strategy. For instance, how about starting by moving the call
'add_llvm_external_project(compiler-rt)' from
llvm/projects/CMakesLists.txt to clang/runtime? We can tweak this
macro (or a clang variant) to optionally do something like:
include(AddCompilerRt)
That way if CMAKE_PREFIX_PATH includes a path to the compiler-rt
install directory, it can import all the same build targets that would
be created by add_subdirectory(compiler-rt).
Regarding the use of ExternalProject within Clang, I think it could
create more problems than it solves. For one, it can't be used from
within the monolithic build (unless you have a duplicate llvm build,
or point CompilerRT to a subset of the currently-building LLVM build).
Secondly, it's not a general enough solution for other LLVM
components. Say, for example, you wanted to use ExternalProject to
build LLVM from both Clang and CompilerRT.
If the parameters passed
to LLVM were identical, CMake could detect that and not build a
duplicate copy. If they parameters are different in any way, you have
a problem. Do you duplicate the build or flag an error? We can avoid
this issue by allowing a super-project or package manager build LLVM
and pass its path to both Clang and CompilerRT.
Regarding the use of just-built-clang for both building CompilerRT and
running its test suite, please consider relaxing that to a
stage0-clang for building and a just-built-clang for testing.
Using
the just-built-clang to build compiler-rt is rough on package
managers. You're basically stating that the compiler-rt build depends
on some unreleased feature of clang to *build* compiler-rt.
To a
package manager, that means it should first build clang, then use that
clang to build compiler-rt, and then build a version of clang that
includes compiler-rt.
Hi Alexey,
> What if we don't have stage0-clang?
I'd like to answer this question in detail. I think if we're on the
same page about which compiler to use to build CompilerRT and where it
comes from, then the rest will, with any luck, fall into place.
Here is a dependency diagram for building and running the sanitizer test suite:
On Tue, Mar 25, 2014 at 6:36 AM, Greg Fitzgerald <gar...@gmail.com> wrote:
Hi Alexey,
> What if we don't have stage0-clang?
I'd like to answer this question in detail. I think if we're on the
same page about which compiler to use to build CompilerRT and where it
comes from, then the rest will, with any luck, fall into place.
Here is a dependency diagram for building and running the sanitizer test suite:Why do you state that Clang depends on compiler-rt libs? Currently it doesn't:compiler-rt libs are not necessary to link "clang" binary (as LLVM libs are).фтв compiler-rt libs are optional in the sense that "clang" binary works perfectly fine ifthey are missing (though not all of the features are supported).