Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 749162 - sys-devel/llvm-11.0.0: std::call_once fails without -pthread as: terminate called after throwing an instance of 'std::system_error'
Summary: sys-devel/llvm-11.0.0: std::call_once fails without -pthread as: terminate ca...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal with 1 vote (vote)
Assignee: LLVM support project
URL: https://gcc.gnu.org/PR55394
Whiteboard:
Keywords:
: 754891 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-10-15 02:15 UTC by Branko Badrljica
Modified: 2020-12-02 18:07 UTC (History)
9 users (show)

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


Attachments
build.log (build.log.bz2,15.83 KB, application/x-bzip)
2020-10-15 02:16 UTC, Branko Badrljica
Details
emerge --info list (my_emerge.info.bz2,3.47 KB, application/x-bzip2)
2020-10-15 02:17 UTC, Branko Badrljica
Details
debug build.log (build_with_debug.log.bz2,15.99 KB, application/x-bzip2)
2020-10-15 19:57 UTC, Branko Badrljica
Details
Minimal flags failed build.log (build.log,327.31 KB, text/x-log)
2020-10-17 19:18 UTC, Cănărău Constantin
Details
Successful build.log (build.log.tar.bz2,68.31 KB, application/x-bzip)
2020-10-17 19:56 UTC, Cănărău Constantin
Details
llvm-tblgen_linking.patch (llvm-tblgen_linking.patch,500 bytes, patch)
2020-10-22 17:50 UTC, Arfrever Frehtes Taifersar Arahesis
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Branko Badrljica 2020-10-15 02:15:18 UTC
LLVM-11 build croaks during compile.

First failurte in build log is during building header file 
include/llvm/IR/IntrinsicsR600.h
that is to be built from corresponding .h.d file.

And then the slew of similar header build fails follow from there.
All of them being IntrisincsXXX.

I thought it might be related to me usifng gcc-10.2.1_pre9999, so I tried with gcc-9.3.0. With same results.



Reproducible: Always

Steps to Reproduce:
1. emerge =llvm-11*
2.
3.
Actual Results:  
compile step fails


