Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 870178 - app-containers/lxc-5.0.1 failed to compile w/ clang
Summary: app-containers/lxc-5.0.1 failed to compile w/ clang
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Joonas Niilola
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: systemwide-clang lto
  Show dependency tree
 
Reported: 2022-09-15 03:23 UTC by Zhixu Liu
Modified: 2022-09-18 07:24 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (emerge-info.txt,5.84 KB, text/plain)
2022-09-16 04:07 UTC, Zhixu Liu
Details
build.log (build.log,18.68 KB, text/plain)
2022-09-16 04:07 UTC, Zhixu Liu
Details
meson-log.txt (meson-log.txt,151.77 KB, text/plain)
2022-09-16 04:08 UTC, Zhixu Liu
Details
patch to change lto mode (a.patch,342 bytes, patch)
2022-09-16 04:09 UTC, Zhixu Liu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zhixu Liu 2022-09-15 03:23:58 UTC
when build lxc w/ clang, the build failed with: 

ERROR: LLVM's thinLTO only works with gnu gold, lld, lld-link, and ld64, not ld.bfd

This is probably a meson issue, but I'm not sure. see https://github.com/mesonbuild/meson/issues/10798

Build temporary fixed by following patch, change LTO mode to default.

diff --git a/meson.build b/meson.build
index 5d1bb36..351f832 100644
--- a/meson.build
+++ b/meson.build
@@ -8,7 +8,7 @@ project(
     license: 'LGPLv2+',
     default_options: [
         'b_lto=true',
-        'b_lto_mode=thin',
+        'b_lto_mode=default',
         'b_colorout=always',
         'b_asneeded=true',
         'b_pie=true',




Reproducible: Always
Comment 1 Stephan Hartmann (RETIRED) gentoo-dev 2022-09-15 07:51:22 UTC
Please attach full build.log and paste emerge --info. Afterwards, please re-open.
Comment 2 Zhixu Liu 2022-09-16 04:07:31 UTC
Created attachment 805411 [details]
emerge --info
Comment 3 Zhixu Liu 2022-09-16 04:07:57 UTC
Created attachment 805414 [details]
build.log
Comment 4 Zhixu Liu 2022-09-16 04:08:17 UTC
Created attachment 805417 [details]
meson-log.txt
Comment 5 Zhixu Liu 2022-09-16 04:09:00 UTC
Created attachment 805420 [details, diff]
patch to change lto mode
Comment 6 Zhixu Liu 2022-09-16 04:10:16 UTC
please see attachments for the required info, thanks.
Comment 7 Joonas Niilola gentoo-dev 2022-09-16 12:53:18 UTC
I don't understand. It doesn't looke like you have lto enabled... do you? I see your emerge --info lists clang as CC so indeed why are you using bfd with clang? 

Anyway I don't seem to have problems, 
# cat /var/db/pkg/app-containers/lxc-5.0.1/CC
clang
# cat /var/db/pkg/app-containers/lxc-5.0.1/CFLAGS 
-march=native -O3 -pipe -flto=thin
Comment 8 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-09-16 13:04:20 UTC
Are you saying that with clang, it tries to automatically use LTO even when you haven't set it yourself?
Comment 9 Joonas Niilola gentoo-dev 2022-09-16 16:35:50 UTC
I can't see lto being enabled anywhere, but I wonder how to print whatever the project forces on. I wonder if this is a meson or lxc bug.

On a GCC system:
# CC="clang" CXX="clang++" emerge -1 lxc --usepkg=n --buildpkg=n
results in
ERROR: LLVM's thinLTO only works with gnu gold, lld, lld-link, and ld64, not ld.bfd

but my meson.log or build.log doesn't show lto being enabled.
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-09-16 16:42:36 UTC
May need environment file from OP too...
Comment 11 Joonas Niilola gentoo-dev 2022-09-16 17:00:14 UTC
So does look like lxc upstream enables lto via meson options:
    default_options: [
        'b_lto=true',
        'b_lto_mode=thin',

but it's meson that gets the thin wrong, I think.
Comment 12 Eli Schwartz 2022-09-16 20:20:57 UTC
lxc's meson.build file sets the default (unless you pass your own -Db_lto=false in MYMESONARGS) value of lto to:

- on
- specifically thin

Meson isn't getting anything "wrong" here, you (that is, the lxc project, not the gentoo bug reporter) explicitly requested something that Meson believes it cannot fulfill, so it raises an error.

Ignoring the mode=thin is IMO not an option -- if you ask for it, Meson shouldn't successfully ignore it.

In mesonbuild/compilers/mixins/clang.py : 

```
        if mode == 'thin':
            # Thin LTO requires the use of gold, lld, ld64, or lld-link
            if not isinstance(self.linker, (AppleDynamicLinker, ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker)):
                raise mesonlib.MesonException(f"LLVM's thinLTO only works with gnu gold, lld, lld-link, and ld64, not {self.linker.id}")
            args.append(f'-flto={mode}')
```

If, as the linked Meson ticket asks about, that is no longer true (you can patch out the middle 3 lines and locally test), then Meson could be changed to enable the clang+bfd combination. But that would require testing and confirmation, and seems unlikely.
Comment 13 Zhixu Liu 2022-09-17 08:31:35 UTC
yes, I 've said that this might be the problem of meson. The issue (https://github.com/mesonbuild/meson/issues/10798) was submited by me too.
But I'm not familar w/ the internals of thinLTO, I did a simple test w/ cland and ldd.bfd, it seems work, but I just can't conclude that the assertion of meson is wrong.

(In reply to Eli Schwartz from comment #12)
> lxc's meson.build file sets the default (unless you pass your own
> -Db_lto=false in MYMESONARGS) value of lto to:
> 
> - on
> - specifically thin
> 
> Meson isn't getting anything "wrong" here, you (that is, the lxc project,
> not the gentoo bug reporter) explicitly requested something that Meson
> believes it cannot fulfill, so it raises an error.
> 
> Ignoring the mode=thin is IMO not an option -- if you ask for it, Meson
> shouldn't successfully ignore it.
> 
> In mesonbuild/compilers/mixins/clang.py : 
> 
> ```
>         if mode == 'thin':
>             # Thin LTO requires the use of gold, lld, ld64, or lld-link
>             if not isinstance(self.linker, (AppleDynamicLinker,
> ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker)):
>                 raise mesonlib.MesonException(f"LLVM's thinLTO only works
> with gnu gold, lld, lld-link, and ld64, not {self.linker.id}")
>             args.append(f'-flto={mode}')
> ```
> 
> If, as the linked Meson ticket asks about, that is no longer true (you can
> patch out the middle 3 lines and locally test), then Meson could be changed
> to enable the clang+bfd combination. But that would require testing and
> confirmation, and seems unlikely.
Comment 14 Larry the Git Cow gentoo-dev 2022-09-18 07:22:49 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c67d9ff4be934959df1ae631fcb9c5c50c7a1faf

commit c67d9ff4be934959df1ae631fcb9c5c50c7a1faf
Author:     Joonas Niilola <juippis@gentoo.org>
AuthorDate: 2022-09-18 07:18:28 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2022-09-18 07:18:28 +0000

    app-containers/lxc: add "lto" use flag
    
     - upstream enables lto unconditionally which causes all kinds of issues for
       us with different linkers available.
    
    Closes: https://bugs.gentoo.org/870178
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 app-containers/lxc/lxc-5.0.1-r1.ebuild | 166 +++++++++++++++++++++++++++++++++
 app-containers/lxc/metadata.xml        |   1 +
 2 files changed, 167 insertions(+)
Comment 15 Joonas Niilola gentoo-dev 2022-09-18 07:24:57 UTC
This should be handled by our ebuild now, but Liu, if you use system-wide clang you should also use lld. The simples way is to emerge sys-devel/clang with +default-lld USE flag configuration.