Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 702344

Summary: >sys-devel/clang-9 - add support for default libunwind library (none|libgcc|libunwind)
Product: Gentoo Linux Reporter: David Carlos Manuelda <StormByte>
Component: Current packagesAssignee: LLVM support project <llvm>
Status: UNCONFIRMED ---    
Severity: normal CC: arfrever.fta, sam, telans
Priority: Normal Keywords: EBUILD, PullRequest
Version: unspecified   
Hardware: All   
OS: Linux   
See Also:
Package list:
Runtime testing required: ---
Attachments: clang ebuild
Current ebuild diff

Description David Carlos Manuelda 2019-12-09 14:42:34 UTC
Since Clang9, a new option has been introduced: the usage of a default libunwind library (being those values: none, libgcc and libunwind) being the default none.

The problem is that when enabling default-compiler-rt, in C{,XX}FLAGS it is needed to be added "--unwindlib=libunwind" (or libgcc) and this flag is often filtered out by some ebuilds, causing linkage failures (undefined symbol Unwind_Resume, for example)

Furthermore, in order to get rid of gcc_s if compiler-rt is selected as default, llvm-libunwind must be used instead of libunwind (tested, and currently libunwind gives undefined references to __register_frame and friends, which llvm-libunwind exports but libunwind seems not)

I tested in a local repository modifying the ebuild so when default-compiler-rt is selected, llvm-libunwind is brought as a dep, and also a default CMake variable is set (adding the modifying ebuild as attachment).

Whether I am not sure that this is the best way to aproach this missing option in current ebuild, I think it is fair to be considered for some action in this direction.

Reproducible: Always
Comment 1 David Carlos Manuelda 2019-12-09 14:43:28 UTC
Created attachment 598940 [details]
clang ebuild

Modified ebuild to handle libunwind default
Comment 2 David Carlos Manuelda 2019-12-09 15:32:05 UTC
Created attachment 598950 [details, diff]
Current ebuild diff

Current ebuild diff
Comment 3 David Carlos Manuelda 2019-12-09 17:58:00 UTC
Also, further test seems needed, as it reaches out of my knowledge, because in my test on a stage3 chrooted, when emerging -e world I am getting extraneous SIGSEGV, leading to even a broken gcc.
Comment 4 Theo Anderson 2021-03-03 02:43:00 UTC
Unwind linking issues are fixed for me too when applying the diff attached to the latest Clang ebuilds.

Perhaps compiler-rt SIGSEGV issues should be a different bug, but I experience the same with at least media-gfx/qview::guru
Comment 5 tt_1 2021-03-06 13:19:12 UTC
can you maybe not force abi_x86_32 on amd64 multilib? I only need multilib llvm for media-libs/mesa[llvm] and wine-vanilla subsequently. Or are there any clang related libs ( which will be forced to be build in abi_x86_32 on amd64 multilib with these changes commited?
Comment 6 Theo Anderson 2021-03-06 20:35:03 UTC
Only sys-devel/clang-runtime and the deps:
- sys-libs/libcxxabi
- sys-libs/libcxx
- sys-libs/libomp
- sys-libs/llvm-libunwind

are forced abi_x86_32, not sys-devel/llvm or sys-devel/clang, so no big compile times.
Comment 7 Arfrever Frehtes Taifersar Arahesis 2021-03-07 03:20:09 UTC
I think that __register_frame and __deregister_frame are used so rarely that, instead of forcing sys-libs/llvm-libunwind for default-compiler-rt, it is possible to support both libunwind implementations and add package-specific workarounds where __register_frame and __deregister_frame are actually used.

For some months, I have been using similar patch but with llvm-libunwind USE flag to select between sys-libs/llvm-libunwind and sys-libs/libunwind:

> --- sys-devel/clang/clang-11.1.0.ebuild
> +++ sys-devel/clang/clang-11.1.0.ebuild
> @@ -24,7 +24,7 @@
>  SLOT="$(ver_cut 1)/$(ver_cut 1-2)"
>  KEYWORDS="~amd64 ~arm ~arm64 ~ppc64 ~riscv ~x86 ~amd64-linux ~x64-macos"
>  IUSE="debug default-compiler-rt default-libcxx default-lld
> -     doc +static-analyzer test xml kernel_FreeBSD ${ALL_LLVM_TARGETS[*]}"
> +     doc llvm-libunwind +static-analyzer test xml kernel_FreeBSD ${ALL_LLVM_TARGETS[*]}"
>       || ( ${ALL_LLVM_TARGETS[*]} )"
>  RESTRICT="!test? ( test )"
> @@ -52,7 +52,11 @@
>       sys-devel/clang-common
>       ~sys-devel/clang-runtime-${PV}
> -     default-compiler-rt? ( =sys-libs/compiler-rt-${PV%_*}* )
> +     default-compiler-rt? (
> +             =sys-libs/compiler-rt-${PV%_*}*
> +             llvm-libunwind? ( =sys-libs/llvm-libunwind-${PV%_*}* )
> +             !llvm-libunwind? ( sys-libs/libunwind )
> +     )
>       default-libcxx? ( >=sys-libs/libcxx-${PV} )
>       default-lld? ( sys-devel/lld )"
> @@ -77,6 +81,7 @@
>  # multilib clang* libraries (not runtime, not wrappers).
> +     "${FILESDIR}"/11.0.0/clang-libunwind-as-needed.patch
>       "${FILESDIR}"/9999/prefix-dirs.patch
>  )
> @@ -263,6 +268,7 @@
>               # override default stdlib and rtlib
>               -DCLANG_DEFAULT_CXX_STDLIB=$(usex default-libcxx libc++ "")
>               -DCLANG_DEFAULT_RTLIB=$(usex default-compiler-rt compiler-rt "")
> +             -DCLANG_DEFAULT_UNWINDLIB=$(usex default-compiler-rt libunwind "")
>               -DCLANG_DEFAULT_LINKER=$(usex default-lld lld "")
>               -DCLANG_ENABLE_ARCMT=$(usex static-analyzer)
Comment 8 Arfrever Frehtes Taifersar Arahesis 2021-03-07 03:24:01 UTC
Created attachment 689727 [details, diff]
Comment 9 Arfrever Frehtes Taifersar Arahesis 2021-03-07 03:27:41 UTC
Regarding forcing of abi_x86_32, it may be possible to create llvm subprofiles and force abi_x86_32 for these packagess only in these subprofiles.
Comment 10 Theo Anderson 2021-03-08 19:34:59 UTC
Latest version of PR depends on either sys-libs/llvm-libunwind (first preference) or sys-libs/libunwind