[libc-commits] [libc] [libc][cmake] make i386 distinct from x86_64 (PR #114477)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Thu Oct 31 15:45:57 PDT 2024
https://github.com/nickdesaulniers created https://github.com/llvm/llvm-project/pull/114477
Configured via:
$ cmake ../runtimes -G Ninja -DLLVM_ENABLE_LLD=ON \
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libc" \
-DLIBC_TARGET_TRIPLE=i386-linux-gnu -DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++
Link: #93709
>From 5f7f85e785064e5d428002ce5b0de39140cdd010 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Thu, 31 Oct 2024 15:38:42 -0700
Subject: [PATCH] [libc][cmake] make i386 distinct from x86_64
Configured via:
$ cmake ../runtimes -G Ninja -DLLVM_ENABLE_LLD=ON \
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libc" \
-DLIBC_TARGET_TRIPLE=i386-linux-gnu -DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++
Link: #93709
---
libc/cmake/modules/LLVMLibCArchitectures.cmake | 6 +++++-
libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake | 2 +-
libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 6 +++---
libc/cmake/modules/LLVMLibCFlagRules.cmake | 6 +++---
libc/cmake/modules/LLVMLibCTestRules.cmake | 2 +-
libc/config/linux/i386/entrypoints.txt | 11 +++++++++++
libc/config/linux/i386/headers.txt | 3 +++
libc/src/__support/OSUtil/linux/i386/CMakeLists.txt | 11 +++++++++++
libc/src/__support/OSUtil/linux/i386/vdso.h | 0
9 files changed, 38 insertions(+), 9 deletions(-)
create mode 100644 libc/config/linux/i386/entrypoints.txt
create mode 100644 libc/config/linux/i386/headers.txt
create mode 100644 libc/src/__support/OSUtil/linux/i386/CMakeLists.txt
create mode 100644 libc/src/__support/OSUtil/linux/i386/vdso.h
diff --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake
index 1e5ed723194a26..fbb1091ddabab4 100644
--- a/libc/cmake/modules/LLVMLibCArchitectures.cmake
+++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake
@@ -39,8 +39,10 @@ function(get_arch_and_system_from_triple triple arch_var sys_var)
set(target_arch "arm")
elseif(target_arch MATCHES "^aarch64")
set(target_arch "aarch64")
- elseif(target_arch MATCHES "(x86_64)|(AMD64|amd64)|(^i.86$)")
+ elseif(target_arch MATCHES "(x86_64)|(AMD64|amd64)")
set(target_arch "x86_64")
+ elseif(target_arch MATCHES "(^i.86$)")
+ set(target_arch "i386")
elseif(target_arch MATCHES "^(powerpc|ppc)")
set(target_arch "power")
elseif(target_arch MATCHES "^riscv32")
@@ -147,6 +149,8 @@ if(LIBC_TARGET_ARCHITECTURE STREQUAL "arm")
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "aarch64")
set(LIBC_TARGET_ARCHITECTURE_IS_AARCH64 TRUE)
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "x86_64")
+ set(LIBC_TARGET_ARCHITECTURE_IS_X86_64 TRUE)
+elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "i386")
set(LIBC_TARGET_ARCHITECTURE_IS_X86 TRUE)
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "riscv64")
set(LIBC_TARGET_ARCHITECTURE_IS_RISCV64 TRUE)
diff --git a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
index 3b6b6f56fc80cf..c8a2827d33a8d8 100644
--- a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
+++ b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
@@ -5,7 +5,7 @@
# Initialize ALL_CPU_FEATURES as empty list.
set(ALL_CPU_FEATURES "")
-if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
+if(${LIBC_TARGET_ARCHITECTURE_IS_X86_64})
set(ALL_CPU_FEATURES SSE2 SSE4_2 AVX AVX2 AVX512F AVX512BW FMA)
set(LIBC_COMPILE_OPTIONS_NATIVE -march=native)
elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index e30f7d322eb029..65851f1c86571a 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -10,7 +10,7 @@ function(_get_compile_options_from_flags output_var)
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
if(ADD_FMA_FLAG)
- if(LIBC_TARGET_ARCHITECTURE_IS_X86)
+ if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)
list(APPEND compile_options "-mavx2")
list(APPEND compile_options "-mfma")
elseif(LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
@@ -18,7 +18,7 @@ function(_get_compile_options_from_flags output_var)
endif()
endif()
if(ADD_ROUND_OPT_FLAG)
- if(LIBC_TARGET_ARCHITECTURE_IS_X86)
+ if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)
# ROUND_OPT_FLAG is only enabled if SSE4.2 is detected, not just SSE4.1,
# because there was code to check for SSE4.2 already, and few CPUs only
# have SSE4.1.
@@ -145,7 +145,7 @@ function(_get_common_compile_options output_var flags)
endif()
if (LIBC_CONF_KEEP_FRAME_POINTER)
list(APPEND compile_options "-fno-omit-frame-pointer")
- if (LIBC_TARGET_ARCHITECTURE_IS_X86)
+ if (LIBC_TARGET_ARCHITECTURE_IS_X86_64)
list(APPEND compile_options "-mno-omit-leaf-frame-pointer")
endif()
endif()
diff --git a/libc/cmake/modules/LLVMLibCFlagRules.cmake b/libc/cmake/modules/LLVMLibCFlagRules.cmake
index 69f31ace80dd3d..e5b0e249c90676 100644
--- a/libc/cmake/modules/LLVMLibCFlagRules.cmake
+++ b/libc/cmake/modules/LLVMLibCFlagRules.cmake
@@ -268,21 +268,21 @@ set(EXPLICIT_SIMD_OPT_FLAG "EXPLICIT_SIMD_OPT")
set(MISC_MATH_BASIC_OPS_OPT_FLAG "MISC_MATH_BASIC_OPS_OPT")
# Skip FMA_OPT flag for targets that don't support fma.
-if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "FMA")) OR
+if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86_64 AND (LIBC_CPU_FEATURES MATCHES "FMA")) OR
LIBC_TARGET_ARCHITECTURE_IS_RISCV64))
set(SKIP_FLAG_EXPANSION_FMA_OPT TRUE)
endif()
# Skip EXPLICIT_SIMD_OPT flag for targets that don't support SSE2.
# Note: one may want to revisit it if they want to control other explicit SIMD
-if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE2")))
+if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86_64 AND (LIBC_CPU_FEATURES MATCHES "SSE2")))
set(SKIP_FLAG_EXPANSION_EXPLICIT_SIMD_OPT TRUE)
endif()
# Skip ROUND_OPT flag for targets that don't support rounding instructions. On
# x86, these are SSE4.1 instructions, but we already had code to check for
# SSE4.2 support.
-if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE4_2")) OR
+if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86_64 AND (LIBC_CPU_FEATURES MATCHES "SSE4_2")) OR
LIBC_TARGET_ARCHITECTURE_IS_AARCH64 OR LIBC_TARGET_OS_IS_GPU))
set(SKIP_FLAG_EXPANSION_ROUND_OPT TRUE)
endif()
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 35cc6fe46be53f..c3a0f371cd6201 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -402,7 +402,7 @@ function(add_integration_test test_name)
if(NOT INTEGRATION_TEST_SRCS)
message(FATAL_ERROR "The SRCS list for add_integration_test is missing.")
endif()
- if(NOT TARGET libc.startup.${LIBC_TARGET_OS}.crt1)
+ if(NOT LLVM_LIBC_FULL_BUILD AND NOT TARGET libc.startup.${LIBC_TARGET_OS}.crt1)
message(FATAL_ERROR "The 'crt1' target for the integration test is missing.")
endif()
diff --git a/libc/config/linux/i386/entrypoints.txt b/libc/config/linux/i386/entrypoints.txt
new file mode 100644
index 00000000000000..6548c9b816c93f
--- /dev/null
+++ b/libc/config/linux/i386/entrypoints.txt
@@ -0,0 +1,11 @@
+set(TARGET_LIBC_ENTRYPOINTS
+ # errno.h entrypoints
+ libc.src.errno.errno
+)
+
+set(TARGET_LIBM_ENTRYPOINTS "")
+
+set(TARGET_LLVMLIBC_ENTRYPOINTS
+ ${TARGET_LIBC_ENTRYPOINTS}
+ ${TARGET_LIBM_ENTRYPOINTS}
+)
diff --git a/libc/config/linux/i386/headers.txt b/libc/config/linux/i386/headers.txt
new file mode 100644
index 00000000000000..f34ff9141cbca1
--- /dev/null
+++ b/libc/config/linux/i386/headers.txt
@@ -0,0 +1,3 @@
+set(TARGET_PUBLIC_HEADERS
+ libc.include.assert
+)
diff --git a/libc/src/__support/OSUtil/linux/i386/CMakeLists.txt b/libc/src/__support/OSUtil/linux/i386/CMakeLists.txt
new file mode 100644
index 00000000000000..aa35d7e153d1b7
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/i386/CMakeLists.txt
@@ -0,0 +1,11 @@
+add_header_library(
+ linux_i386_util
+ HDRS
+ syscall.h
+)
+
+add_header_library(
+ vdso
+ HDRS
+ vdso.h
+)
diff --git a/libc/src/__support/OSUtil/linux/i386/vdso.h b/libc/src/__support/OSUtil/linux/i386/vdso.h
new file mode 100644
index 00000000000000..e69de29bb2d1d6
More information about the libc-commits
mailing list