unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [RFC] Use LLVM_BUILD_LLVM_DYLIB instead of BUILD_SHARED_LIBS
@ 2022-04-20 10:56 Zhu Zihao
  2022-08-23  3:57 ` Maxim Cournoyer
  2022-08-26 18:24 ` Maxime Devos
  0 siblings, 2 replies; 5+ messages in thread
From: Zhu Zihao @ 2022-04-20 10:56 UTC (permalink / raw)
  To: Guix Devel

# 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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] Use LLVM_BUILD_LLVM_DYLIB instead of BUILD_SHARED_LIBS
  2022-04-20 10:56 [RFC] Use LLVM_BUILD_LLVM_DYLIB instead of BUILD_SHARED_LIBS Zhu Zihao
@ 2022-08-23  3:57 ` Maxim Cournoyer
  2022-08-26 17:40   ` John Kehayias
  2022-08-26 18:24 ` Maxime Devos
  1 sibling, 1 reply; 5+ messages in thread
From: Maxim Cournoyer @ 2022-08-23  3:57 UTC (permalink / raw)
  To: Zhu Zihao; +Cc: Guix Devel

Hi,

Zhu Zihao <all_but_last@163.com> writes:

> # 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.

[...]

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

That's something I had been meaning to do for some time, but it fell
into the cracks.  I'd welcome this change; you may want to look at
'llvm-cling', which already builds using such flag.

Thanks,

Maxim


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] Use LLVM_BUILD_LLVM_DYLIB instead of BUILD_SHARED_LIBS
  2022-08-23  3:57 ` Maxim Cournoyer
@ 2022-08-26 17:40   ` John Kehayias
  0 siblings, 0 replies; 5+ messages in thread
From: John Kehayias @ 2022-08-26 17:40 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: Zhu Zihao, guix-devel

Hello,

On Mon, Aug 22, 2022 at 11:57 PM, Maxim Cournoyer wrote:

> Zhu Zihao <all_but_last@163.com> writes:
> [...]
>
>> # Solution
>>
>> I suggest to replace `-DBUILD_SHARED_LIBS:BOOL=TRUE` with
>> `-DLLVM_BUILD_LLVM_DYLIB:BOOL=TRUE`.
>
> That's something I had been meaning to do for some time, but it fell
> into the cracks.  I'd welcome this change; you may want to look at
> 'llvm-cling', which already builds using such flag.
>

Just wanted to chime in that I ran across this unexpected configuration when debugging some unrelated issues (had to do with Mesa library loading, so was looking at its dependencies). I think it would be good to follow this more expected and typical configuration for building LLVM, at least as far as I understand it.

John



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] Use LLVM_BUILD_LLVM_DYLIB instead of BUILD_SHARED_LIBS
  2022-04-20 10:56 [RFC] Use LLVM_BUILD_LLVM_DYLIB instead of BUILD_SHARED_LIBS Zhu Zihao
  2022-08-23  3:57 ` Maxim Cournoyer
@ 2022-08-26 18:24 ` Maxime Devos
  2022-09-13  2:57   ` Maxim Cournoyer
  1 sibling, 1 reply; 5+ messages in thread
From: Maxime Devos @ 2022-08-26 18:24 UTC (permalink / raw)
  To: Zhu Zihao, Guix Devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1194 bytes --]


On 20-04-2022 12:56, Zhu Zihao wrote:
> 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.

IIUC, this causes the static libraries to be built, right?

If so, they could be moved into a separate output.

I would prefer to disable static libraries, those cause problems with 
grafts and size usage. If not possible, I would prefer them to be in a 
separate output, to avoid them being used by accident and to reduce the 
closure size of dependents of LLVM that use the shared version.

Greetings,
Maxime.


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] Use LLVM_BUILD_LLVM_DYLIB instead of BUILD_SHARED_LIBS
  2022-08-26 18:24 ` Maxime Devos
@ 2022-09-13  2:57   ` Maxim Cournoyer
  0 siblings, 0 replies; 5+ messages in thread
From: Maxim Cournoyer @ 2022-09-13  2:57 UTC (permalink / raw)
  To: Maxime Devos; +Cc: Zhu Zihao, Guix Devel

Hi Maxime,

Maxime Devos <maximedevos@telenet.be> writes:

> On 20-04-2022 12:56, Zhu Zihao wrote:
>> 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.
>
> IIUC, this causes the static libraries to be built, right?

What the DYLIB build option does is to build a single .so which contains
all of the LLVM libraries instead of having a bunch of differently named
.so around.

It's much simpler to use, and the recommended approach for a shared
library LLVM.

Maxim


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-13  2:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-20 10:56 [RFC] Use LLVM_BUILD_LLVM_DYLIB instead of BUILD_SHARED_LIBS Zhu Zihao
2022-08-23  3:57 ` Maxim Cournoyer
2022-08-26 17:40   ` John Kehayias
2022-08-26 18:24 ` Maxime Devos
2022-09-13  2:57   ` Maxim Cournoyer

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).