<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 20, 2015 at 5:35 PM, Nick Kledzik <span dir="ltr"><<a href="mailto:kledzik@apple.com" target="_blank">kledzik@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Jan 19, 2015, at 6:33 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:<br>
<br>
> I wanted to go through and map out the layering of LLD's libraries today and found that it's essentially impossible. I think some serious cleanup is needed here.<br>
><br>
> Let's start with the purely link-level dependencies encoded in the CMake build:<br>
><br>
> Curently the Core library depends on the ReaderWriter/Native library, which links against the ReaderWriter library, which links against the Core library. This clearly cannot work. The same cycle exists with Core -> YAML -> ReaderWrite -> Core.<br>
</span>How are you determining these cycles?   How is Core dependent on YAML? (cause that seems wrong).<br></blockquote><div><br></div><div>This is in the CMake build system today. You can see it with CMakeLists.txt. Also you can look at Greg's patch for some of the issues here.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
I just build all of lld in an Xcode projects (which compiles each .o file and links them all together).  I never see any of the layering...<br></blockquote><div><br></div><div>The CMake build works on Mac OS X too. =] With Ninja, it is even quite speedy (or so I understand).</div><div><br></div><div>I'm hopeful in the not-too-distant-future we'll actually start enforcing even header file layering using Clang's Module's support (when it happens to be the host compiler). When that happens this stuff should actually be really explicit and enforced easily.</div><div><br></div><div>Until then, I also have access to some crazy (and sadly internal) tools that check header file layering between libraries. Hopefully we just modules soon though.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><br>
> The situation seems a bit worse for includes. If you start from LinkingContext.h I think this becomes quite clear. This is ostensibly part of the Core library, but it has methods that produce types from the ReaderWriter library. Combined with the fact that ReaderWriter depends on Core (not the other way around) and ReaderWriter/ELF subclasses LinkingContext, I can't make heads or tails of what was intended here.<br>
><br>
><br>
> My vague guess is that Core should actually be two libraries. One that doesn't depend on anything (other than Config) and provides the very "core" types for LLD. And another, perhaps called "Linker" which is a much higher-level library and provides useful APIs for actually doing linking, depends on ReaderWriter and provides methods that manipulate it. I could even see needing to spilt the target libraries in a similar manner.<br>
><br>
><br>
> But I don't know LLD's design well, I'm just trying to stitch the build system back together in a reasonable way, so maybe I've missed things completely. So help me out. I'd like to understand a reasonable DAG in which to construct libraries for LLD. Having this should allow proper layering, layering checks, and eventually building with C++ modules. All of which seem essentially impossible today.<br>
<br>
</span>One question I have is what should the granularity of the libraries be?  At one point I asked about building an lld for OSX that only had mach-o support and got push-back that lld should always be a universal linker.  If that is the case, why have so many small libraries?<br>
<br>
Besides lld the command line tool, I can see lld libraries being used to construct a JIT linker.  And in that case, I can see wanting a very pared down linker - just one file format (not yaml) and no driver. </blockquote></div><br>So, I think there is a good rationale for supporting both fine grained libraries and LLD always being a universal / cross linker.</div><div class="gmail_extra"><br></div><div class="gmail_extra">The libraries make it *possible* (as you indicate with the JIT stuff) to build a narrowly targeted linker that has no excess functionality. We should still choose to produce a full cross-linker binary called "lld" which uses all the libraries.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Does that make sense?</div><div class="gmail_extra"><br></div><div class="gmail_extra">While I think that generally layering also helps abstractly organize the code, I don't think it is worth thinking about layering that serves no purpose. So, if it isn't *possible* to use library A without using library B as well, it doesn't make sense to separate them. I'm happy to separate them if it is possible even if the users for this separation haven't yet materialized.</div><div class="gmail_extra"><br></div><div class="gmail_extra">-Chandler</div></div>