gentooLTO icon indicating copy to clipboard operation
gentooLTO copied to clipboard

llvm-11 and friends fails with lto

Open hedmo opened this issue 5 years ago • 24 comments

llvm-11 has been released and it fails with. affected packages : ` / # cat /etc/portage/package.cflags/ltolocalworkarounds.conf

BEGIN: LTO workarounds

sys-devel/llvm FLAGS-=-flto sys-devel/clang FLAGS-=-flto sys-libs/libomp FLAGS-=-flto

END: LTO not recommended

/ # `

hedmo avatar Oct 13 '20 06:10 hedmo

Build LLVM/Clang with LLVM/Clang.

perfect7gentleman avatar Oct 13 '20 06:10 perfect7gentleman

Build LLVM/Clang with LLVM/Clang.

what do youn mean?

hedmo avatar Oct 13 '20 06:10 hedmo

Build Clang 11 with Clang 10, same with LLVM.

elsandosgrande avatar Oct 13 '20 07:10 elsandosgrande

++ all LLVM tools and libs

perfect7gentleman avatar Oct 13 '20 07:10 perfect7gentleman

I have successfully built both clang:11 and libomp-11.0.0 with -flto. It's only llvm:11 that fails. It seems to build a broken llvm-tablegen binary which then crashes during the build when it tries to use it to generate files needed to continue building.

I tried switching compiler to clang like this: /etc/portage/env/clang: CC="clang" CXX="clang++" AR="llvm-ar" NM="llvm-nm" RANLIB="llvm-ranlib"

/etc/portage/package.env: sys-devel/llvm clang

Then it builds but clang doesn't recognize any of these flags: -fgraphite-identity -floop-nest-optimize -fdevirtualize-at-ltrans -fno-semantic-interposition -flto=4 -fuse-linker-plugin

So then it builds without lto. As a final test I tried using this instead: /etc/portage/env/clang-lto: CC="clang" CXX="clang++" CFLAGS="${CFLAGS} -flto" CXXFLAGS="${CXXFLAGS} -flto" LDFLAGS="-Wl,-O3 -Wl,--as-needed" AR="llvm-ar" NM="llvm-nm" RANLIB="llvm-ranlib"

Which then tries to build llvm:11 with clang and -flto but then the build fails in the same way (it builds a broken llvm-tablegen which crashes when launched).

AnonymousRetard avatar Oct 13 '20 10:10 AnonymousRetard

I got them to successfully build with LTO by disabling --as-needed for llvm and clang

khuei avatar Oct 13 '20 12:10 khuei

I got them to successfully build with LTO by disabling --as-needed for llvm and clang

Confirm this worked for me and building libomp/llvm/clang-11 with clang-10 allowed libomp to build with LTO.

To whom should a bug report be sent for the no-as-needed switch with llvm/clang?

Ninpo avatar Oct 14 '20 23:10 Ninpo

I can also confirm that building llvm:11 with all flags from this overlay: CFLAGS="-march=znver1 -O3 -fgraphite-identity -floop-nest-optimize -fdevirtualize-at-ltrans -fipa-pta -flto=4 -fuse-linker-plugin -pipe -fomit-frame-pointer -fno-finite-math-only -Wl,-O1" works as long as I remove --as-needed from LDFLAGS. But not if I try to build llvm:11 with clang:11, it only works with GCC 10.2.0. I could also get it to build with clang:11 if I disable LTO but removing --as-needed only works for GCC. With clang:11 it gets me a lot further but it still fails in the final linking step. I have not tried clang:10.

Additionally I never had any problems with building clang, only llvm. As for libomp I have the "cuda" USE-flag enabled for that package which forces me to use <= GCC 9.

AnonymousRetard avatar Oct 15 '20 09:10 AnonymousRetard

I went ahead and disabled LTO on these packages as I'm strapped for time at the moment to deep dive and figure out where they are breaking. Normally LLVM builds fine with LTO, so this is surprising.

InBetweenNames avatar Oct 21 '20 01:10 InBetweenNames

Maybe you can try -flto=thin instead, my setup works fine with this:

