From 273f6c822ab2ef14967568b9009924eeb8a58600 Mon Sep 17 00:00:00 2001 From: Sterling Augustine Date: Fri, 24 Oct 2025 14:46:51 -0700 Subject: [PATCH 1/3] Move LIBC_CONF_STRING_UNSAFE_WIDE_READ to top-level libc-configuration This options sets a compile option when building sources inside the string directory, and this option affects string_utils.h. But string_utils.h is #included from more places than just the string directory (such as from __support/CPP/string.h), leading to both narrow-reads in those cases, but more seriously, ODR violations when the two different string_length implementations are included int he same program. Having this option at the top level avoids this problem. --- libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 4 ++++ libc/src/string/CMakeLists.txt | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake index 4c36ed8620f40..c4e4a9e3465d7 100644 --- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake +++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake @@ -81,6 +81,10 @@ function(_get_compile_options_from_config output_var) list(APPEND config_options "-DLIBC_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}") endif() + if(LIBC_CONF_STRING_UNSAFE_WIDE_READ) + list(APPEND config_options "-DLIBC_COPT_STRING_UNSAFE_WIDE_READ") + endif() + if(LIBC_TYPES_TIME_T_IS_32_BIT AND LLVM_LIBC_FULL_BUILD) list(APPEND config_options "-DLIBC_TYPES_TIME_T_IS_32_BIT") endif() diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt index 83c956429be24..fd1ae8d417f8c 100644 --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -1,8 +1,5 @@ add_subdirectory(memory_utils) -if(LIBC_CONF_STRING_UNSAFE_WIDE_READ) - list(APPEND string_config_options "-DLIBC_COPT_STRING_UNSAFE_WIDE_READ") -endif() if(LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING) list(APPEND string_config_options "-DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING") endif() From 1219f8884d9b0667da4088e2718422e9ad173baa Mon Sep 17 00:00:00 2001 From: Sterling Augustine Date: Fri, 24 Oct 2025 15:49:49 -0700 Subject: [PATCH 2/3] Also do this for LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING --- libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 4 ++++ libc/src/string/CMakeLists.txt | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake index c4e4a9e3465d7..7486a14bb4e18 100644 --- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake +++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake @@ -85,6 +85,10 @@ function(_get_compile_options_from_config output_var) list(APPEND config_options "-DLIBC_COPT_STRING_UNSAFE_WIDE_READ") endif() + if(LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING) + list(APPEND string_config_options "-DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING") + endif() + if(LIBC_TYPES_TIME_T_IS_32_BIT AND LLVM_LIBC_FULL_BUILD) list(APPEND config_options "-DLIBC_TYPES_TIME_T_IS_32_BIT") endif() diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt index fd1ae8d417f8c..35960c3706725 100644 --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -1,8 +1,5 @@ add_subdirectory(memory_utils) -if(LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING) - list(APPEND string_config_options "-DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING") -endif() if(string_config_options) list(PREPEND string_config_options "COMPILE_OPTIONS") endif() From 846f0e85241a63309a64985bc91f803df540056d Mon Sep 17 00:00:00 2001 From: Sterling Augustine Date: Mon, 27 Oct 2025 11:28:36 -0700 Subject: [PATCH 3/3] Remove string_config_options altogether --- libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 2 +- libc/src/string/CMakeLists.txt | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake index 7486a14bb4e18..4e9a9b66a63a7 100644 --- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake +++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake @@ -86,7 +86,7 @@ function(_get_compile_options_from_config output_var) endif() if(LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING) - list(APPEND string_config_options "-DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING") + list(APPEND config_options "-DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING") endif() if(LIBC_TYPES_TIME_T_IS_32_BIT AND LLVM_LIBC_FULL_BUILD) diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt index 35960c3706725..a640e1d2cc774 100644 --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -1,9 +1,5 @@ add_subdirectory(memory_utils) -if(string_config_options) - list(PREPEND string_config_options "COMPILE_OPTIONS") -endif() - add_header_library( string_utils HDRS @@ -18,7 +14,6 @@ add_header_library( libc.src.__support.common libc.src.__support.macros.attributes libc.src.string.memory_utils.inline_memcpy - ${string_config_options} ) add_header_library(