[libc] Don't pass -fpie/-ffreestanding on Windows
authorCaitlyn Cano <caitlyncano@google.com>
Thu, 8 Jul 2021 17:44:10 +0000 (17:44 +0000)
committerCaitlyn Cano <caitlyncano@google.com>
Tue, 13 Jul 2021 20:39:51 +0000 (20:39 +0000)
The current compile options function hardcodes the -fpie and
-ffreestanding flags, which don't exist on Windows. This patch sets the
compilation flags conditionally based on the OS specifics.

Reviewed By: sivachandra, aeubanks

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

libc/cmake/modules/LLVMLibCObjectRules.cmake

index 8c4e6bf..55761ee 100644 (file)
@@ -1,7 +1,11 @@
 set(OBJECT_LIBRARY_TARGET_TYPE "OBJECT_LIBRARY")
 
 function(_get_common_compile_options output_var)
-  set(${output_var} -fpie ${LLVM_CXX_STD_default} -ffreestanding ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN} PARENT_SCOPE)
+  set(compile_options ${LLVM_CXX_STD_default} ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN})
+  if(NOT ${LIBC_TARGET_OS} STREQUAL "windows")
+    set(compile_options ${compile_options} -fpie -ffreestanding)
+  endif()
+  set(${output_var} ${compile_options} PARENT_SCOPE)
 endfunction()
 
 # Rule which is essentially a wrapper over add_library to compile a set of