[LLVMdev] Using LLVM code in projects/compiler-rt

Chandler Carruth chandlerc at google.com
Thu May 31 02:16:22 PDT 2012


On Thu, May 31, 2012 at 2:02 AM, Alexey Samsonov <samsonov at google.com>wrote:

> Hi,
>
> tl;dr How can I include LLVM headers and use code from libLLVM*.a files
> when building compiler-rt libraries?
>

Currently, there isn't a way, but this is something I very much want to see
supported. I started working on this w/ the CMake build system, but had to
go work on other things. I do hope to get back to it, and if this is on the
critical path, I can try to talk you through what needs to be done and
review patches. I may even have some time to work on it soon.


I'd like to create a symbolizer that would be used in AddressSanitizer
> (ASan) and ThreadSanitizer (TSan) tools which are now part of
> projects/compiler-rt (as a first step, symbolizer should be able to return
> file/line info for a given address).
> I'd like to use and gradually extend the interface in
> "llvm/DebugInfo/DIContext.h"
>

I've discussed this with several others before (including Chris IIRC), and
he strongly agreed with this approach FWIW.


> I see two obstacles:
>
> 1) How can I include LLVM headers in source files inside
> projects/compiler-rt?
> As a local workaround, I modify configuration for ASan/TSan runtimes as
> follows:
> CFLAGS.asan-x86_64 := $(CFLAGS) -I$(PathToLLVMInclude)
> -I$(PathToLLVMBuildInclude)
> Note that I need both "/path/to/llvm_checkout/include" and
> "/path/to/llvm_build/include", because some LLVM headers are generated when
> LLVM is built (e.g. "llvm/Support/DataTypes.h"). This looks very broken,
> as paths are hardcoded, and LLVM headers are
> not included in dependencies for ASan/TSan runtime.
>

The CMake build system should make much of this Just Work by building the
runtime as just another LLVM sub-project. I increasingly think this is the
correct approach rather than trying to bootstrap the runtime library
(despite being firmly on the other side of things originally). It
simplifies a large number of issues, and I think all of my prior concerns
were misplaced.

I'm not an expert in the Makefile build system, but my suspicion is that
the changes needed to get into the same position as the (rudimentary, and
incomplete) CMake build support is to switch compiler-rt, and especially
the *san libraries, to use the normal LLVM-subproject build system
structure.


However, the current Makefile build for compiler-rt has a huge special
feature that won't play nicely with this: automatic cross-compilation. In
order to make this *really* work, in either the Makefile or CMake build
systems, we're going to have to teach the root LLVM build system how to do
on-demand cross-compilation of selected LLVM libraries, so that compiler-rt
can build a collection of libraries for different target platforms. From my
perspective, that's the big hurdle. It's also likely to be quite a bit of
work to figure out in either CMake or Makefiles, and I'm only really
competent with the CMake side of things....


> 2) How can I use LLVM libraries when building compiler-rt?
> Currently, compiler-rt builds (linux) runtime and stores it as an .a file
> in "/path/to/llvm_build/Release+Asserts/lib/clang/3.2/linux".
> Can I somehow make this runtime contain compiled LLVM libraries as well?
> Currently I need libLLVMDebugInfo.a and libLLVMSupport.a.
>

This shouldn't be a hard problem to solve at the build system level once
you can compile against the libraries. You just have to re-run ar to fuse
the archives. Let's solve this if & when we get the other solved.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120531/00e7cc3a/attachment.html>


More information about the llvm-dev mailing list