Files
llvm-project/clang/test/CodeGenCUDA/device-stub-macho.cu
Paulius Velesko 264ac2d3af [HIP][MacOS] Mach-O support and Darwin toolchain fixes (#183991)
This PR adds support for HIP on macOS: Mach-O section naming, Darwin
host toolchain initialization guards, and HIPSPV behavior when Darwin is
the host.

This has been verified using chipStar on MacOS via the PoCL OpenCL
implementation.

## Uninitialized target workaround
Darwin’s toolchain is only initialized when its own TranslateArgs runs.
For HIP/CUDA device jobs, Darwin is used as the HostTC and never gets
its args translated, so its target stays uninitialized. The new checks
avoid asserting on that uninitialized state. A better long-term fix is
to initialize Darwin earlier (see the FIXME in Driver.cpp
BuildJobsForAction).

- [ ] Initialize Darwin toolchain during construction instead of lazily
in TranslateArgs. See Driver.cpp BuildJobsForAction FIXME.

- [x] In Darwin’s addClangTargetOptions, skip host-stdlib flags when
DeviceOffloadKind != OFK_None so HIPSPV can safely delegate to the host.
2026-04-28 12:43:59 -05:00

29 lines
1.2 KiB
Plaintext

// Verify that HIP fat binary sections use Mach-O "segment,section" format on Darwin.
// RUN: echo -n "GPU binary would be here." > %t
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.15.0 -emit-llvm %s \
// RUN: -fcuda-include-gpubinary %t -o - -x hip \
// RUN: | FileCheck %s --check-prefix=HIPEF
// RUN: %clang_cc1 -cuid=123 -triple x86_64-apple-macosx10.15.0 -emit-llvm %s \
// RUN: -o - -x hip \
// RUN: | FileCheck %s --check-prefix=HIPNEF
#include "Inputs/cuda.h"
__device__ int device_var;
__constant__ int constant_var;
// When fat binary is embedded, section names use Mach-O format.
// HIPEF: @[[FATBIN:.*]] = private constant{{.*}} c"GPU binary would be here.",{{.*}}section "__HIP,__hip_fatbin"{{.*}}align 4096
// HIPEF: @__hip_fatbin_wrapper = internal constant { i32, i32, ptr, ptr }
// HIPEF-SAME: section "__HIP,__fatbin"
// When fat binary is external (no -fcuda-include-gpubinary), external symbol uses Mach-O section.
// HIPNEF: @[[FATBIN:__hip_fatbin_[0-9a-f]+]] = external constant i8, section "__HIP,__hip_fatbin"
// HIPNEF: @__hip_fatbin_wrapper = internal constant { i32, i32, ptr, ptr }
// HIPNEF-SAME: section "__HIP,__fatbin"
__global__ void kernelfunc(int i, int j, int k) {}
void hostfunc(void) { kernelfunc<<<1, 1>>>(1, 1, 1); }