[libc-commits] [libc] be0fa31 - [libc] fix unit tests in fullbuild (#78864)

via libc-commits libc-commits at lists.llvm.org
Sun Jan 21 18:37:22 PST 2024


Author: Schrodinger ZHU Yifan
Date: 2024-01-21T21:37:17-05:00
New Revision: be0fa319f922e6ea3661640aa55f6b9092be5a99

URL: https://github.com/llvm/llvm-project/commit/be0fa319f922e6ea3661640aa55f6b9092be5a99
DIFF: https://github.com/llvm/llvm-project/commit/be0fa319f922e6ea3661640aa55f6b9092be5a99.diff

LOG: [libc] fix unit tests in fullbuild (#78864)

fixes https://github.com/llvm/llvm-project/issues/78743

- For normal objects, the patch removes `RTTI` and exceptions in `fullbuild`
- For FP tests, the patch adds links to `stdc++` and `gcc_s` if `MPFR` is used.

Added: 
    

Modified: 
    libc/cmake/modules/LLVMLibCTestRules.cmake
    libc/utils/MPFRWrapper/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 24f543f6e4c132..9b7e9180275414 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -187,7 +187,7 @@ function(create_libc_unittest fq_target_name)
   if(LLVM_LIBC_FULL_BUILD)
     target_compile_options(
       ${fq_build_target_name}
-      PRIVATE -ffreestanding
+      PRIVATE -ffreestanding -fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables
     )
   endif()
   if(LIBC_UNITTEST_COMPILE_OPTIONS)

diff  --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index d9fa0e31df0e50..adc073c9a91f52 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -4,9 +4,13 @@ if(LIBC_TESTS_CAN_USE_MPFR)
     MPFRUtils.h
     mpfr_inc.h
   )
-  add_compile_options(
-    -O3
-  )
+  target_compile_options(libcMPFRWrapper PRIVATE -O3)
+  if (LLVM_LIBC_FULL_BUILD)
+    # It is not easy to make libcMPFRWrapper a standalone library because gmp.h may unconditionally
+    # pull in some STL headers. As a result, targets using this library will need to link against 
+    # C++ and unwind libraries. Since we are using MPFR anyway, we directly specifies the GNU toolchain.
+    target_link_libraries(libcMPFRWrapper PUBLIC -lstdc++ -lgcc_s)
+  endif()
   add_dependencies(
     libcMPFRWrapper 
     libc.src.__support.CPP.string_view 
@@ -19,7 +23,7 @@ if(LIBC_TESTS_CAN_USE_MPFR)
     target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
     target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
   endif()
-  target_link_libraries(libcMPFRWrapper LibcFPTestHelpers.unit LibcTest.unit mpfr gmp)
+  target_link_libraries(libcMPFRWrapper PUBLIC LibcFPTestHelpers.unit LibcTest.unit mpfr gmp)
 elseif(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
   message(WARNING "Math tests using MPFR will be skipped.")
 endif()


        


More information about the libc-commits mailing list