Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 927752 - sys-devel/clang-common-18.1.2-r1[cet] breaks HIP code
Summary: sys-devel/clang-common-18.1.2-r1[cet] breaks HIP code
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: LLVM support project
URL:
Whiteboard:
Keywords: PullRequest
: 927738 927763 927908 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-03-24 20:47 UTC by Sv. Lockal
Modified: 2024-04-08 14:53 UTC (History)
7 users (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-03-24 20:47:45 UTC
With CET flags, Clang fails to compile hip code

  cd /tmp && wget https://raw.githubusercontent.com/ROCm-Developer-Tools/HIP-CPU/master/examples/vadd_hip/vadd_hip.cpp

  # -fcf-protection=full is added by sys-devel/clang-common
/usr/lib/llvm/18/bin/clang++ --offload-arch=native -x hip vadd_hip.cpp -o vadd_hip -fno-stack-protector --hip-link -nogpulib

  error: option 'cf-protection=return' cannot be specified on this target


Reported to LLVM here - https://github.com/llvm/llvm-project/issues/86450. However after report I immediately remembered another solution. /etc/clang/gentoo-hardened.cfg can contain:

  -Xarch_device -fstack-clash-protection
  -Xarch_device -fstack-protector-strong
  -Xarch_device -fPIE
  -include "/usr/include/gentoo/fortify.h"
  -Xarch_device -fcf-protection=full

This might look messy for those who view "clang -v" output, but it makes compilation transparent, so we won't patch every HIP project like this: https://github.com/gentoo/gentoo/pull/34869#issuecomment-2016833430

And maybe in some distant future, when Gentoo drops Clang 18, if Clang would be smart enough to differentiate between GPU and CPU flags, then Gentoo can drop -Xarch_device.
Comment 1 Sv. Lockal 2024-03-24 21:07:22 UTC
Ouch, copy&paste error my previous comment. Please use -Xarch_host ...
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-03-25 19:19:50 UTC
Could you make a PR please?
Comment 3 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2024-03-26 05:50:07 UTC
*** Bug 927738 has been marked as a duplicate of this bug. ***
Comment 4 Larry the Git Cow gentoo-dev 2024-03-26 13:40:10 UTC
The bug has been closed via the following commit(s):

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

commit a026c9c2fc47f40331bad89a40d2e953a8a90a79
Author:     Sv. Lockal <lockalsash@gmail.com>
AuthorDate: 2024-03-26 10:54:31 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2024-03-26 13:36:40 +0000

    sys-devel/clang-common: add -Xarch_host to fix GPU compilation
    
    Add -Xarch_host to CPU-specific flags, so that it does not affects
    heterogenous code (e. g. HIP).
    
    For stack-protector flags: fixes compiler crashes like
    https://github.com/llvm/llvm-project/issues/83777.  Clang 18.1.0 does
    not try to apply these flags to GPU code, but current ROCm libraries use
    Clang 17, so add "-Xarch_host" there too.  This will allow to drop
    "-fno-stack-protector" patches from rocm-comgr, hip and hipcc
    eventually.
    
    For -fcf-protection: fixes error: option 'cf-protection=return' cannot
    be specified on this target.
    
    For -fPIE: do not touch, as at least since Clang 15 it only affects host
    relocation model.  See also:
    https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/clang/test/Driver/hip-fpie-option.hip
    
    Bug: https://github.com/llvm/llvm-project/issues/86450
    Closes: https://bugs.gentoo.org/927752
    Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
    Closes: https://github.com/gentoo/gentoo/pull/35926
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 .../clang-common/clang-common-15.0.7-r8.ebuild     | 185 ++++++++++++++++++++
 .../clang-common/clang-common-16.0.6-r3.ebuild     | 191 +++++++++++++++++++++
 ...0.6-r2.ebuild => clang-common-17.0.6-r3.ebuild} |   6 +-
 ...1.2-r1.ebuild => clang-common-18.1.2-r2.ebuild} |   6 +-
 .../clang-common/clang-common-19.0.0.9999.ebuild   |   6 +-
 ...d => clang-common-19.0.0_pre20240322-r1.ebuild} |   6 +-
 6 files changed, 388 insertions(+), 12 deletions(-)
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2024-03-26 17:00:47 UTC
*** Bug 927908 has been marked as a duplicate of this bug. ***
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-03-28 04:06:42 UTC
*** Bug 927763 has been marked as a duplicate of this bug. ***
Comment 7 Yury Zhuravlev 2024-04-08 14:53:00 UTC
Sorry, it's not fix dev-libs/libclc and break mesa rusticl OpenCL implementation as well.
Comment 8 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-04-08 14:53:31 UTC
(In reply to Yury Zhuravlev from comment #7)
> Sorry, it's not fix dev-libs/libclc and break mesa rusticl OpenCL
> implementation as well.

Please file a new bug for that.