Skip to content

Commit 7d1538c

Browse files
Move LIBC_CONF_STRING_UNSAFE_WIDE_READ to top-level libc-configuration (#165046)
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.
1 parent 1c837ec commit 7d1538c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ function(_get_compile_options_from_config output_var)
8181
list(APPEND config_options "-DLIBC_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}")
8282
endif()
8383

84+
if(LIBC_CONF_STRING_UNSAFE_WIDE_READ)
85+
list(APPEND config_options "-DLIBC_COPT_STRING_UNSAFE_WIDE_READ")
86+
endif()
87+
88+
if(LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING)
89+
list(APPEND config_options "-DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING")
90+
endif()
91+
8492
if(LIBC_TYPES_TIME_T_IS_32_BIT AND LLVM_LIBC_FULL_BUILD)
8593
list(APPEND config_options "-DLIBC_TYPES_TIME_T_IS_32_BIT")
8694
endif()

libc/src/string/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
add_subdirectory(memory_utils)
22

3-
if(LIBC_CONF_STRING_UNSAFE_WIDE_READ)
4-
list(APPEND string_config_options "-DLIBC_COPT_STRING_UNSAFE_WIDE_READ")
5-
endif()
6-
if(LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING)
7-
list(APPEND string_config_options "-DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING")
8-
endif()
9-
if(string_config_options)
10-
list(PREPEND string_config_options "COMPILE_OPTIONS")
11-
endif()
12-
133
add_header_library(
144
string_utils
155
HDRS
@@ -24,7 +14,6 @@ add_header_library(
2414
libc.src.__support.common
2515
libc.src.__support.macros.attributes
2616
libc.src.string.memory_utils.inline_memcpy
27-
${string_config_options}
2817
)
2918

3019
add_header_library(

0 commit comments

Comments
 (0)