[libc] Disable rtti/expections
authorGuillaume Chatelet <gchatelet@google.com>
Thu, 3 Feb 2022 12:36:05 +0000 (12:36 +0000)
committerGuillaume Chatelet <gchatelet@google.com>
Tue, 8 Feb 2022 10:46:28 +0000 (10:46 +0000)
llvm-libc exhibits a C interface but its source is C++.
This patch explicitly disables the use of exceptions and RTTI when compiling the entrypoints.

Differential Revision: https://reviews.llvm.org/D118889

libc/cmake/modules/LLVMLibCObjectRules.cmake

index 3ab05e0..0ddf8a1 100644 (file)
@@ -5,6 +5,15 @@ function(_get_common_compile_options output_var)
   if(NOT ${LIBC_TARGET_OS} STREQUAL "windows")
     set(compile_options ${compile_options} -fpie -ffreestanding)
   endif()
+  if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
+    list(APPEND compile_options "-fno-exceptions")
+    list(APPEND compile_options "-fno-unwind-tables")
+    list(APPEND compile_options "-fno-asynchronous-unwind-tables")
+    list(APPEND compile_options "-fno-rtti")
+  elseif(MSVC)
+    list(APPEND compile_options "/EHs-c-")
+    list(APPEND compile_options "/GR-")
+  endif()
   set(${output_var} ${compile_options} PARENT_SCOPE)
 endfunction()