[compiler-rt] compiler-rt: Suppress -g error for gpu builds (PR #202230)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 8 00:25:31 PDT 2026
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/202230
>From 8b05911f4903b4f6b27ce4613282380c0c7e40e1 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sun, 7 Jun 2026 21:42:19 +0200
Subject: [PATCH 1/2] compiler-rt: Suppress -g error for gpu builds
Currently a RelWithDebInfo build fails when gpu targets
are enabled enabled as runtime targets, since clang will error
with -g.
Co-Authored-By: Claude Sonnet 4.5 <noreply at anthropic.com>
---
compiler-rt/CMakeLists.txt | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 63bda0dc186c2..65fcac57077a9 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -523,6 +523,7 @@ if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
endif()
# Build sanitizer runtimes with debug info.
+# GPU targets (amdgcn, nvptx, spirv64) may not support debug info flags.
if(MSVC)
# Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099
# warning from the MS linker complaining that it can't find the 'vc140.pdb'
@@ -535,17 +536,19 @@ if(MSVC)
string(REGEX REPLACE "(^| )/Z[i7I]($| )" " /Z7 "
"${var_to_update}" "${${var_to_update}}")
endforeach()
-elseif(APPLE)
- # On Apple platforms use full debug info (i.e. not `-gline-tables-only`)
- # for all build types so that the runtime can be debugged.
- if(NOT COMPILER_RT_HAS_G_FLAG)
- message(FATAL_ERROR "-g is not supported by host compiler")
+elseif(NOT "${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx|spirv64")
+ if(APPLE)
+ # On Apple platforms use full debug info (i.e. not `-gline-tables-only`)
+ # for all build types so that the runtime can be debugged.
+ if(NOT COMPILER_RT_HAS_G_FLAG)
+ message(FATAL_ERROR "-g is not supported by host compiler")
+ endif()
+ list(APPEND SANITIZER_COMMON_CFLAGS -g)
+ elseif(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
+ list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
+ elseif(COMPILER_RT_HAS_G_FLAG)
+ list(APPEND SANITIZER_COMMON_CFLAGS -g)
endif()
- list(APPEND SANITIZER_COMMON_CFLAGS -g)
-elseif(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
- list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
-elseif(COMPILER_RT_HAS_G_FLAG)
- list(APPEND SANITIZER_COMMON_CFLAGS -g)
endif()
if(LLVM_ENABLE_MODULES)
>From 292f9401f6c3d01afb5c05edbfe297679ae67a66 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 8 Jun 2026 08:34:51 +0200
Subject: [PATCH 2/2] Match against apple vendor and use -nogpulib in -g test
---
compiler-rt/CMakeLists.txt | 23 ++++++++-----------
.../cmake/Modules/CompilerRTUtils.cmake | 1 +
2 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 65fcac57077a9..54df32f3ab2c6 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -523,7 +523,6 @@ if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
endif()
# Build sanitizer runtimes with debug info.
-# GPU targets (amdgcn, nvptx, spirv64) may not support debug info flags.
if(MSVC)
# Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099
# warning from the MS linker complaining that it can't find the 'vc140.pdb'
@@ -536,19 +535,17 @@ if(MSVC)
string(REGEX REPLACE "(^| )/Z[i7I]($| )" " /Z7 "
"${var_to_update}" "${${var_to_update}}")
endforeach()
-elseif(NOT "${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx|spirv64")
- if(APPLE)
- # On Apple platforms use full debug info (i.e. not `-gline-tables-only`)
- # for all build types so that the runtime can be debugged.
- if(NOT COMPILER_RT_HAS_G_FLAG)
- message(FATAL_ERROR "-g is not supported by host compiler")
- endif()
- list(APPEND SANITIZER_COMMON_CFLAGS -g)
- elseif(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
- list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
- elseif(COMPILER_RT_HAS_G_FLAG)
- list(APPEND SANITIZER_COMMON_CFLAGS -g)
+elseif("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES "apple")
+ # On Apple platforms use full debug info (i.e. not `-gline-tables-only`)
+ # for all build types so that the runtime can be debugged.
+ if(NOT COMPILER_RT_HAS_G_FLAG)
+ message(FATAL_ERROR "-g is not supported by host compiler")
endif()
+ list(APPEND SANITIZER_COMMON_CFLAGS -g)
+elseif(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
+ list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
+elseif(COMPILER_RT_HAS_G_FLAG)
+ list(APPEND SANITIZER_COMMON_CFLAGS -g)
endif()
if(LLVM_ENABLE_MODULES)
diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index f4e5560f88412..89fa3e53e9141 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -426,6 +426,7 @@ macro(construct_compiler_rt_default_triple)
# Pass the necessary flags to make flag detection work.
if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn")
set(COMPILER_RT_GPU_BUILD ON)
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "nvptx|spirv64")
set(COMPILER_RT_GPU_BUILD ON)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c")
More information about the llvm-commits
mailing list