<div class="gmail_quote">On Thu, May 31, 2012 at 2:02 AM, Alexey Samsonov <span dir="ltr"><<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<div><br></div><div>tl;dr How can I include LLVM headers and use code from libLLVM*.a files when building compiler-rt libraries?</div></blockquote><div><br></div><div>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.</div>
<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>I'd like to create a symbolizer that would be used in AddressSanitizer (ASan) and ThreadSanitizer (TSan) tools which are now part of</div>

<div>projects/compiler-rt (as a first step, symbolizer should be able to return file/line info for a given address).</div><div>I'd like to use and gradually extend the interface in "llvm/DebugInfo/DIContext.h"</div>
</blockquote><div><br></div><div>I've discussed this with several others before (including Chris IIRC), and he strongly agreed with this approach FWIW.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div>I see two obstacles:</div><div><br></div><div>1) How can I include LLVM headers in source files inside projects/compiler-rt?</div><div>As a local workaround, I modify configuration for ASan/TSan runtimes as follows:</div>

<div>CFLAGS.asan-x86_64 := $(CFLAGS) -I$(PathToLLVMInclude) -I$(PathToLLVMBuildInclude)</div><div>Note that I need both "/path/to/llvm_checkout/include" and "/path/to/llvm_build/include", because some LLVM headers are generated when</div>

<div>LLVM is built (e.g. "llvm/Support/DataTypes.h"). This looks very broken, as paths are hardcoded, and LLVM headers are</div><div>not included in dependencies for ASan/TSan runtime.</div></blockquote><div><br>
</div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div><br></div><div>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....</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>2) How can I use LLVM libraries when building compiler-rt?</div><div>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".</div>
<div>
Can I somehow make this runtime contain compiled LLVM libraries as well?</div><div>Currently I need libLLVMDebugInfo.a and libLLVMSupport.a.</div></blockquote><div><br></div><div>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.</div>
</div>