guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC] Use LLVM_BUILD_LLVM_DYLIB instead of BUILD_SHARED_LIBS


From: Zhu Zihao
Subject: [RFC] Use LLVM_BUILD_LLVM_DYLIB instead of BUILD_SHARED_LIBS
Date: Sat, 20 Aug 2022 06:02:48 -0000
User-agent: mu4e 1.6.10; emacs 27.2

# Background

Now in Guix. LLVM is built with configure flag
"-DBUILD_SHARED_LIBS:BOOL=TRUE". According to
https://llvm.org/docs/CMake.html. Build LLVM with `BUILD_SHARED_LIBS` is
not recommended for non LLVM developing usage. LLVM says that packager
should use `LLVM_BUILD_LLVM_DYLIB` instead.

The main difference between `LLVM_BUILD_LLVM_DYLIB` and
`BUILD_SHARED_LIBS` is the former one will generate a monolith shared
library called `libLLVM.so` and the latter will generate individual
libLLVMCore.so libLLVMXXX.so ...

# Issue

`BUILD_SHARED_LIBS` works for us now. But this configure flags will
violates some setup of the cmake script of LLVM.

LLVM components provides an cmake option called `LLVM_LINK_LLVM_DYLIB`
to let user to choose whether dynamically linked or not. Our build
breaks this option.

In lib/cmake/llvm/AddOCaml.cmake:69

```
  if(LLVM_LINK_LLVM_DYLIB)
    list(APPEND ocaml_flags "-lLLVM")
  else()
```

If the add_ocaml_library function is used and `LLVM_LINK_LLVM_DYLIB` is
set to true, it'll tries to link the libLLVM.so which is not provided by
us.

This issue also exists for add_llvm_library.


Though this looks like the issue of LLVM, because `llvm-config`
executable works well for us: if you pass `--link-static` to
llvm-config, it will complain that static archive files is not found.
And if pass `--link-shared`, it can generate the command args that link
to individual shared library.

# Solution

I suggest to replace `-DBUILD_SHARED_LIBS:BOOL=TRUE` with
`-DLLVM_BUILD_LLVM_DYLIB:BOOL=TRUE`.

# Cons

We may introduce following problems if we apply this solution.

1. Increase the closure size of LLVM.

By default, if LLVM_BUILD_LLVM_DYLIB is set true, LLVM still tries to
build the static archive. This may increase the closure size of LLVM.
And some package linking with LLVM may use the static archive instead of
linking to the dynamic library.

My opinion: If we're OK with the bigger closure size, that's not a
problem. If not, we may consider disable the static archive generation.
For LLVM components, we can use `LLVM_LINK_LLVM_DYLIB` to ask these
packages to link with the shared version. For package use `llvm-config`
directly or indirectly, we can pass `--link-shared` to it.

-- 
Retrieve my PGP public key:

  gpg --recv-keys D47A9C8B2AE3905B563D9135BE42B352A9F6821F

Zihao




reply via email to

[Prev in Thread] Current Thread [Next in Thread]