[compiler-rt] [compiler-rt][test][builtins] Check linker support for --start-group (PR #205610)
Kelvin Li via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 29 06:54:44 PDT 2026
https://github.com/kkwli updated https://github.com/llvm/llvm-project/pull/205610
>From 64684d56862184c61530c11b5246aa5ffdca395e Mon Sep 17 00:00:00 2001
From: Kelvin Li <kli at ca.ibm.com>
Date: Tue, 23 Jun 2026 12:25:41 -0400
Subject: [PATCH 1/5] [compiler-rt][test][builtins] Check if the linker
supports --start-group (NFC)
This patch is to add a check for the linker whether the --start-group
option is supported before passing to the linker. This can accommodate
different linker requirements.
---
compiler-rt/test/builtins/CMakeLists.txt | 5 +++++
compiler-rt/test/builtins/Unit/lit.cfg.py | 13 ++++++++++---
compiler-rt/test/builtins/Unit/lit.site.cfg.py.in | 1 +
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/compiler-rt/test/builtins/CMakeLists.txt b/compiler-rt/test/builtins/CMakeLists.txt
index 16349f221463e..843e76264e12b 100644
--- a/compiler-rt/test/builtins/CMakeLists.txt
+++ b/compiler-rt/test/builtins/CMakeLists.txt
@@ -43,6 +43,11 @@ if (MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
endif()
pythonize_bool(BUILTINS_IS_MSVC)
+# Check if the linker supports --start-group and --end-group options
+include(CheckLinkerFlag)
+check_linker_flag(C "-Wl,--start-group" COMPILER_RT_HAS_START_GROUP)
+pythonize_bool(COMPILER_RT_HAS_START_GROUP)
+
set(BUILTIN_TEST_ARCH ${BUILTIN_SUPPORTED_ARCH})
if(APPLE)
darwin_filter_host_archs(BUILTIN_SUPPORTED_ARCH BUILTIN_TEST_ARCH)
diff --git a/compiler-rt/test/builtins/Unit/lit.cfg.py b/compiler-rt/test/builtins/Unit/lit.cfg.py
index 2bb72630a41e9..0c7073b600fd7 100644
--- a/compiler-rt/test/builtins/Unit/lit.cfg.py
+++ b/compiler-rt/test/builtins/Unit/lit.cfg.py
@@ -107,9 +107,16 @@ def get_libgcc_file_name():
if config.target_os == "Haiku":
config.substitutions.append(("%librt ", base_lib + " -lroot "))
else:
- config.substitutions.append(
- ("%librt ", "-lm -Wl,--start-group " + base_lib + " -lc -Wl,--end-group ")
- )
+ # Check if the linker supports --start-group and --end-group
+ linker_supports_start_group = get_required_attr(config, "linker_supports_start_group")
+ if linker_supports_start_group:
+ config.substitutions.append(
+ ("%librt ", "-lm -Wl,--start-group " + base_lib + " -lc -Wl,--end-group ")
+ )
+ else:
+ config.substitutions.append(
+ ("%librt ", "-lm " + base_lib + " -lc ")
+ )
builtins_test_crt = get_required_attr(config, "builtins_test_crt")
if builtins_test_crt:
diff --git a/compiler-rt/test/builtins/Unit/lit.site.cfg.py.in b/compiler-rt/test/builtins/Unit/lit.site.cfg.py.in
index 91675d62f7dc9..6776d86b488d0 100644
--- a/compiler-rt/test/builtins/Unit/lit.site.cfg.py.in
+++ b/compiler-rt/test/builtins/Unit/lit.site.cfg.py.in
@@ -9,6 +9,7 @@ config.builtins_test_crt = @COMPILER_RT_TEST_CRT_PYBOOL@
config.is_msvc = @MSVC_PYBOOL@
config.builtins_is_msvc = @BUILTINS_IS_MSVC_PYBOOL@
config.builtins_lit_source_features = "@BUILTINS_LIT_SOURCE_FEATURES@"
+config.linker_supports_start_group = @COMPILER_RT_HAS_START_GROUP_PYBOOL@
config.test_suite_supports_overriding_runtime_lib_path = True
# Load common config for all compiler-rt lit tests.
>From d05afb761e893314e00c7b226527c29005968a1b Mon Sep 17 00:00:00 2001
From: Kelvin Li <kli at ca.ibm.com>
Date: Wed, 24 Jun 2026 14:12:56 -0400
Subject: [PATCH 2/5] fix format
---
compiler-rt/test/builtins/Unit/lit.cfg.py | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/compiler-rt/test/builtins/Unit/lit.cfg.py b/compiler-rt/test/builtins/Unit/lit.cfg.py
index 0c7073b600fd7..6e812a56053b1 100644
--- a/compiler-rt/test/builtins/Unit/lit.cfg.py
+++ b/compiler-rt/test/builtins/Unit/lit.cfg.py
@@ -108,15 +108,18 @@ def get_libgcc_file_name():
config.substitutions.append(("%librt ", base_lib + " -lroot "))
else:
# Check if the linker supports --start-group and --end-group
- linker_supports_start_group = get_required_attr(config, "linker_supports_start_group")
+ linker_supports_start_group = get_required_attr(
+ config, "linker_supports_start_group"
+ )
if linker_supports_start_group:
config.substitutions.append(
- ("%librt ", "-lm -Wl,--start-group " + base_lib + " -lc -Wl,--end-group ")
+ (
+ "%librt ",
+ "-lm -Wl,--start-group " + base_lib + " -lc -Wl,--end-group "
+ )
)
else:
- config.substitutions.append(
- ("%librt ", "-lm " + base_lib + " -lc ")
- )
+ config.substitutions.append(("%librt ", "-lm " + base_lib + " -lc "))
builtins_test_crt = get_required_attr(config, "builtins_test_crt")
if builtins_test_crt:
>From fe98781ca4dff0c5f30b3301f267103ad3b3d225 Mon Sep 17 00:00:00 2001
From: Kelvin Li <kli at ca.ibm.com>
Date: Wed, 24 Jun 2026 16:24:15 -0400
Subject: [PATCH 3/5] - fix format - add guard for nvptx target
---
compiler-rt/test/builtins/Unit/lit.cfg.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/compiler-rt/test/builtins/Unit/lit.cfg.py b/compiler-rt/test/builtins/Unit/lit.cfg.py
index 6e812a56053b1..63218dcdd6671 100644
--- a/compiler-rt/test/builtins/Unit/lit.cfg.py
+++ b/compiler-rt/test/builtins/Unit/lit.cfg.py
@@ -107,15 +107,16 @@ def get_libgcc_file_name():
if config.target_os == "Haiku":
config.substitutions.append(("%librt ", base_lib + " -lroot "))
else:
- # Check if the linker supports --start-group and --end-group
linker_supports_start_group = get_required_attr(
config, "linker_supports_start_group"
)
- if linker_supports_start_group:
+ # Check if the linker supports --start-group and --end-group
+ # For nvptx64 target, it falls back to the default.
+ if linker_supports_start_group and "nvptx" in target_arch:
config.substitutions.append(
(
"%librt ",
- "-lm -Wl,--start-group " + base_lib + " -lc -Wl,--end-group "
+ "-lm -Wl,--start-group " + base_lib + " -lc -Wl,--end-group ",
)
)
else:
>From 2f4872677c85ababfb77daaf28ecd145cbbbd21b Mon Sep 17 00:00:00 2001
From: Kelvin Li <kli at ca.ibm.com>
Date: Wed, 24 Jun 2026 17:06:18 -0400
Subject: [PATCH 4/5] Fix logic
---
compiler-rt/test/builtins/Unit/lit.cfg.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/test/builtins/Unit/lit.cfg.py b/compiler-rt/test/builtins/Unit/lit.cfg.py
index 63218dcdd6671..d44553b6dd082 100644
--- a/compiler-rt/test/builtins/Unit/lit.cfg.py
+++ b/compiler-rt/test/builtins/Unit/lit.cfg.py
@@ -112,7 +112,7 @@ def get_libgcc_file_name():
)
# Check if the linker supports --start-group and --end-group
# For nvptx64 target, it falls back to the default.
- if linker_supports_start_group and "nvptx" in target_arch:
+ if linker_supports_start_group and "nvptx" not in config.target_arch:
config.substitutions.append(
(
"%librt ",
>From faaa46315e086b5dea2b1f9ab8f2ed84c344d6aa Mon Sep 17 00:00:00 2001
From: Kelvin Li <kli at ca.ibm.com>
Date: Sat, 27 Jun 2026 15:23:24 -0400
Subject: [PATCH 5/5] add check suggested in review
---
compiler-rt/test/builtins/CMakeLists.txt | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/compiler-rt/test/builtins/CMakeLists.txt b/compiler-rt/test/builtins/CMakeLists.txt
index 843e76264e12b..6e6fabd3e2c15 100644
--- a/compiler-rt/test/builtins/CMakeLists.txt
+++ b/compiler-rt/test/builtins/CMakeLists.txt
@@ -43,9 +43,17 @@ if (MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
endif()
pythonize_bool(BUILTINS_IS_MSVC)
-# Check if the linker supports --start-group and --end-group options
-include(CheckLinkerFlag)
-check_linker_flag(C "-Wl,--start-group" COMPILER_RT_HAS_START_GROUP)
+# Check if the linker supports --start-group options
+# Standalone builtins builds set CMAKE_TRY_COMPILE_TARGET_TYPE to
+# STATIC_LIBRARY to avoid invoking the linker during compiler checks.
+# Such builds are typically intended for target environments (e.g.
+# bare-metal) where support for --start-group is assumed.
+if(CMAKE_TRY_COMPILE_TARGET_TYPE STREQUAL "STATIC_LIBRARY")
+ set(COMPILER_RT_HAS_START_GROUP ON)
+else()
+ include(CheckLinkerFlag)
+ check_linker_flag(C "-Wl,--start-group" COMPILER_RT_HAS_START_GROUP)
+endif()
pythonize_bool(COMPILER_RT_HAS_START_GROUP)
set(BUILTIN_TEST_ARCH ${BUILTIN_SUPPORTED_ARCH})
More information about the llvm-commits
mailing list