diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake index 2c3cf116fc860..709acd9ad614f 100644 --- a/libc/cmake/modules/LLVMLibCObjectRules.cmake +++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake @@ -278,7 +278,9 @@ function(_build_gpu_objects fq_target_name internal_target_name) target_compile_options(${internal_target_name} BEFORE PRIVATE ${common_compile_options} --target=${LIBC_GPU_TARGET_TRIPLE}) if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) - target_compile_options(${internal_target_name} PRIVATE -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto) + target_compile_options(${internal_target_name} PRIVATE + "SHELL:-Xclang -mcode-object-version=none" + -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto) elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE}) target_compile_options(${internal_target_name} PRIVATE ${nvptx_options}) diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake index 4d17dcaf06fe9..e1286b4ab9631 100644 --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -528,7 +528,8 @@ function(add_integration_test test_name) if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) target_compile_options(${fq_build_target_name} PRIVATE -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} - -flto --target=${LIBC_GPU_TARGET_TRIPLE}) + -flto --target=${LIBC_GPU_TARGET_TRIPLE} + -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}) elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE}) target_compile_options(${fq_build_target_name} PRIVATE @@ -578,7 +579,9 @@ set(LIBC_HERMETIC_TEST_COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_DEFAULT} # The GPU build requires overriding the default CMake triple and architecture. if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS - -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto --target=${LIBC_GPU_TARGET_TRIPLE}) + -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto + --target=${LIBC_GPU_TARGET_TRIPLE} + -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}) elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE}) list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS diff --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake index 063c3b3ca6506..0b6067f69775c 100644 --- a/libc/cmake/modules/prepare_libc_gpu_build.cmake +++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake @@ -115,3 +115,13 @@ if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) get_filename_component(LIBC_CUDA_ROOT "${CUDAToolkit_BIN_DIR}" DIRECTORY ABSOLUTE) endif() endif() + +if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) + # The AMDGPU environment uses different code objects to encode the ABI for + # kernel calls and intrinsic functions. We want to specify this manually to + # conform to whatever the test suite was built to handle. + # FIXME: The test suite currently hangs when compiled targeting version five. + # This occurrs during traversal of the callback array in the startup code. We + # deliberately use version four until this can be addressed. + set(LIBC_GPU_CODE_OBJECT_VERSION 4) +endif() diff --git a/libc/startup/gpu/amdgpu/CMakeLists.txt b/libc/startup/gpu/amdgpu/CMakeLists.txt index e7c0aeafafd9a..723ed9bdb290c 100644 --- a/libc/startup/gpu/amdgpu/CMakeLists.txt +++ b/libc/startup/gpu/amdgpu/CMakeLists.txt @@ -13,6 +13,7 @@ add_startup_object( -nogpulib # Do not include any GPU vendor libraries. -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -emit-llvm # AMDGPU's intermediate object file format is bitcode. + -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION} # Manually set the ABI. --target=${LIBC_GPU_TARGET_TRIPLE} NO_GPU_BUNDLE # Compile this file directly without special GPU handling. ) @@ -26,4 +27,5 @@ target_link_libraries( "--target=${LIBC_GPU_TARGET_TRIPLE}" "-flto" "-Wl,-mllvm,-amdgpu-lower-global-ctor-dtor=0" + "-Wl,-mllvm,-amdhsa-code-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}" ) diff --git a/libc/test/IntegrationTest/CMakeLists.txt b/libc/test/IntegrationTest/CMakeLists.txt index 0c4c38db12f32..3d32b6cb53be9 100644 --- a/libc/test/IntegrationTest/CMakeLists.txt +++ b/libc/test/IntegrationTest/CMakeLists.txt @@ -3,6 +3,7 @@ if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -emit-llvm # AMDGPU's intermediate object file format is bitcode. --target=${LIBC_GPU_TARGET_TRIPLE} + -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION} # Manually set the ABI. ) elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) set(TEST_COMPILE_FLAGS