This is an archive of the discontinued LLVM Phabricator instance.

Adding llvm-shlib to CMake build system with a few new bells and whistles
ClosedPublic

Authored by beanz on Oct 21 2014, 12:26 PM.

Details

Summary

This patch adds a new CMake build setting LLVM_BUILD_LLVM_DYLIB, which defaults to OFF. When set to ON, this will generate a shared library containing most of LLVM. The contents of the shared library can be overriden by specifying LLVM_DYLIB_COMPONENTS. LLVM_DYLIB_COMPONENTS can be set to a semi-colon delimited list of any LLVM components that you llvm-config can resolve.

On Windows, unless you are using Cygwin, you must specify an explicit symbol export file using LLVM_EXPORTED_SYMBOL_FILE. On Cygwin and all unix-like platforms if you do not specify LLVM_EXPORTED_SYMBOL_FILE, an export file containing only the LLVM C API will be auto-generated from the list of LLVM components specified in LLVM_DYLIB_COMPONENTS.

Diff Detail

Event Timeline

beanz updated this revision to Diff 15202.Oct 21 2014, 12:26 PM
beanz retitled this revision from to Adding llvm-shlib to CMake build system with a few new bells and whistles.
beanz updated this object.
beanz edited the test plan for this revision. (Show Details)
beanz added a subscriber: Unknown Object (MLST).
rnk added a subscriber: rnk.Oct 21 2014, 1:52 PM

At a really high level, I wonder why we don't annotate the entire LLVM C API as attribute((visibility("default"))) / dllexport / whatever is needed on MachO.

tools/llvm-shlib/CMakeLists.txt
54

I'm not sure if this is always correct with funky generators like VS and XCode.

59

Linux (and other OSs) won't add this leading underscore to functions with extern "C" linkage, so nm's output will look like 'T LLVM*'.

59

It looks like you can skip the removal of leading underscores, add_llvm_symbol_exports appears to do this for you on Mac.

beanz added a comment.Oct 21 2014, 2:16 PM

I'm not really sure tagging the C API with default visibility would solve the problem I'm trying to solve. Marking the C API as exported, doesn't mark the C++ API to not be exported - which is what I'm trying to do here.

New patches coming soon, and comments below.

tools/llvm-shlib/CMakeLists.txt
54

I'm not too concerned about VS because generally Windows support will need to be done by someone else. I'm a bit weak WRT Windows development. I'll make sure this does the right thing for Xcode though. I mostly work with SublimeText & Ninja.

59

Good catch. on both of these. I'll update the patches.

beanz added inline comments.Oct 21 2014, 3:40 PM
tools/llvm-shlib/CMakeLists.txt
59

Looking at this further. I do actually need to strip the _. The sed line in add_llvm_symbol_exports actually adds a leading _ so that darwin can be compatible with Linux & Windows export lists that don't have leading underscores.

beanz updated this revision to Diff 15295.Oct 22 2014, 8:39 PM

Fixed generation for Xcode. This should work for VS too if someone wants to take the time to implement the export list generation. I also caught an error I overlooked. I was inadvertently generating an empty static library along side the dylib.

rnk accepted this revision.Oct 23 2014, 9:39 AM
rnk added a reviewer: rnk.

lgtm

I'm sure the awk is broken on some platforms, but this is a good start and we can let people try it and fix it as needed.

tools/llvm-shlib/CMakeLists.txt
2

Can you add a short comment explaining what this library is? It's not as readily apparent as the other tools.

68

Our CMake generally doesn't repeat the contents of the 'if' and 'foreach' clauses. This one doesn't match, so I'd nuke it and the others.

This revision is now accepted and ready to land.Oct 23 2014, 9:39 AM
Diffusion closed this revision.Oct 23 2014, 10:32 AM
Diffusion updated this revision to Diff 15336.

Closed by commit rL220490 (authored by cbieneman).

chapuni added a subscriber: chapuni.Nov 5 2014, 4:29 PM

IMO, I wonder the term "DYLIB" here might be odd. I mis-imagined this were darwin-specific stuff at first.

That said, I don't have better idea for now.

  • Configure provides --enable-shared
  • CMakefiles provides BUILD_SHARED_LIBS.
  • FYI, in past, I tried to introduce LLVM_ENABLE_SHARED. (See D2942).
beanz added a comment.Nov 6 2014, 11:59 AM

I'm not particularly attached to any specific naming. The problem however is that all three major OS types have different nomenclature for the same construct. On Linux they are shared objects (so), on Windows they are dynamically linked libraries (dll), and on Darwin things are even more confusing because they are referred to in documentation as shared libraries, but the extension is dylib which refers to the dynamic linking aspect.

That said, I do see your point that dylib does sound awfully "Darwin". An alternative naming could be LLVM_BUILD_LLVM_SHLIB, which would more clearly map to the llvm-shlib "tool" which generates the library.

rnk added a comment.Nov 6 2014, 3:47 PM

I try to use "DSO" as an OS-neutral term, but it stands for "dynamic shared
object", so it still shows Unix roots.

FYI, it should work also on mingw.

  • binutils nm.exe is shipped by most mingw distros. You may assume nm.exe available also on mingw.
  • It works if awk is available. I have gawk.exe in my msys tree.

I guess it would also work on msvc with a few tweaks.

I suggest to avoid awk|sort|sed. Could we use python here? Just only python is required to build the tree.
I will work for that.