/etc/portage/env/compiler-clang.conf:
CC="clang"
CXX="clang++"
AR="llvm-ar"
NM="llvm-nm"
RANLIB="llvm-ranlib"
CFLAGS="-march=native -O3 -pipe -flto=thin"
CXXFLAGS="${CFLAGS} -stdlib=libc++"
LDFLAGS="-Wl,-O2 -Wl,--as-needed -fuse-ld=lld -stdlib=libc++ -rtlib=compiler-rt -unwindlib=libunwind -flto=thin -Wl,--thinlto-jobs=8"
/etc/portage/package.env:
sys-devel/llvm-common compiler-clang.conf
sys-devel/llvm compiler-clang.conf
sys-devel/llvmgold compiler-clang.conf
sys-devel/lld compiler-clang.conf
sys-devel/clang compiler-clang.conf
sys-devel/clang-common compiler-clang.conf
sys-libs/compiler-rt-sanitizers compiler-clang.conf
sys-libs/compiler-rt compiler-clang.conf
sys-devel/clang-runtime compiler-clang.conf
sys-libs/libcxx compiler-clang.conf
sys-libs/libcxxabi compiler-clang.conf
sys-libs/libomp compiler-clang.conf
sys-libs/llvm-libunwind compiler-clang.conf
dev-lang/rust compiler-clang.conf
media-libs/mesa compiler-clang.conf

leandrolnh avatar Oct 21 '20 22:10 leandrolnh

in my opinion.i dont think it is a good idea to mixing compilers.well on local basics it is okay but not global like here in lto-overlay.I went ahead and disabled LTO on these packages as i have more package in my system that has a mix off clang and gcc when it is compiling.BTW i am keeping : sys-devel/llvm *FLAGS-="${IPAPTA}" to just in case.

hedmo avatar Oct 24 '20 08:10 hedmo

they compile fine with clang --flto=full and -fwhole-program-vtables

zkvsky avatar Oct 24 '20 20:10 zkvsky

@barolo , how long will it take to build llvm and clang with -flto=full and -fwhole-program-vtables against -flto=thin ?

perfect7gentleman avatar Oct 25 '20 03:10 perfect7gentleman

@perfect7gentleman genlop says that it took 53 min for llvm and 54 for clang [ multilib ], on my 4 core APU

zkvsky avatar Oct 25 '20 11:10 zkvsky

I'm still getting build failures even with lto disabled

FAILED: include/llvm/IR/IntrinsicsPowerPC.h cd /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_32.x86 && /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_32.x86/bin/llvm-tblgen -gen-intrinsic-enums -intrinsic-prefix=ppc -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm/include/llvm/IR -I /usr/include/libxml2 -I /var/tmp/portage/sys-devel/llvm-11.0.0/work/llvm-11.0.0_build-abi_x86_32.x86/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/IntrinsicsPowerPC.h -d include/llvm/IR/IntrinsicsPowerPC.h.d terminate called after throwing an instance of 'std::system_error' what(): Unknown error -1

https://dpaste.com/FFGJR9WXS

killbox998 avatar Oct 29 '20 16:10 killbox998

so, you wanna say that -flto=1 means it's disabled?

perfect7gentleman avatar Oct 29 '20 16:10 perfect7gentleman

/etc/portage/package.cflags/ltoworkarounds.conf -> sys-devel/llvm: FLAGS-=-flto* # Issue #619 temporarily disabled for now due to build errors

I think it's because it's missing the prefix *, so it should be *FLAGS-=-flto* rather than FLAGS-=-flto*

khuei avatar Oct 29 '20 16:10 khuei

Yeah, That was the issue

killbox998 avatar Oct 29 '20 17:10 killbox998

llvm requires -Wl,--no-as-needed due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55394#c7, fixed in gcc 11. it causes terminate called after throwing an instance of 'std::system_error' what(): Unknown error -1.

Hello71 avatar Dec 16 '20 18:12 Hello71

Testing -Wl,--no-as-needed it's only required for tablegen with sys-devel/llvm and sys-devel/clang and not sys-libs/libomp (when using LTO). Only build difference was libLLVM-11.so being linked to librt.so.

alanswanson avatar Jan 13 '21 16:01 alanswanson

llvm requires -Wl,--no-as-needed due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55394#c7, fixed in gcc 11. it causes terminate called after throwing an instance of 'std::system_error' what(): Unknown error -1.

okej . I Will remove my overides and check .

hedmo avatar Jan 13 '21 16:01 hedmo

i can confirm that llvm-11 and friends compiles with full LTO on gcc-11

hedmo avatar Jan 13 '21 20:01 hedmo

FWIW, this issue is tracked in https://bugs.gentoo.org/749162, and there are patches there available for both LLVM and Clang that have been reported to fix LTO builds with GCC<11.

laomaiweng avatar Apr 08 '21 23:04 laomaiweng

With llvm 16.0.4 I have to turn off IPAPTA or it will fail to build with a stack trace.

Tomte-Fan avatar May 20 '23 10:05 Tomte-Fan