Skip to content

[libc][cmake] make i386 distinct from x86_64 #114477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

nickdesaulniers
Copy link
Member

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

@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/114477.diff

9 Files Affected:

  • (modified) libc/cmake/modules/LLVMLibCArchitectures.cmake (+5-1)
  • (modified) libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake (+1-1)
  • (modified) libc/cmake/modules/LLVMLibCCompileOptionRules.cmake (+3-3)
  • (modified) libc/cmake/modules/LLVMLibCFlagRules.cmake (+3-3)
  • (modified) libc/cmake/modules/LLVMLibCTestRules.cmake (+1-1)
  • (added) libc/config/linux/i386/entrypoints.txt (+11)
  • (added) libc/config/linux/i386/headers.txt (+3)
  • (added) libc/src/__support/OSUtil/linux/i386/CMakeLists.txt (+11)
  • (added) 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

@nickdesaulniers
Copy link
Member Author

FWIW, I do plan to flush out the entrypoints and headers text files, but not in this PR.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but we should plan to stand up a bot for this i386 once it's properly working.

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: llvm#93709
Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense in general, guessing we'll fill out the entrypoints later.

@@ -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})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need ${...} here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in 76a871b

@nickdesaulniers nickdesaulniers merged commit e083a33 into llvm:main Nov 1, 2024
7 checks passed
smallp-o-p pushed a commit to smallp-o-p/llvm-project that referenced this pull request Nov 3, 2024
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: llvm#93709
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
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: llvm#93709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants