<div>I've updated the patch files:</div>
<div> </div>
<div><a href="http://www.jtlanguage.com/xfer/dll_llvm_patch.txt" target="_blank">http://www.jtlanguage.com/xfer/dll_llvm_patch.txt</a></div>
<div><a href="http://www.jtlanguage.com/xfer/dll_clang_patch.txt" target="_blank">http://www.jtlanguage.com/xfer/dll_clang_patch.txt</a></div>
<div> </div>
<div>I broke some things in TargetSelect.h which are now fixed.</div>
<div> </div>
<div>I figured out why the clang tests weren't running for me. Turns out you can't have the Cygwin version of python in the PATH as cmake will use it regardless of other pythons earlier in the PATH.</div>
<div> </div>
<div>However, 8 of the Index tests fail with my DLL version, which I haven't figured out yet, but I will. The non-DLL build fails with one error, but is the same as a clean tree.</div>
<div> </div>
<div>I'd appreciate some feedback on whether this approach will be acceptible.<br></div>
<div>-John<br></div>
<div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">John Thompson</b> <span dir="ltr"><<a href="mailto:john.thompson.jtsoftware@gmail.com">john.thompson.jtsoftware@gmail.com</a>></span><br>
Date: Mon, Apr 25, 2011 at 1:23 PM<br>Subject: Big Windows Clang DLL<br>To: <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a>, llvmdev <<a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>><br><br>
<br><font size="2">
<p>Hi,</p>
<p>I've been doing some experimenting to get a "big" DLL version of Clang working. This involves changes to LLVM as well as Clang, and might apply to doing a "big" DLL version of LLVM too (if that makes sense), so I'm posting this to both cfe-dev and llvmdev.</p>
<p>Basically, I want to find out if this mechanism is acceptable, or what alternative I should pursue.</p>
<p>I have a minimal version partly working, with just enough symbols exported so I can build a clang executable against the DLL, so I thought it would be the right time to open it up for discussion and review.</p>
<p>The scheme is meant to satisfy the following design goals/constraints:</p>
<p>1. Create a single Windows DLL including the main Clang and LLVM modules needed for a compiler and other tools, such that it's the only module you need to link against (from the Clang/LLVM project).</p>
<p>2. Preserve the current module organization and build, leaving the static-library and other platform's shared library versions as they are. (This leaves open the option of creating per-module Windows DLLS in the future.)</p>
<p>3. Enable Clang plug-ins to share the code and data space with the Clang or other tool executables.</p>
<p>4. Make the "big" DLL version optional by means of cmake arguments given upon running cmake. (I'm not sure of the criteria for deciding whether to make it the default for Windows or not.)</p>
<p>These are the build changes, with respect to the cmake build tool:</p>
<p>1. A "BUILD_LLVM_DLL" configuration flag is added to the cmake build, such that specifying "-DBUILD_LLVM_DLL=ON" in the cmake command line will enable the big-DLL build. By default it is off.</p>
<p>2. Factor out the common portions of the "add_clang_library" into "add_clang_library_common".</p>
<p>3. Modify the cmake macro "add_clang_library" to collect the source file full path strings in a new target property. </p>
<p>4. Add a new "add_clang_dll" cmake macro for creating the big DLL. This macro operates like "add_clang_library", but always builds a DLL target, and doesn't collect the source paths. It also passes "LLVM_USE_DLL" and "LLVM_EXPORTS" defines to the compiler, to enable the symbol exports to be described later.</p>
<p>5. Create a new "ClangDLL" project under tools/clang/lib for creating the big DLL, which uses the new "add_clang_dll" macro.</p>
<p>6. Add new "set_clang_components" and "set_clang_llvm_components" cmake macros for use in conjunction with "add_clang_executable" to collect the Clang and LLVM components, as opposed to setting "LLVM_USED_LIBS" and "LLVM_LINK_COMPONENTS" directory. (These macros will substitute the big DLL for the component libraries.)</p>
<p>7. Modify "add_clang_executable" to pass an "LLVM_USE_DLL" define to the compiler if the big-DLL version is enabled. This define enables the symbol imports/exports to be described later.</p>
<p>8. Update the clang executable, interpreter, and PrintFunctionNames projects to use the new and revised cmake macros.</p>
<p>The source changes mainly consist of adding "(moduleNameUppercase)_LINKAGE" macro instances to the declarations of the classes, functions, and other symbols to be exported/imported, and new header files that define these macros. These changes can be summarized as follows:</p>
<p>1. A new "(moduleName)Common.h" file is added to each LLVM and Clang module include directory. This file defines a "(moduleNameUppercase)_LINKAGE" macro for that component module. This macro expands to nothing for the non-big-DLL version ("LLVM_USE_DLL" is not defined to the compiler), or to the LLVM_EXPORT macro when building the DLL ("Clang_EXPORTS" or "LLVM_EXPORTS" or "(moduleName)_EXPORTS" is defined), or to the LLVM_IMPORT macro when building against the DLL ("LLVM_USE_DLL" is defined). This include file will be included by any headers in the component needing the "(moduleNameUppercase)_LINKAGE" macro. </p>
<p>2. A new "LLVMCommon.h" file is added to the include/llvm directory under the root to define "LLVM_EXPORT" and "LLVM_IMPORT" macros that wrap the Visual C++ "__declspec(dllexport)" and "__declspec(dllimport)" directives, as well as to define the "LLVMCORE_LINKAGE" macro. This file will be included by all the "(moduleName)Common.h" files for the LLVM components.</p>
<p>3. A new "ClangCommon.h" file is added to the tools/clang/include/clang directory. It just includes the "LLVMCommon.h" file, and will be included by the "(moduleName)Common.h" files for the Clang components.</p>
<p>In my experimental version, I added most of the "(moduleName)Common.h" files, but I only added the "(moduleNameUppercase)_LINKAGE" macro instance to some of the symbols, at least the ones needed by the Clang driver and interpreter to link.</p>
<p>Caveats:</p>
<p>1. The ALL_BUILD project build breaks on some missing .inc files from the X86 target project. I think this has to do with an inherent dependency problem in the cmake build. Even though the "(target)CodeGenTable_gen" project dependency is added to the DLL, the .inc files are not created before the DLL link. I will look into this. A rebuild of the "clang" project does work, as that was the focus of my experiment. The interpreter might build too, as it did earlier.</p>
<p>2. While I seem to be able to run the clang executable okay, on my machine the clang tests don't run. They don't run for the clean tree either, so either my machine setup is broken, or the tests in general are broken on Windows. I haven't figured out the problem yet. I'll be looking into this shortly, or if you know of a problem in general, please let me know.</p>
<p>3. As I mentioned, I only exported some of the symbols, those needed to get the clang executables to build. A big edit (manual or automated) will be needed to add the "(moduleNameUppercase)_LINKAGE" macros to the rest of the symbols, and any needed "(moduleName)Common.h" headers not yet created.</p>
<p>4. I only enabled the X86 target in LLVM (the default for the Windows build in general), for the purpose of this experiment. The other targets will need to be done as well.</p>
<p>5. I tried running the PrintFunctionNames plugin, but there's still a disconnect between the registry referenced by the plugin and the one in the big DLL. I didn't look into it deep enough yet, but I'm guessing it has something to do with the template mechanism used not being exported. I'm not even sure how to export it. But I think the better solution is to switch to the simplified plugin mechanism I provided a patch for in a previous post (and which I'm still waiting for a review fornudge-nudge).</p>
<p>6. In building on Windows with the big DLL mechanism enabled, there are a lot of "class 'someTemplateClass<_Ty>' needs to have dll-interface to be used by clients of class 'someClass'" warnings. I haven't looked into how to best fix of these yet.</p>
<p>7. These were somewhat hasty edits, but I verified that it still builds for Windows with the big-DLL option turned off. Sorry if I missed something in this write-up.</p>
<p>I've created two patch files with my current changes. Because they are so big I'm not including them as an enclosure, but you can get them here:</p>
<div><a href="http://www.jtlanguage.com/xfer/dll_llvm_patch.txt" target="_blank">http://www.jtlanguage.com/xfer/dll_llvm_patch.txt</a></div>
<div><a href="http://www.jtlanguage.com/xfer/dll_clang_patch.txt" target="_blank">http://www.jtlanguage.com/xfer/dll_clang_patch.txt</a></div>
<div> </div>
<div>You can search on "CMakeLists.txt" and ".cmake" to see the cmake file changes, or "Common.h" to see the new headers. Most of the rest of the changes are just the adding of the "(moduleNameUppercase)_LINKAGE" macros to the class and function definitions.</div>
<div>Again, basically, I'm hoping to find out if this mechanism is acceptable, or what alternative I should pursue. A timely response would be appreciated, as I'm pretty much available to work on this full time (for now).</div>
<div> </div>
<div>Thanks.</div>
<p>-John</p></font><br clear="all"><font color="#888888"><br>-- <br>John Thompson<br><a href="mailto:John.Thompson.JTSoftware@gmail.com" target="_blank">John.Thompson.JTSoftware@gmail.com</a><br><br></font></div><br><br clear="all">
<br>-- <br>John Thompson<br><a href="mailto:John.Thompson.JTSoftware@gmail.com">John.Thompson.JTSoftware@gmail.com</a><br><br>