[compiler-rt] [ARM][Compiler-RT] Add optional exclusion of libc provided ARM AEABI builtins from compiler-rt. (PR #137952)

Simi Pallipurath via llvm-commits llvm-commits at lists.llvm.org
Thu May 1 02:08:25 PDT 2025


https://github.com/simpal01 updated https://github.com/llvm/llvm-project/pull/137952

>From 8eff12706a93b8b9794a10a178f84efbbe3c880f Mon Sep 17 00:00:00 2001
From: Simi Pallipurath <simi.pallipurath at arm.com>
Date: Wed, 30 Apr 2025 11:25:10 +0100
Subject: [PATCH 1/2] [ARM][Compiler-RT] Add optional exclusion of libc
 provided ARM AEABI builtins from compiler-rt.

This patch introduces a new optional CMake flag:
  COMPILER_RT_EXCLUDE_LIBC_PROVIDED_ARM_AEABI_BUILTINS

When enabled, this flag excludes the following ARM AEABI
memory function implementations from the compiler-rt build:
	__aeabi_memset
	__aeabi_memcpy
	__aeabi_memmove

These functions are already provided by standard C
libraries like glibc, newlib, and picolibc, so excluding
them avoids duplicate symbol definitions and reduces
unnecessary code duplication.

Note: __aeabi_memcmp and other AEABI functions are not
excluded, as they are not defined in all standard libraries.
This flag is OFF by default, meaning all AEABI memory builtins
will still be built unless explicitly excluded.

This change is useful for environments where libc provides
runtime routines, supporting more minimal, conflict free builds.
---
 compiler-rt/lib/builtins/CMakeLists.txt | 61 +++++++++++++++++--------
 1 file changed, 42 insertions(+), 19 deletions(-)

diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index 0c986f484bf5e..cca41c431dbb1 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -230,6 +230,9 @@ set(GENERIC_TF_SOURCES
 option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN
   "Skip the atomic builtin (these should normally be provided by a shared library)"
   On)
+option(COMPILER_RT_EXCLUDE_LIBC_PROVIDED_ARM_AEABI_BUILTINS
+  "Skip the standard C library provided arm aeabi builtins from compiler-rt)"
+  Off)
 
 if(NOT FUCHSIA AND NOT COMPILER_RT_BAREMETAL_BUILD AND NOT COMPILER_RT_GPU_BUILD)
   set(GENERIC_SOURCES
@@ -450,25 +453,45 @@ set(thumb1_base_SOURCES
   ${GENERIC_SOURCES}
 )
 
-set(arm_EABI_SOURCES
-  arm/aeabi_cdcmp.S
-  arm/aeabi_cdcmpeq_check_nan.c
-  arm/aeabi_cfcmp.S
-  arm/aeabi_cfcmpeq_check_nan.c
-  arm/aeabi_dcmp.S
-  arm/aeabi_div0.c
-  arm/aeabi_drsub.c
-  arm/aeabi_fcmp.S
-  arm/aeabi_frsub.c
-  arm/aeabi_idivmod.S
-  arm/aeabi_ldivmod.S
-  arm/aeabi_memcmp.S
-  arm/aeabi_memcpy.S
-  arm/aeabi_memmove.S
-  arm/aeabi_memset.S
-  arm/aeabi_uidivmod.S
-  arm/aeabi_uldivmod.S
-)
+if(NOT COMPILER_RT_EXCLUDE_LIBC_PROVIDED_ARM_AEABI_BUILTINS)
+  set(arm_EABI_SOURCES
+     arm/aeabi_cdcmp.S
+     arm/aeabi_cdcmpeq_check_nan.c
+     arm/aeabi_cfcmp.S
+     arm/aeabi_cfcmpeq_check_nan.c
+     arm/aeabi_dcmp.S
+     arm/aeabi_div0.c
+     arm/aeabi_drsub.c
+     arm/aeabi_fcmp.S
+     arm/aeabi_frsub.c
+     arm/aeabi_idivmod.S
+     arm/aeabi_ldivmod.S
+     arm/aeabi_memcmp.S
+     arm/aeabi_memcpy.S
+     arm/aeabi_memmove.S
+     arm/aeabi_memset.S
+     arm/aeabi_uidivmod.S
+     arm/aeabi_uldivmod.S
+  )
+else()
+	message(STATUS "COMPILER_RT_EXCLUDE_LIBC_PROVIDED_ARM_AEABI_BUILTINS is ON, so skipping __aeabi_memcpy, __aeabi_memmove and __aeabi_memset Sources")
+  set(arm_EABI_SOURCES
+     arm/aeabi_cdcmp.S
+     arm/aeabi_cdcmpeq_check_nan.c
+     arm/aeabi_cfcmp.S
+     arm/aeabi_cfcmpeq_check_nan.c
+     arm/aeabi_dcmp.S
+     arm/aeabi_div0.c
+     arm/aeabi_drsub.c
+     arm/aeabi_fcmp.S
+     arm/aeabi_frsub.c
+     arm/aeabi_idivmod.S
+     arm/aeabi_ldivmod.S
+     arm/aeabi_memcmp.S
+     arm/aeabi_uidivmod.S
+     arm/aeabi_uldivmod.S
+  )
+endif()
 
 set(arm_Thumb1_JT_SOURCES
   arm/switch16.S

>From bb4120b139d29eac822696ce99c6170406536619 Mon Sep 17 00:00:00 2001
From: Simi Pallipurath <simi.pallipurath at arm.com>
Date: Thu, 1 May 2025 09:41:02 +0100
Subject: [PATCH 2/2] fixup! [ARM][Compiler-RT] Add optional exclusion of libc
 provided ARM AEABI builtins from compiler-rt.

Add aeabi_memcmp.S to the set of libc-supplied builtins.
Refactor the CMake logic upon adding a new optional flag.
---
 compiler-rt/lib/builtins/CMakeLists.txt | 59 +++++++++++--------------
 1 file changed, 27 insertions(+), 32 deletions(-)

diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index cca41c431dbb1..5efc4ab0e85bc 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -453,43 +453,38 @@ set(thumb1_base_SOURCES
   ${GENERIC_SOURCES}
 )
 
+set(arm_EABI_RT_SOURCES
+  arm/aeabi_cdcmp.S
+  arm/aeabi_cdcmpeq_check_nan.c
+  arm/aeabi_cfcmp.S
+  arm/aeabi_cfcmpeq_check_nan.c
+  arm/aeabi_dcmp.S
+  arm/aeabi_div0.c
+  arm/aeabi_drsub.c
+  arm/aeabi_fcmp.S
+  arm/aeabi_frsub.c
+  arm/aeabi_idivmod.S
+  arm/aeabi_ldivmod.S
+  arm/aeabi_uidivmod.S
+  arm/aeabi_uldivmod.S
+)
+
+set(arm_EABI_CLIB_SOURCES
+  arm/aeabi_memcmp.S
+  arm/aeabi_memcpy.S
+  arm/aeabi_memmove.S
+  arm/aeabi_memset.S
+)
+
 if(NOT COMPILER_RT_EXCLUDE_LIBC_PROVIDED_ARM_AEABI_BUILTINS)
   set(arm_EABI_SOURCES
-     arm/aeabi_cdcmp.S
-     arm/aeabi_cdcmpeq_check_nan.c
-     arm/aeabi_cfcmp.S
-     arm/aeabi_cfcmpeq_check_nan.c
-     arm/aeabi_dcmp.S
-     arm/aeabi_div0.c
-     arm/aeabi_drsub.c
-     arm/aeabi_fcmp.S
-     arm/aeabi_frsub.c
-     arm/aeabi_idivmod.S
-     arm/aeabi_ldivmod.S
-     arm/aeabi_memcmp.S
-     arm/aeabi_memcpy.S
-     arm/aeabi_memmove.S
-     arm/aeabi_memset.S
-     arm/aeabi_uidivmod.S
-     arm/aeabi_uldivmod.S
+    ${arm_EABI_RT_SOURCES}
+    ${arm_EABI_CLIB_SOURCES}
   )
 else()
-	message(STATUS "COMPILER_RT_EXCLUDE_LIBC_PROVIDED_ARM_AEABI_BUILTINS is ON, so skipping __aeabi_memcpy, __aeabi_memmove and __aeabi_memset Sources")
+  message(STATUS "COMPILER_RT_EXCLUDE_LIBC_PROVIDED_ARM_AEABI_BUILTINS is ON, so skipping __aeabi_memcmp, __aeabi_memcpy, __aeabi_memmove and __aeabi_memset Sources")
   set(arm_EABI_SOURCES
-     arm/aeabi_cdcmp.S
-     arm/aeabi_cdcmpeq_check_nan.c
-     arm/aeabi_cfcmp.S
-     arm/aeabi_cfcmpeq_check_nan.c
-     arm/aeabi_dcmp.S
-     arm/aeabi_div0.c
-     arm/aeabi_drsub.c
-     arm/aeabi_fcmp.S
-     arm/aeabi_frsub.c
-     arm/aeabi_idivmod.S
-     arm/aeabi_ldivmod.S
-     arm/aeabi_memcmp.S
-     arm/aeabi_uidivmod.S
-     arm/aeabi_uldivmod.S
+    ${arm_EABI_RT_SOURCES}
   )
 endif()
 



More information about the llvm-commits mailing list