I have attached my build log and output of "emerge --info"
Comment 1 Branko Badrljica 2020-10-15 02:16:31 UTC
Created attachment 665681 [details]
build.log
Comment 2 Branko Badrljica 2020-10-15 02:17:02 UTC
Created attachment 665684 [details]
emerge --info list
Comment 3 Cănărău Constantin 2020-10-15 07:40:05 UTC
I can confirm this issue. 
In ${WORDIR}/include/llvm/IR/ no include file is generated from headers.
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-10-15 10:53:28 UTC
Could you try lowering your CFLAGS and seeing if that changes anything?  You could also try if USE=debug produces a better error message.
Comment 5 Cănărău Constantin 2020-10-15 18:46:17 UTC
(In reply to Michał Górny from comment #4)
> Could you try lowering your CFLAGS and seeing if that changes anything?  You
> could also try if USE=debug produces a better error message.

It is due to -flto, the usual suspect. But I have to admit, this error is different than common flto erros.
Comment 6 Cănărău Constantin 2020-10-15 19:33:33 UTC
I don't know how to debug this:


gentoo /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64 # /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/llvm-tblgen -gen-intrinsic-impl -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/include -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR/Intrinsics.td --write-if-changed -o include/llvm/IR/IntrinsicImpl.inc -d include/llvm/IR/IntrinsicImpl.inc.d
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
Aborted (core dumped)

gentoo /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64 # strace /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/llvm-tblgen -gen-intrinsic-impl -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/include -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR/Intrinsics.td --write-if-changed -o include/llvm/IR/IntrinsicImpl.inc -d include/llvm/IR/IntrinsicImpl.inc.d
execve("/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/llvm-tblgen", ["/var/tmp/portage/sys-devel/llvm-"..., "-gen-intrinsic-impl", "-I", "/var/tmp/portage/sys-devel/llvm-"..., "-I", "/var/tmp/portage/sys-devel/llvm-"..., "-I", "/var/tmp/portage/sys-devel/llvm-"..., "/var/tmp/portage/sys-devel/llvm-"..., "--write-if-changed", "-o", "include/llvm/IR/IntrinsicImpl.in"..., "-d", "include/llvm/IR/IntrinsicImpl.in"...], 0x7ffd7c816048 /* 42 vars */) = 0
brk(NULL)                               = 0x5625d0e93000
readlink("/proc/self/exe", "/var/tmp/portage/sys-devel/llvm-"..., 4096) = 94
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/tls/haswell/x86_64/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/tls/haswell/x86_64", 0x7ffd416f1ab0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/tls/haswell/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/tls/haswell", 0x7ffd416f1ab0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/tls/x86_64/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/tls/x86_64", 0x7ffd416f1ab0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/tls/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/tls", 0x7ffd416f1ab0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/haswell/x86_64/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/haswell/x86_64", 0x7ffd416f1ab0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/haswell/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/haswell", 0x7ffd416f1ab0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/x86_64/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/x86_64", 0x7ffd416f1ab0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=115588, ...}) = 0
mmap(NULL, 115588, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa6d9dde000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\340\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=244640, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa6d9ddc000
mmap(NULL, 248616, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa6d9d9f000
mprotect(0x7fa6d9dad000, 172032, PROT_NONE) = 0
mmap(0x7fa6d9dad000, 102400, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe000) = 0x7fa6d9dad000
mmap(0x7fa6d9dc6000, 65536, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x27000) = 0x7fa6d9dc6000
mmap(0x7fa6d9dd7000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x37000) = 0x7fa6d9dd7000
close(3)                                = 0
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \21\n\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2519248, ...}) = 0
mmap(NULL, 2535104, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa6d9b34000
mprotect(0x7fa6d9bd1000, 1806336, PROT_NONE) = 0
mmap(0x7fa6d9bd1000, 1130496, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x9d000) = 0x7fa6d9bd1000
mmap(0x7fa6d9ce5000, 671744, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b1000) = 0x7fa6d9ce5000
mmap(0x7fa6d9d8a000, 73728, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x255000) = 0x7fa6d9d8a000
mmap(0x7fa6d9d9c000, 11968, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fa6d9d9c000
close(3)                                = 0
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/libm.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\322\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1255208, ...}) = 0
mmap(NULL, 1257496, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa6d9a00000
mmap(0x7fa6d9a0d000, 577536, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xd000) = 0x7fa6d9a0d000
mmap(0x7fa6d9a9a000, 622592, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x9a000) = 0x7fa6d9a9a000
mmap(0x7fa6d9b32000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x131000) = 0x7fa6d9b32000
close(3)                                = 0
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0203\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=100520, ...}) = 0
mmap(NULL, 103496, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa6d99e6000
mmap(0x7fa6d99e9000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7fa6d99e9000
mmap(0x7fa6d99fa000, 16384, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14000) = 0x7fa6d99fa000
mmap(0x7fa6d99fe000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7fa6d99fe000
close(3)                                = 0
openat(AT_FDCWD, "/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/../lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@?\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1805928, ...}) = 0
mmap(NULL, 1819504, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa6d9829000
mprotect(0x7fa6d984b000, 1642496, PROT_NONE) = 0
mmap(0x7fa6d984b000, 1331200, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7fa6d984b000
mmap(0x7fa6d9990000, 307200, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x167000) = 0x7fa6d9990000
mmap(0x7fa6d99dc000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b2000) = 0x7fa6d99dc000
mmap(0x7fa6d99e2000, 13168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fa6d99e2000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa6d9827000
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa6d9824000
arch_prctl(ARCH_SET_FS, 0x7fa6d9824740) = 0
mprotect(0x7fa6d99dc000, 16384, PROT_READ) = 0
mprotect(0x7fa6d99fe000, 4096, PROT_READ) = 0
mprotect(0x7fa6d9b32000, 4096, PROT_READ) = 0
mprotect(0x7fa6d9d8a000, 53248, PROT_READ) = 0
mprotect(0x7fa6d9dd7000, 16384, PROT_READ) = 0
mprotect(0x5625d0169000, 32768, PROT_READ) = 0
mprotect(0x7fa6d9e25000, 4096, PROT_READ) = 0
munmap(0x7fa6d9dde000, 115588)          = 0
brk(NULL)                               = 0x5625d0e93000
brk(0x5625d0eb4000)                     = 0x5625d0eb4000
write(2, "terminate called after throwing "..., 48terminate called after throwing an instance of ') = 48
write(2, "std::system_error", 17std::system_error)       = 17
write(2, "'\n", 2'
)                      = 2
write(2, "  what():  ", 11  what():  )             = 11
write(2, "Unknown error -1", 16Unknown error -1)        = 16
write(2, "\n", 1
)                       = 1
rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0
getpid()                                = 115652
gettid()                                = 115652
tgkill(115652, 115652, SIGABRT)         = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=115652, si_uid=0} ---
+++ killed by SIGABRT (core dumped) +++
Aborted (core dumped)
Comment 7 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-10-15 19:39:26 UTC
My rough guess would be that GCC miscompiles it somehow.  This exception probably comes from libstdc++ but your strace doesn't suggest any failing syscalls, so it might be a misfire somewhere.  You could try building with -O0 -g, and then rerunning the command under gdb to see a backtrace.
Comment 8 Branko Badrljica 2020-10-15 19:56:51 UTC
It's compiling it with LTO that fails.
Compile with non-LTO flag works.
I have attached build log, made with USE="debug".
Comment 9 Branko Badrljica 2020-10-15 19:57:59 UTC
Created attachment 665918 [details]
debug build.log
Comment 10 Cănărău Constantin 2020-10-16 06:34:27 UTC
It doesn't fail with -O0, but fail with -O1:

FEATURES="-fail-clean" CFLAGS="-O1 -g -pipe -march=native -w -ftree-vectorize -flto=auto" CXXFLAGS="-O1 -g -pipe -march=native -w -ftree-vectorize -flto=auto" LDFLAGS="-Wl,-O1,--sort-common,--hash-style=gnu,--enable-new-dtags,--as-needed,-z,relro,-z,now -flto=auto" emerge -O1 -j1 llvm

mini /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64 # gdb --args /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/llvm-tblgen -gen-attrs -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/include -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR/Attributes.td --write-if-changed -o include/llvm/IR/Attributes.inc -d include/llvm/IR/Attributes.inc.d
GNU gdb (Gentoo 9.2 vanilla) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.gentoo.org/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/llvm-tblgen...
(gdb) 
(gdb) run
Starting program: /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/llvm-tblgen -gen-attrs -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/include -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR/Attributes.td --write-if-changed -o include/llvm/IR/Attributes.inc -d include/llvm/IR/Attributes.inc.d
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1

Program received signal SIGABRT, Aborted.
0x00007ffff7a24301 in raise () from /lib64/libc.so.6
(gdb) trace
Tracepoint 1 at 0x7ffff7a24301
(gdb) backtrace
#0  0x00007ffff7a24301 in raise () from /lib64/libc.so.6
#1  0x00007ffff7a0d536 in abort () from /lib64/libc.so.6
#2  0x00007ffff7da18dc in ?? () from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6
#3  0x00007ffff7dd0976 in ?? () from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6
#4  0x00007ffff7dd09e1 in std::terminate() () from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6
#5  0x00007ffff7dd0c83 in __cxa_throw () from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6
#6  0x00007ffff7da4a29 in std::__throw_system_error(int) () from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6
#7  0x000055555572029b in std::call_once<void (&)()> (__once=..., __f=@0x55555571ff96: {void (void)} 0x55555571ff96 <initializeMutex()>) at /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include/g++-v10/x86_64-pc-linux-gnu/bits/gthr-default.h:700
#8  0x0000555555722b5c in llvm::call_once<void (&)()> (F=@0x55555571ff96: {void (void)} 0x55555571ff96 <initializeMutex()>, flag=...) at /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/Support/Threading.h:119
#9  getManagedStaticMutex () at /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/lib/Support/ManagedStatic.cpp:29
#10 llvm::ManagedStaticBase::RegisterManagedStatic (this=0x555555800040 <_ZL12GlobalParser.lto_priv.0>, Creator=0x5555557185f6 <llvm::object_creator<(anonymous namespace)::CommandLineParser>::call()>, 
    Deleter=0x5555557176a0 <llvm::object_deleter<(anonymous namespace)::CommandLineParser>::call(void*)>) at /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/lib/Support/ManagedStatic.cpp:37
#11 0x0000555555718d08 in llvm::ManagedStatic<(anonymous namespace)::CommandLineParser, llvm::object_creator<(anonymous namespace)::CommandLineParser>, llvm::object_deleter<(anonymous namespace)::CommandLineParser> >::operator* (this=0x555555800040 <_ZL12GlobalParser.lto_priv.0>)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include/g++-v10/bits/atomic_base.h:741
#12 0x000055555571549d in llvm::ManagedStatic<(anonymous namespace)::CommandLineParser, llvm::object_creator<(anonymous namespace)::CommandLineParser>, llvm::object_deleter<(anonymous namespace)::CommandLineParser> >::operator-> (this=<optimized out>)
    at /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/Support/ManagedStatic.h:94
#13 llvm::cl::Option::addArgument (this=0x555555802900 <_ZL14OutputFilename.lto_priv.0>) at /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/lib/Support/CommandLine.cpp:445
#14 0x000055555577defe in _sub_I_65535_0.0 ()
#15 0x00005555557818dd in __libc_csu_init ()
#16 0x00007ffff7a0ed9a in __libc_start_main () from /lib64/libc.so.6
#17 0x000055555556caaa in _start ()
(gdb) 

The relevant issue seems to be  
#5  0x00007ffff7dd0c83 in __cxa_throw () from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6

I am working on Object Pascal (Lazarus) and as web developer. Not very familiarized with C/C++. It is anything that I can do to help ?
Comment 11 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-10-16 07:19:55 UTC
The most relevant code is this:

  static void initializeMutex() {
    ManagedStaticMutex = new std::recursive_mutex();
  }

I can't imagine why that would fail under normal circumstances.  Given that it depends on optimization level, I think it's 90% a bug in GCC.
Comment 12 Branko Badrljica 2020-10-16 07:33:08 UTC
If it's about gcc bug, that would be one persistent bug.
It fails with gcc-9.3.0 and 10.2.1_pre9999 in exact same way.
Comment 13 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-10-16 07:42:51 UTC
I wouldn't be surprised if LLVM was the first package to hit.  LLVM is good in using C++ to its extent.
Comment 14 Cănărău Constantin 2020-10-16 11:09:45 UTC
We have a test machine and it seems that error occurred somewhere between llvm-11.0.0_rc3 and llvm-11.0.0_rc6. But, right now, both llvm-11.0.0-rc3 and 4 fail with same error.
So tried with gcc-10.2.0-r1 and error is no more.

Fortunately, we are talking about up to 3 gcc+llvm recompile to bisect:

gentoo /mnt/linux/backup/distfiles # LC_MESSAGES=C diff -ur patch2 patch3 
diff -ur patch2/28_all_EXTRA_OPTIONS-fstack-clash-protection.patch patch3/28_all_EXTRA_OPTIONS-fstack-clash-protection.patch
--- patch2/28_all_EXTRA_OPTIONS-fstack-clash-protection.patch	2020-08-23 12:14:51.000000000 +0300
+++ patch3/28_all_EXTRA_OPTIONS-fstack-clash-protection.patch	2020-10-02 12:25:53.000000000 +0300
@@ -30,7 +30,7 @@
     vtable entries.  Setting this nonzero tells the compiler to use
     function descriptors instead.  The value of this macro says how
 --- a/gcc/toplev.c	2018-02-13 17:18:37.000000000 +0100
-+++ b/toplev.c	2018-04-30 16:46:37.244027303 +0200
++++ b/gcc/toplev.c	2018-04-30 16:46:37.244027303 +0200
 @@ -1682,6 +1682,10 @@ process_options (void)
  
    /* -fstack-clash-protection is not currently supported on targets
Only in patch3: 37_all_c-vector-init-PR96377.patch
Only in patch3: 38_all_gcov-TOPN-PR96913.patch
Only in patch3: 39_all_ipa-prop-multispec.patch

If somebody can make an educated guest to pinpoint to error, please do so. I'll look at 9.3.0 latest patches to try to reduce number of test and will start to bisect, but it won't be fast.
Comment 15 Cănărău Constantin 2020-10-16 13:09:37 UTC
I don't know what is this about.
It didn't failed with 28_all_EXTRA_OPTIONS-fstack-clash-protection.patch and 37_all_c-vector-init-PR96377.patch, but failed with both or individual 38_all_gcov-TOPN-PR96913.patch and 39_all_ipa-prop-multispec.patch.

What is unusual: it fails now with *original* 10.2.0-r1 patch2 which is untouched. Refetched it just to be sure.
I tough that I made a error, but genlop -t llvm confirmed that at first try with gcc-10.2.0-r1 llvm was compiled with lto.

Any hint, explication ?
Comment 16 Sergei Trofimovich gentoo-dev 2020-10-16 15:55:16 UTC
llvm-11 builds fine for me on -O3 -march=native=flto.

So far I see only one emerge --info with -march=native in CFLAGS.

Try to find minimum amount of options deviating from defaults needed to reproduce the failure. The usual avenues are:

1. Expand your -march=native with https://wiki.gentoo.org/wiki/Gcc-ICE-reporting-guide#Expand_-march.3Dnative.2C_exact_gcc_version_and_other_system-specific_options and make sure the error is still present on expanded CFLAGS
2. Remove as many unrelated CFLAGS/CXXFLAGS/LDFLAGS as possible (-O2 is ok to leave as is).
3. Remove as many unrelated USE-flags as possible (like, ABI_X86=32).

That way toolchain@ will get better chance to reproduce the failure.
Comment 17 Cănărău Constantin 2020-10-17 10:56:08 UTC
I was unable to find a flags combinations to make llvm-11 to compile with lto. It fail with just -O|1|2|3 -pipe -flto, with -march=x86_64 or native.
The only way to make it to compile is to drop -flto.
Comment 18 Sam James archtester gentoo-dev Security 2020-10-17 10:57:03 UTC
(In reply to Cănărău Constantin from comment #17)
> I was unable to find a flags combinations to make llvm-11 to compile with
> lto. It fail with just -O|1|2|3 -pipe -flto, with -march=x86_64 or native.
> The only way to make it to compile is to drop -flto.

Expanded -march=native is required for us.
Comment 19 Sergei Trofimovich gentoo-dev 2020-10-17 11:19:22 UTC
(In reply to Cănărău Constantin from comment #17)
> I was unable to find a flags combinations to make llvm-11 to compile with
> lto. It fail with just -O|1|2|3 -pipe -flto, with -march=x86_64 or native.
> The only way to make it to compile is to drop -flto.

Please provide emerge --info and build.log for minimal '-O2 -flto' case.
Comment 20 Cănărău Constantin 2020-10-17 14:25:03 UTC
The trigger of error is in LDFLAGS, not in C(XX)FLAGS. I was able to successfully compile llvm-11.0.0 with lto.

Requested info:
Expanded flags list:

gentoo ~ # arch=skylake; for t in param target; do cmd="gcc -Q -O2 -march=$arch --help=$t"; diff -U0 <(LANG=C $cmd) <(LANG=C $cmd -march=native); done
--- /dev/fd/63	2020-10-17 16:30:57.242137544 +0300
+++ /dev/fd/62	2020-10-17 16:30:57.243137586 +0300
@@ -70,3 +70,3 @@
-  --param=l1-cache-line-size= 		32
-  --param=l1-cache-size=      		64
-  --param=l2-cache-size=      		512
+  --param=l1-cache-line-size= 		64
+  --param=l1-cache-size=      		32
+  --param=l2-cache-size=      		8192
--- /dev/fd/61	2020-10-17 16:30:57.350142024 +0300
+++ /dev/fd/60	2020-10-17 16:30:57.350142024 +0300
@@ -12 +12 @@
-  -mabm                       		[disabled]
+  -mabm                       		[enabled]
@@ -15,2 +15,2 @@
-  -madx                       		[disabled]
-  -maes                       		[disabled]
+  -madx                       		[enabled]
+  -maes                       		[enabled]
@@ -26,2 +26,2 @@
-  -mavx                       		[disabled]
-  -mavx2                      		[disabled]
+  -mavx                       		[enabled]
+  -mavx2                      		[enabled]
@@ -48,2 +48,2 @@
-  -mbmi                       		[disabled]
-  -mbmi2                      		[disabled]
+  -mbmi                       		[enabled]
+  -mbmi2                      		[enabled]
@@ -55 +55 @@
-  -mclflushopt                		[disabled]
+  -mclflushopt                		[enabled]
@@ -61 +61 @@
-  -mcx16                      		[disabled]
+  -mcx16                      		[enabled]
@@ -65 +65 @@
-  -mf16c                      		[disabled]
+  -mf16c                      		[enabled]
@@ -70 +70 @@
-  -mfma                       		[disabled]
+  -mfma                       		[enabled]
@@ -76 +76 @@
-  -mfsgsbase                  		[disabled]
+  -mfsgsbase                  		[enabled]
@@ -79 +79 @@
-  -mfxsr                      		[disabled]
+  -mfxsr                      		[enabled]
@@ -84 +84 @@
-  -mhle                       		[disabled]
+  -mhle                       		[enabled]
@@ -99 +99 @@
-  -mlzcnt                     		[disabled]
+  -mlzcnt                     		[enabled]
@@ -104,2 +104,2 @@
-  -mmmx                       		[disabled]
-  -mmovbe                     		[disabled]
+  -mmmx                       		[enabled]
+  -mmovbe                     		[enabled]
@@ -117 +117 @@
-  -mno-sse4                   		[enabled]
+  -mno-sse4                   		[disabled]
@@ -123 +123 @@
-  -mpclmul                    		[disabled]
+  -mpclmul                    		[enabled]
@@ -127 +127 @@
-  -mpopcnt                    		[disabled]
+  -mpopcnt                    		[enabled]
@@ -132 +132 @@
-  -mprfchw                    		[disabled]
+  -mprfchw                    		[enabled]
@@ -136,2 +136,2 @@
-  -mrdrnd                     		[disabled]
-  -mrdseed                    		[disabled]
+  -mrdrnd                     		[enabled]
+  -mrdseed                    		[enabled]
@@ -145,3 +145,3 @@
-  -mrtm                       		[disabled]
-  -msahf                      		[disabled]
-  -msgx                       		[disabled]
+  -mrtm                       		[enabled]
+  -msahf                      		[enabled]
+  -msgx                       		[enabled]
@@ -152,2 +152,2 @@
-  -msse                       		[disabled]
-  -msse2                      		[disabled]
+  -msse                       		[enabled]
+  -msse2                      		[enabled]
@@ -155,4 +155,4 @@
-  -msse3                      		[disabled]
-  -msse4                      		[disabled]
-  -msse4.1                    		[disabled]
-  -msse4.2                    		[disabled]
+  -msse3                      		[enabled]
+  -msse4                      		[enabled]
+  -msse4.1                    		[enabled]
+  -msse4.2                    		[enabled]
@@ -162 +162 @@
-  -mssse3                     		[disabled]
+  -mssse3                     		[enabled]
@@ -175 +175 @@
-  -mtune=                     		
+  -mtune=                     		skylake
@@ -186,4 +186,4 @@
-  -mxsave                     		[disabled]
-  -mxsavec                    		[disabled]
-  -mxsaveopt                  		[disabled]
-  -mxsaves                    		[disabled]
+  -mxsave                     		[enabled]
+  -mxsavec                    		[enabled]
+  -mxsaveopt                  		[enabled]
+  -mxsaves                    		[enabled]


emerge --info

gentoo ~ # emerge --info llvm
Portage 3.0.8 (python 3.9.0-final-0, default/linux/amd64/17.1/no-multilib, gcc-10.2.0, glibc-2.32-r2, 5.9.0-gentoo-costel x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-5.9.0-gentoo-costel-x86_64-Intel-R-_Core-TM-_i7-6700K_CPU_@_4.00GHz-with-glibc2.32
KiB Mem:    32751472 total,  25934040 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Sat, 17 Oct 2020 07:45:01 +0000
Head commit of repository gentoo: 2ba4e811c5fbf1a925210f8b43e2f7cdb9baee84
sh bash 5.0_p18
ld GNU ld (Gentoo 2.35.1 p1) 2.35.1
app-shells/bash:          5.0_p18::gentoo
dev-java/java-config:     2.3.1::python
dev-lang/perl:            5.32.0-r1::gentoo
dev-lang/python:          3.9.0-r1::newer
dev-util/cmake:           3.18.4::gentoo
sys-apps/baselayout:      2.7::gentoo
sys-apps/sandbox:         2.20::gentoo
sys-devel/autoconf:       2.69-r5::gentoo
sys-devel/automake:       1.16.2::gentoo
sys-devel/binutils:       2.35.1::gentoo
sys-devel/gcc:            10.2.0-r2::gentoo
sys-devel/gcc-config:     2.3.2::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.3::gentoo
sys-kernel/linux-headers: 5.9::gentoo (virtual/os-headers)
sys-libs/glibc:           2.32-r2::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: rsync
    sync-uri: rsync://rsync.ro.gentoo.org/gentoo-portage/
    priority: -1000
    sync-rsync-verify-jobs: 4
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-metamanifest: yes
    sync-rsync-vcs-ignore: true
    sync-rsync-extra-opts: --human-readable --delete-before --progress

added
    location: /var/db/repos/added
    masters: gentoo
    priority: 100

gnome
    location: /var/db/repos/gnome
    masters: gentoo
    priority: 100

newer
    location: /var/db/repos/newer
    masters: gentoo
    priority: 100

python
    location: /var/db/repos/python
    masters: gentoo
    priority: 100

Installed sets: @desktop, @dev, @minimal, @vpn, @xfce
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta -fno-semantic-interposition -fdevirtualize-at-ltrans -fno-plt"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php7.4/ext-active/ /etc/php/cgi-php7.4/ext-active/ /etc/php/cli-php7.4/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta -fno-semantic-interposition -fdevirtualize-at-ltrans -fno-plt"
DISTDIR="/mnt/linux/distfiles"
EMERGE_DEFAULT_OPTS="--jobs=3 --load-average=9 --keep-going --with-bdeps=y --complete-graph --quiet-build=n --autounmask-write"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs candy cgroup collision-protect config-protect-if-modified distlocks fail-clean fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news nodoc noinfo parallel-fetch parallel-install pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-filter unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://mirrors.xservers.ro/gentoo/ http://distfiles.gentoo.org/"
INSTALL_MASK="/usr/share/locale -/usr/share/locale/ro -/usr/share/locale/en -/usr/share/locale/en_US"
LANG="ro_RO.UTF-8"
LC_ALL="ro_RO.UTF-8"
LDFLAGS="-Wl,-O1,--sort-common,--hash-style=gnu,--enable-new-dtags,--as-needed,-z,relro,-z,now -flto=auto"
MAKEOPTS="-j8 --load-average=10"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_EXTRA_OPTS="--human-readable --delete-before --progress"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X aac acl acpi aes alsa amd64 avx avx2 berkdb branding bzip2 cairo caps cli crypt dbus dri encode f16c fam flac fma3 fortran gdbm gif gpm gtk gtk3 iconv icu ipv6 jpeg jpeg2k libglvnd libtirpc lm-sensors lz4 mmx mmxext mp3 mpeg ncurses networkmanager nls nptl ogg opengl openmp opus pam pango pclmul pcre pdf png policykit popcnt portaudio pulseaudio readline seccomp server split-usr sse sse2 sse3 sse4_1 sse4_2 ssl ssse3 svg systemd tcpd theora threads tiff truetype udev udisks unicode usb vaapi vdpau vhosts vorbis vulkan webp x264 xattr zlib zstd" ABI_X86="64" ADA_TARGET="gnat_2018" ALSA_CARDS="hda-intel usb-audio" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput" KERNEL="linux" L10N="ro en" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LLVM_TARGETS="BPF NVPTX X86" NGINX_MODULES_HTTP="access auth_basic autoindex browser charset fastcgi geoip2 gunzip gzip limit_conn limit_req memcached naxsi realip referer rewrite split_clients ssi userid" NGINX_MODULES_STREAM="access geoip2 limit_conn realip" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_9" PYTHON_TARGETS="python3_9" RUBY_TARGETS="ruby27" USERLAND="GNU" VIDEO_CARDS="intel i965 nvidia" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS

=================================================================
                        Package Settings
=================================================================

sys-devel/llvm-11.0.0::gentoo was built with the following:
USE="libffi ncurses -debug -doc -exegesis -gold -libedit -test -xar -xml -z3" LLVM_TARGETS="BPF NVPTX (X86) -AArch64 -AMDGPU -ARC -ARM -AVR -Hexagon -Lanai -MSP430 -Mips -PowerPC -RISCV -Sparc -SystemZ -VE -WebAssembly -XCore"
CFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta -fdevirtualize-at-ltrans -fno-plt"
CXXFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta -fdevirtualize-at-ltrans -fno-plt"
FEATURES="noinfo unknown-features-filter binpkg-logs candy news unmerge-logs unmerge-orphans userfetch collision-protect keepwork sandbox qa-unresolved-soname-deps merge-sync ipc-sandbox preserve-libs xattr distlocks sfperms pid-sandbox multilib-strict config-protect-if-modified usersync parallel-fetch assume-digests strict protect-owned network-sandbox nodoc userpriv usersandbox fixlafiles unknown-features-warn parallel-install cgroup binpkg-docompress binpkg-dostrip"
LDFLAGS="-Wl,-O1 -flto=auto"

I will report back when I'll found the responsable ldflag.
Comment 21 Cănărău Constantin 2020-10-17 15:02:22 UTC
It seems that llvm-11 fail with -flto and --as-needed.
as-needed is present in the original reporter flags.

gentoo ~ # emerge --info llvm
Portage 3.0.8 (python 3.9.0-final-0, default/linux/amd64/17.1/no-multilib, gcc-10.2.0, glibc-2.32-r2, 5.9.0-gentoo-costel x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-5.9.0-gentoo-costel-x86_64-Intel-R-_Core-TM-_i7-6700K_CPU_@_4.00GHz-with-glibc2.32
KiB Mem:    32751472 total,  29670572 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Sat, 17 Oct 2020 07:45:01 +0000
Head commit of repository gentoo: 2ba4e811c5fbf1a925210f8b43e2f7cdb9baee84
sh bash 5.0_p18
ld GNU ld (Gentoo 2.35.1 p1) 2.35.1
app-shells/bash:          5.0_p18::gentoo
dev-java/java-config:     2.3.1::python
dev-lang/perl:            5.32.0-r1::gentoo
dev-lang/python:          3.9.0-r1::newer
dev-util/cmake:           3.18.4::gentoo
sys-apps/baselayout:      2.7::gentoo
sys-apps/sandbox:         2.20::gentoo
sys-devel/autoconf:       2.69-r5::gentoo
sys-devel/automake:       1.16.2::gentoo
sys-devel/binutils:       2.35.1::gentoo
sys-devel/gcc:            10.2.0-r2::gentoo
sys-devel/gcc-config:     2.3.2::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.3::gentoo
sys-kernel/linux-headers: 5.9::gentoo (virtual/os-headers)
sys-libs/glibc:           2.32-r2::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: rsync
    sync-uri: rsync://rsync.ro.gentoo.org/gentoo-portage/
    priority: -1000
    sync-rsync-verify-jobs: 4
    sync-rsync-extra-opts: --human-readable --delete-before --progress
    sync-rsync-verify-max-age: 24
    sync-rsync-vcs-ignore: true
    sync-rsync-verify-metamanifest: yes

added
    location: /var/db/repos/added
    masters: gentoo
    priority: 100

gnome
    location: /var/db/repos/gnome
    masters: gentoo
    priority: 100

newer
    location: /var/db/repos/newer
    masters: gentoo
    priority: 100

python
    location: /var/db/repos/python
    masters: gentoo
    priority: 100

Installed sets: @desktop, @dev, @minimal, @vpn, @xfce
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta -fno-semantic-interposition -fdevirtualize-at-ltrans -fno-plt"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php7.4/ext-active/ /etc/php/cgi-php7.4/ext-active/ /etc/php/cli-php7.4/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta -fno-semantic-interposition -fdevirtualize-at-ltrans -fno-plt"
DISTDIR="/mnt/linux/distfiles"
EMERGE_DEFAULT_OPTS="--jobs=3 --load-average=9 --keep-going --with-bdeps=y --complete-graph --quiet-build=n --autounmask-write"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs candy cgroup collision-protect config-protect-if-modified distlocks fail-clean fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news nodoc noinfo parallel-fetch parallel-install pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-filter unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://mirrors.xservers.ro/gentoo/ http://distfiles.gentoo.org/"
INSTALL_MASK="/usr/share/locale -/usr/share/locale/ro -/usr/share/locale/en -/usr/share/locale/en_US"
LANG="ro_RO.UTF-8"
LC_ALL="ro_RO.UTF-8"
LDFLAGS="-Wl,-O1,--sort-common,--hash-style=gnu,--enable-new-dtags,--as-needed,-z,relro,-z,now -flto=auto"
MAKEOPTS="-j8 --load-average=10"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_EXTRA_OPTS="--human-readable --delete-before --progress"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X aac acl acpi aes alsa amd64 avx avx2 berkdb branding bzip2 cairo caps cli crypt dbus dri encode f16c fam flac fma3 fortran gdbm gif gpm gtk gtk3 iconv icu ipv6 jpeg jpeg2k libglvnd libtirpc lm-sensors lz4 mmx mmxext mp3 mpeg ncurses networkmanager nls nptl ogg opengl openmp opus pam pango pclmul pcre pdf png policykit popcnt portaudio pulseaudio readline seccomp server split-usr sse sse2 sse3 sse4_1 sse4_2 ssl ssse3 svg systemd tcpd theora threads tiff truetype udev udisks unicode usb vaapi vdpau vhosts vorbis vulkan webp x264 xattr zlib zstd" ABI_X86="64" ADA_TARGET="gnat_2018" ALSA_CARDS="hda-intel usb-audio" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput" KERNEL="linux" L10N="ro en" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LLVM_TARGETS="BPF NVPTX X86" NGINX_MODULES_HTTP="access auth_basic autoindex browser charset fastcgi geoip2 gunzip gzip limit_conn limit_req memcached naxsi realip referer rewrite split_clients ssi userid" NGINX_MODULES_STREAM="access geoip2 limit_conn realip" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_9" PYTHON_TARGETS="python3_9" RUBY_TARGETS="ruby27" USERLAND="GNU" VIDEO_CARDS="intel i965 nvidia" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS

=================================================================
                        Package Settings
=================================================================

sys-devel/llvm-11.0.0::gentoo was built with the following:
USE="libffi ncurses -debug -doc -exegesis -gold -libedit -test -xar -xml -z3" LLVM_TARGETS="BPF NVPTX (X86) -AArch64 -AMDGPU -ARC -ARM -AVR -Hexagon -Lanai -MSP430 -Mips -PowerPC -RISCV -Sparc -SystemZ -VE -WebAssembly -XCore"
CFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta -fdevirtualize-at-ltrans -fno-plt"
CXXFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta -fdevirtualize-at-ltrans -fno-plt"
FEATURES="parallel-install cgroup preserve-libs unmerge-logs unknown-features-warn sfperms config-protect-if-modified binpkg-dostrip noinfo unknown-features-filter binpkg-docompress binpkg-logs multilib-strict nodoc network-sandbox news sandbox usersync qa-unresolved-soname-deps userpriv protect-owned xattr parallel-fetch usersandbox userfetch collision-protect unmerge-orphans fixlafiles strict ipc-sandbox candy merge-sync pid-sandbox distlocks assume-digests"
LDFLAGS="-Wl,-O1,--sort-common,--hash-style=gnu,--enable-new-dtags,-z,relro,-z,now -flto=auto"
Comment 22 Sergei Trofimovich gentoo-dev 2020-10-17 17:57:28 UTC
I suggest following #comment16 to get minimal amount of flags added to defaults needed to reproduce the failure.
Comment 23 Cănărău Constantin 2020-10-17 19:18:34 UTC
Created attachment 666311 [details]
Minimal flags failed build.log

It fails with -flto in C(XX)FLAGS and --as-needed in LDFLAGS.
Attached failed build.log with:
 
CFLAGS="-O2 -pipe -flto=auto"
CXXFLAGS="-O2 -pipe -flto=auto"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -flto=auto"

Reproductible for me on Intel 6700K and on AMD Ryzen 3 3200G.

It builds fine without -Wl,--as-needed:
CFLAGS="-O2 -pipe -flto=auto"
CXXFLAGS="-O2 -pipe -flto=auto"
LDFLAGS="-Wl,-O1 -flto=auto"
Comment 24 Cănărău Constantin 2020-10-17 19:56:56 UTC
Created attachment 666320 [details]
Successful build.log

CFLAGS='-O2 -pipe -flto=auto'
CXXFLAGS='-O2 -pipe -flto=auto'
LDFLAGS='-Wl,-O1 -flto=auto'

It builds fine without --as-needed
Comment 25 Sergei Trofimovich gentoo-dev 2020-10-17 21:22:58 UTC
(In reply to Cănărău Constantin from comment #23)
> Created attachment 666311 [details]
> Minimal flags failed build.log
> 
> It fails with -flto in C(XX)FLAGS and --as-needed in LDFLAGS.
> Attached failed build.log with:
>  
> CFLAGS="-O2 -pipe -flto=auto"
> CXXFLAGS="-O2 -pipe -flto=auto"
> LDFLAGS="-Wl,-O1 -Wl,--as-needed -flto=auto"
> 
> Reproductible for me on Intel 6700K and on AMD Ryzen 3 3200G.
> 
> It builds fine without -Wl,--as-needed:
> CFLAGS="-O2 -pipe -flto=auto"
> CXXFLAGS="-O2 -pipe -flto=auto"
> LDFLAGS="-Wl,-O1 -flto=auto"

Thank you!

Given that crash happens in libstdc++ can you rebuild your active gcc with these same options to make sure it's not a leftover from old options?

If crash disappears you might need to do find new set of flags against gcc.
Comment 26 Cănărău Constantin 2020-10-18 10:16:48 UTC
I rebuild gcc with 
1. With
CFLAGS='-O2 -pipe -flto=auto'
CXXFLAGS='-O2 -pipe -flto=auto'
LDFLAGS='-Wl,-O1 -flto=auto'

2. With  
CFLAGS="-O2 -pipe -flto=auto"
CXXFLAGS="-O2 -pipe -flto=auto"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -flto=auto"

3. With  
CFLAGS="-O2 -pipe -flto=auto -march=native"
CXXFLAGS="-O2 -pipe -flto=auto -march=native"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -flto=auto"

4. My normal flags:
CFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta -fno-semantic-interposition -fdevirtualize-at-ltrans -fno-plt"
CXXFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta -fno-semantic-interposition -fdevirtualize-at-ltrans -fno-plt"
LDFLAGS="-Wl,-O1 -Wl,--sort-common -Wl,--hash-style=gnu -Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,relro,-z,now -flto=auto"


=================================================================
                        Package Settings
=================================================================

sys-devel/gcc-10.2.0-r2::gentoo was built with the following:
USE="(cxx) graphite lto nls nptl openmp pch pgo (pie) sanitize ssp vtv zstd (-ada) -d -debug -doc (-fixed-point) -fortran -go (-hardened) -jit (-libssp) (-multilib) -objc -objc++ -objc-gc -systemtap -test -vanilla"
CFLAGS="-pipe -march=native -w -O2"
CXXFLAGS="-pipe -march=native -w -O2"
FEATURES="sandbox distlocks unmerge-logs protect-owned cgroup strict qa-unresolved-soname-deps unknown-features-filter usersync xattr collision-protect usersandbox network-sandbox userpriv fixlafiles news pid-sandbox preserve-libs userfetch assume-digests ipc-sandbox merge-sync binpkg-docompress parallel-install sfperms binpkg-logs noinfo multilib-strict binpkg-dostrip nodoc parallel-fetch unknown-features-warn candy config-protect-if-modified unmerge-orphans fail-clean"
LDFLAGS="-Wl,-O1 -Wl,--sort-common -Wl,--hash-style=gnu -Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,relro,-z,now"

toolchain.eclass (I presume) strip down flags to bare minimum, anyway, and original reporter use CFLAGS="-march=native -pipe -O3 -flto  -fuse-linker-plugin"

I tried, also, without pgo and lto useflags.
The result remains the same: -flto and --as-needed make llvm to fail to compile. 

I am fully aware that before to solve a problem it is necessary to be able to reproduce the scenario, but I don't know what else to try next to isolate the issue.
I think it would help if Branko Badrljica or somebody else could confirm that removing as-needed solves the issue in his case.
If there is something else you suggest to try, please tell me.
Comment 27 Sergei Trofimovich gentoo-dev 2020-10-18 12:07:31 UTC
(In reply to Cănărău Constantin from comment #26)
> I rebuild gcc with 
> 1. With
> CFLAGS='-O2 -pipe -flto=auto'
> CXXFLAGS='-O2 -pipe -flto=auto'
> LDFLAGS='-Wl,-O1 -flto=auto'
> 
> 2. With  
> CFLAGS="-O2 -pipe -flto=auto"
> CXXFLAGS="-O2 -pipe -flto=auto"
> LDFLAGS="-Wl,-O1 -Wl,--as-needed -flto=auto"
> 
> 3. With  
> CFLAGS="-O2 -pipe -flto=auto -march=native"
> CXXFLAGS="-O2 -pipe -flto=auto -march=native"
> LDFLAGS="-Wl,-O1 -Wl,--as-needed -flto=auto"
> 
> 4. My normal flags:
> CFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32
> -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta
> -fno-semantic-interposition -fdevirtualize-at-ltrans -fno-plt"
> CXXFLAGS="-O2 -pipe -march=native -w -ftree-vectorize -falign-functions=32
> -fgraphite-identity -floop-nest-optimize -flto=auto -fipa-pta
> -fno-semantic-interposition -fdevirtualize-at-ltrans -fno-plt"
> LDFLAGS="-Wl,-O1 -Wl,--sort-common -Wl,--hash-style=gnu
> -Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,relro,-z,now -flto=auto"

What was the result? Did llvm rebuild crashes happen on each of [1.]/[2.]/[3.]?
Comment 28 Cănărău Constantin 2020-10-18 17:59:57 UTC
Yes, llvm keeps failed to compile with -flto and --as-needed.
Comment 29 Sergei Trofimovich gentoo-dev 2020-10-18 18:16:56 UTC
Thank you!

Reproduced successfully when rebuilt gcc with USE="lto pgo". Will explore in more detail.
Comment 30 Sergei Trofimovich gentoo-dev 2020-10-18 18:59:06 UTC
The crash happens within global constructors awhile attempting to initialize synchronization primitives. It's probably very sensitive to constructor call order.

Here is the full backtrace:

(gdb) run
Starting program: /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/bin/llvm-tblgen -gen-attrs -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_64.amd64/include -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR/Attributes.td --write-if-changed -o include/llvm/IR/Attributes.inc -d include/llvm/IR/Attributes.inc.d
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1

Program received signal SIGABRT, Aborted.
0x00007ffff7a3af41 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff7a3af41 in raise () from /lib64/libc.so.6
#1  0x00007ffff7a24536 in abort () from /lib64/libc.so.6
#2  0x00007ffff7db48d7 in ?? () from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6
#3  0x00007ffff7de3776 in ?? () from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6
#4  0x00007ffff7de37e1 in std::terminate() ()
   from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6
#5  0x00007ffff7de3a74 in __cxa_throw ()
   from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6
#6  0x00007ffff7db7a49 in std::__throw_system_error(int) ()
   from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/libstdc++.so.6
#7  0x000055555571c1e5 in std::call_once<void (&)()> (__once=...,
    __f=@0x55555571beec: {void (void)} 0x55555571beec <initializeMutex()>)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include/g++-v10/x86_64-pc-linux-gnu/bits/gthr-default.h:700
#8  0x000055555571ea7a in llvm::call_once<void (&)()> (
    F=@0x55555571beec: {void (void)} 0x55555571beec <initializeMutex()>, flag=...)
    at /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/Support/Threading.h:119
#9  getManagedStaticMutex ()
    at /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/lib/Support/ManagedStatic.cpp:29
#10 llvm::ManagedStaticBase::RegisterManagedStatic (
    this=0x5555557fc580 <_ZL12GlobalParser.lto_priv.0>,
    Creator=0x55555571459d <llvm::object_creator<(anonymous namespace)::CommandLineParser>::call()>,
    Deleter=0x555555713654 <llvm::object_deleter<(anonymous namespace)::CommandLineParser>::call(void*)>)
    at /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/lib/Support/ManagedStatic.cpp:37
#11 0x0000555555714cc2 in llvm::ManagedStatic<(anonymous namespace)::CommandLineParser, llvm::object_creator<(anonymous namespace)::CommandLineParser>, llvm::object_deleter<(anonymous namespace)::CommandLineParser> >::operator* (
    this=0x5555557fc580 <_ZL12GlobalParser.lto_priv.0>)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include/g++-v10/bits/atomic_base.h:741
#12 0x00005555557114c7 in llvm::ManagedStatic<(anonymous namespace)::CommandLineParser, llvm::object_creator<(anonymous namespace)::CommandLineParser>, llvm::object_deleter<(anonymous namespace)::CommandLineParser> >::operator-> (this=<optimized out>)
    at /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/Support/ManagedStatic.h:94
#13 llvm::cl::Option::addArgument (this=0x5555557fee40 <_ZL14OutputFilename.lto_priv.0>)
    at /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/lib/Support/CommandLine.cpp:445
#14 0x0000555555779787 in _sub_I_65535_0.0 ()
#15 0x000055555577d0d5 in __libc_csu_init ()
#16 0x00007ffff7a25e3a in __libc_start_main () from /lib64/libc.so.6
#17 0x000055555556caaa in _start ()
Comment 31 Sergei Trofimovich gentoo-dev 2020-10-18 22:21:37 UTC
Has something to do with std::call_once implementation in case when libpthread.so.0 is not linked in (single-trheaded library).

https://stackoverflow.com/questions/50751421/undefined-behavior-in-shared-lib-using-libpthread-but-not-having-it-in-elf-as-d has relevant discussion.

Tl;DR is lack of libpthread.so.0 presence in DT_NEEDED in final binary in bad case and presence in good case.

It's still not clear to me why lack of libpthread.so.0 causes breakage.
Comment 32 Sergei Trofimovich gentoo-dev 2020-10-19 06:49:36 UTC
The breakage appeared in glibc-2.32 probably after
"""
* The GNU C Library now provides the header file <sys/single_threaded.h>
  which declares the variable __libc_single_threaded.  Applications are
  encouraged to use this variable for single-thread optimizations,
  instead of weak references to symbols historically defined in
  libpthread.
"""

gcc's stdc++ tries to detect optional pthread linking via weak symbols presence. But libc.so.6 provides non-weak symbols nowadays.

Small reproducer:

$ cat a.cc
#include <mutex>

static std::once_flag of;
static std::recursive_mutex * pm = nullptr;

int main() {
    std::call_once(of, []() { pm = new std::recursive_mutex; });
}
$ g++-10.2.0 a.cc -o a
$ ./a
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
Comment 33 Sergei Trofimovich gentoo-dev 2020-10-19 07:02:41 UTC
(In reply to Sergei Trofimovich from comment #32)
> The breakage appeared in glibc-2.32 probably after

glibc-2.29 system behaves the same.
Comment 34 Sergei Trofimovich gentoo-dev 2020-10-19 07:29:23 UTC
Filed https://gcc.gnu.org/PR97485 upstream to find out if it's a bug or feature.

meanwhile llvm will need to add -pthread to llvm-tblgen as a workaround.
Comment 35 Sergei Trofimovich gentoo-dev 2020-10-19 22:34:51 UTC
(In reply to Sergei Trofimovich from comment #34)
> Filed https://gcc.gnu.org/PR97485 upstream to find out if it's a bug or
> feature.
> 
> meanwhile llvm will need to add -pthread to llvm-tblgen as a workaround.

Due to https://gcc.gnu.org/PR55394 it will require explicit '-Wl,--no-as-needed -pthread' or equivalent.
Comment 36 Sergei Trofimovich gentoo-dev 2020-10-20 22:55:27 UTC
Also filed https://sourceware.org/PR26762 to consider changing ld's preference of weak-local/strong-remote alternatives.
Comment 37 Arfrever Frehtes Taifersar Arahesis 2020-10-21 00:26:07 UTC
(In reply to Sergei Trofimovich from comment #35)
> Due to https://gcc.gnu.org/PR55394 it will require explicit
> '-Wl,--no-as-needed -pthread' or equivalent.

Better to use --no-as-needed only for one library:

-Wl,--push-state -Wl,--no-as-needed -pthread -Wl,--pop-state
Comment 38 Amit Ugol 2020-10-22 16:43:12 UTC
Can confirm that this worked for me (I have a haswell cpu so...)

# grep llvm /etc/portage/package.env 
sys-devel/llvm compiler-gcc-llvm

# cat /etc/portage/env/compiler-gcc-llvm 
COMMON_FLAGS="-flto -O3 -march=haswell -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
LDFLAGS="-Wl,-O1 -Wl,--no-as-needed"
Comment 39 Arfrever Frehtes Taifersar Arahesis 2020-10-22 17:50:31 UTC
Created attachment 667976 [details, diff]
llvm-tblgen_linking.patch

Please test this patch which sets --no-as-needed only for llvm-tblgen tool.
Comment 40 Cănărău Constantin 2020-10-23 08:43:04 UTC
The patch is ok. Thank you!
It is possible that clang with xml USEFLAG to be affected by this issue. I am using clang only on Raspberry Pi, for firefox.
Comment 41 Cănărău Constantin 2020-10-23 09:09:48 UTC
[27/1579] cd /var/tmp/portage/sys-devel/clang-11.0.0/work/x/y/clang-abi_x86_64.amd64 && /var/tmp/portage/sys-devel/clang-11.0.0/work/x/y/clang-abi_x86_64.amd64/bin/clang-tblgen -gen-clang-data-collectors -I /var/tmp/portage/sys-devel/clang-11.0.0/work/clang/include/clang/AST -I /var/tmp/portage/sys-devel/clang-11.0.0/work/clang/include -I /var/tmp/portage/sys-devel/clang-11.0.0/work/x/y/clang-abi_x86_64.amd64/include -I /include -I /usr/lib/llvm/11/include /var/tmp/portage/sys-devel/clang-11.0.0/work/clang/include/clang/AST/StmtDataCollectors.td --write-if-changed -o include/clang/AST/StmtDataCollectors.inc -d include/clang/AST/StmtDataCollectors.inc.d
FAILED: include/clang/AST/StmtDataCollectors.inc 

Yes, same error, reproduced on amd64. It *not* depends on xml useflag.
The above patch approach worked for clang, too.
Comment 42 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-11-16 23:55:17 UTC
*** Bug 754891 has been marked as a duplicate of this bug. ***
Comment 43 Stefano 2020-11-30 11:23:07 UTC
Same here, I think.

emerge fails with:

[2574/2575] : && /usr/bin/x86_64-pc-linux-gnu-g++ -m32 -fPIC -march=native -O2 -pipe -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections  -Wl,-O1 -Wl,--as-needed -Wl,-z,defs -Wl,-z,nodelete   -Wl,-rpath-link,/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_32.x86/./lib  -Wl,-O3 -Wl,--gc-sections  -Wl,--version-script,"/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_32.x86/tools/lto/LTO.exports" -shared -Wl,-soname,libLTO.so.11 -o lib/libLTO.so.11 tools/lto/CMakeFiles/LTO.dir/LTODisassembler.cpp.o tools/lto/CMakeFiles/LTO.dir/lto.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib"  lib/libLLVM-11.so && :
FAILED: lib/libLTO.so.11 
: && /usr/bin/x86_64-pc-linux-gnu-g++ -m32 -fPIC -march=native -O2 -pipe -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections  -Wl,-O1 -Wl,--as-needed -Wl,-z,defs -Wl,-z,nodelete   -Wl,-rpath-link,/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_32.x86/./lib  -Wl,-O3 -Wl,--gc-sections  -Wl,--version-script,"/var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_32.x86/tools/lto/LTO.exports" -shared -Wl,-soname,libLTO.so.11 -o lib/libLTO.so.11 tools/lto/CMakeFiles/LTO.dir/LTODisassembler.cpp.o tools/lto/CMakeFiles/LTO.dir/lto.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib"  lib/libLLVM-11.so && :
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: tools/lto/CMakeFiles/LTO.dir/lto.cpp.o: in function `lto_initialize()':
lto.cpp:(.text._ZL14lto_initializev+0x71): undefined reference to `LLVMInitializeVETargetInfo'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: lto.cpp:(.text._ZL14lto_initializev+0xd0): undefined reference to `LLVMInitializeVETargetInfo'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: lto.cpp:(.text._ZL14lto_initializev+0x12f): undefined reference to `LLVMInitializeVETarget'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: lto.cpp:(.text._ZL14lto_initializev+0x18e): undefined reference to `LLVMInitializeVETargetMC'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: lto.cpp:(.text._ZL14lto_initializev+0x23d): undefined reference to `LLVMInitializeVEAsmPrinter'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: lto.cpp:(.text._ZL14lto_initializev+0x29c): undefined reference to `LLVMInitializeVEDisassembler'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: tools/lto/CMakeFiles/LTO.dir/LTODisassembler.cpp.o: in function `lto_initialize_disassembler':
LTODisassembler.cpp:(.text.lto_initialize_disassembler+0x38): undefined reference to `LLVMInitializeVETargetInfo'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: LTODisassembler.cpp:(.text.lto_initialize_disassembler+0x97): undefined reference to `LLVMInitializeVETargetMC'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: LTODisassembler.cpp:(.text.lto_initialize_disassembler+0x146): undefined reference to `LLVMInitializeVEDisassembler'
collect2: error: ld returned 1 exit status


$ emerge --info
Portage 3.0.9 (python 3.7.9-final-0, default/linux/amd64/17.1/desktop/plasma, gcc-9.3.0, glibc-2.32-r2, 5.8.18-gentoo x86_64)
=================================================================
System uname: Linux-5.8.18-gentoo-x86_64-Intel-R-_Core-TM-_i7-10750H_CPU_@_2.60GHz-with-gentoo-2.7
KiB Mem:    32628392 total,  10738932 free
KiB Swap:  131071996 total, 131071996 free
Timestamp of repository gentoo: Sun, 29 Nov 2020 10:30:01 +0000
Head commit of repository gentoo: f1f6458e4780457bc1626070719672d55fc1d60e
sh bash 5.0_p18
ld GNU ld (Gentoo 2.34 p6) 2.34.0
ccache version 3.7.12 [disabled]
app-shells/bash:          5.0_p18::gentoo
dev-java/java-config:     2.3.1::gentoo
dev-lang/perl:            5.30.3::gentoo
dev-lang/python:          2.7.18-r4::gentoo, 3.6.12::gentoo, 3.7.9::gentoo, 3.8.6::gentoo, 3.9.0::gentoo
dev-util/ccache:          3.7.12::gentoo
dev-util/cmake:           3.17.4-r1::gentoo
sys-apps/baselayout:      2.7::gentoo
sys-apps/openrc:          0.42.1::gentoo
sys-apps/sandbox:         2.20::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r5::gentoo
sys-devel/automake:       1.13.4-r2::gentoo, 1.16.2-r1::gentoo
sys-devel/binutils:       2.34-r2::gentoo
sys-devel/gcc:            9.3.0-r1::gentoo
sys-devel/gcc-config:     2.3.2-r1::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.2.1-r4::gentoo
sys-kernel/linux-headers: 5.4-r1::gentoo (virtual/os-headers)
sys-libs/glibc:           2.32-r2::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-verify-jobs: 1
    sync-rsync-extra-opts: 
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-metamanifest: yes

steam-overlay
    location: /var/lib/layman/steam-overlay
    masters: gentoo
    priority: 50

sublime-text
    location: /var/lib/layman/sublime-text
    masters: gentoo
    priority: 50

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /etc/stunnel/stunnel.conf /usr/lib64/libreoffice/program/sofficerc /usr/share/config /usr/share/gnupg/qualified.txt /usr/share/themes/oxygen-gtk/gtk-2.0 /usr/share/themes/oxygen-gtk/gtk-3.0"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=native -O2 -pipe"
DISTDIR="/var/cache/distfiles"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://gentoo.modulix.net/gentoo/ ftp://mirror.netcologne.de/gentoo/ rsync://mirror.leaseweb.com/gentoo/"
LANG="it_IT.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j12"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X a52 aac acl acpi activities alsa amd64 archive arts async bash-completion berkdb branding bzip2 cairo cardbus cli crypt cryptsetup css cups curlwrappers dbus declarative dell dga dhcp directfb djbfft dri dts dvb dvd dvdr elogind emboss encode exif fat fbcon fbsplash fftw flac foomaticdb fortran fpx ftp gdbm gif glibc-omitfp gnutls gphoto2 gpm gs gtk gui gzip hostonly hpn hybrid-auth iconv icq icu idea ieee1394 imagemagick imap ios ipod iproute2 ipv6 irda jabber javascript john jpeg jpeg2k jumbo-build kde kipi kpathsea kwallet lapack laptop lcdfilter libglvnd libnotify libtirpc lilo lm_sensors mad mbox messages mime mmap mmx mmxext mng mozilla mp3 mp4 mpeg mplayer msn multilib mysqli nagios-dns ncurses nls nocd nptl nsplugin ntfs ntlm nvidia octave ogg opengl optimization optimized-qmake oscar pam pango pcapnav pcmcia pcntl pcre pda pdf perl phonon plasma pm-utils png policykit posix ppds pulseaudio python qml qt5 radius rdesktop readline replytolist samba scanner seccomp semantic-desktop sharedmem silc slp sms sockets sox spell split-usr sse sse2 sse3 sse4 sse4_1 sse4_2 sse4a ssl ssse3 startup-notification svg sysfs sysvipc tcpd threads tiff truetype udev udisks uefi unicode upower usb userlocales v4l v4l2 vcd vorbis widgets wifi winbind wps wxwidgets x264 xcb xcomposite xml xmlrpc xv xvid xvmc yahoo zlib" ABI_X86="64" ADA_TARGET="gnat_2018" ALSA_CARDS="hda-intel" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="efi-64" INPUT_DEVICES="evdev synaptics libinput v4l" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-2 php7-3 php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_7" PYTHON_TARGETS="python2_7 python3_7" RUBY_TARGETS="ruby25 ruby26" USERLAND="GNU" VIDEO_CARDS="i965 intel iris nvidia" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 44 Cănărău Constantin 2020-11-30 11:59:23 UTC
I am using attached llvm-tblgen_linking.patch for llvm and this for clang:

--- /llvm/utils/TableGen/CMakeLists.txt
+++ /llvm/utils/TableGen/CMakeLists.txt
@@ -56,5 +56,8 @@
   WebAssemblyDisassemblerEmitter.cpp
   CTagsEmitter.cpp
   )
-target_link_libraries(llvm-tblgen PRIVATE LLVMTableGenGlobalISel)
+target_link_libraries(llvm-tblgen PRIVATE LLVMTableGenGlobalISel
+  # Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55394
+  -Wl,--push-state,--no-as-needed -lpthread -Wl,--pop-state
+  )
 set_target_properties(llvm-tblgen PROPERTIES FOLDER "Tablegenning")

Disclaimer: llvm and clang build and run fine *for me*, but I don't fully understand this issue. So no guaranties - use it on your own risk.
Comment 45 Arfrever Frehtes Taifersar Arahesis 2020-11-30 20:14:15 UTC
GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55394) is supposedly fixed in GCC 11.

Would anybody like to install GCC 11 to test if installation of LLVM and Clang is actually fixed with GCC 11 without additional patches?
Comment 46 m1027 2020-12-01 12:37:08 UTC
(In reply to Arfrever Frehtes Taifersar Arahesis from comment #45)
> GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55394) is supposedly
> fixed in GCC 11.
> 
> Would anybody like to install GCC 11 to test if installation of LLVM and
> Clang is actually fixed with GCC 11 without additional patches?

What I did:

emerge sys-devel/gcc:11

gcc --version

gcc (Gentoo 11.0.0_pre9999 p4, commit 76ab0317cfb3201b9b68db9e8a0ced4f4e9f6cd4) 11.0.0 20201201 (experimental)

# re-enabling lto for llvm via package.env

emerge llvm:11

Result: Building does not fail anymore with lto enabled now.