Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 935314 - sys-devel/clang-common: breaks HIP with hardened: __glibcxx_assert_fail in __device__ function
Summary: sys-devel/clang-common: breaks HIP with hardened: __glibcxx_assert_fail in __...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: LLVM support project
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2024-07-01 23:39 UTC by Sv. Lockal
Modified: 2024-07-04 19:08 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sv. Lockal 2024-07-01 23:39:50 UTC
sys-devel/clang-common-18.1.8 with USE=hardened adds the following line to /etc/clang/gentoo-hardened.cfg:

  -D_GLIBCXX_ASSERTIONS


To reproduce:

cat test.cpp

---------------------------------------------

#include <array>
#include <hip/hip_runtime.h>

__global__ void test() {
    std::array<int, 10> x{};
    x[20] = 0;
}

int main()
{
    test<<<dim3(512), dim3(256), 0, 0>>>();
    std::array<int, 10> x{};
    x[20] = 0;
}

---------------------------------------------

hipcc test.cpp -o test && ./test

---------------------------------------------

Expected result: compiles, fails in runtime on host (as GPU has no such thing as glibc assertions).

Actual result: build fails with:

/usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/array:208:2: error: reference to __host__ function '__glibcxx_assert_fail' in __host__ __device__ function
note: called by 'test'
    7 |     x[20] = 0;

---------------------------------------------

Solution: should set `-Xarch_host -D_GLIBCXX_ASSERTIONS` in /etc/clang/gentoo-hardened.cfg
Comment 1 Sv. Lockal 2024-07-01 23:50:29 UTC
Affected line: https://gitweb.gentoo.org/repo/gentoo.git/tree/sys-devel/clang-common/clang-common-18.1.8.ebuild#n252

Note that next line `-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE` is kind of not affected, because hipcc fails with libc++ (probably was never tested).
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-07-01 23:57:00 UTC
I suppose we should -Xarch_host both of them to be safe. Thanks for the report.
Comment 3 Sv. Lockal 2024-07-02 00:47:47 UTC
Sounds good, I'll create PR tomorrow
Comment 4 Larry the Git Cow gentoo-dev 2024-07-04 19:08:01 UTC
The bug has been closed via the following commit(s):

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

commit de01d97d992ee06fa23ed0938cfd32cc0ea34493
Author:     Sv. Lockal <lockalsash@gmail.com>
AuthorDate: 2024-07-04 03:44:33 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-07-04 19:07:10 +0000

    sys-devel/clang-common: add -Xarch_host for hardening flags to fix HIP compilation
    
    Fixes USE=hardened errors like:
    `error: reference to __host__ function '__glibcxx_assert_fail' in __host__ __device__ function`
    
    Closes: https://bugs.gentoo.org/935314
    Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
    Closes: https://github.com/gentoo/gentoo/pull/37420
    Signed-off-by: Sam James <sam@gentoo.org>

 .../clang-common/clang-common-17.0.6-r6.ebuild     | 303 +++++++++++++++++++++
 ...18.1.8.ebuild => clang-common-18.1.8-r1.ebuild} |   4 +-
 .../clang-common/clang-common-19.0.0.9999.ebuild   |   4 +-
 .../clang-common-19.0.0_pre20240630.ebuild         |   4 +-
 4 files changed, 309 insertions(+), 6 deletions(-)