[libc-commits] [libc] ed4f4ed - [libc] Allow target architecture customization
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Mon May 10 00:54:01 PDT 2021
Author: Guillaume Chatelet
Date: 2021-05-10T07:53:48Z
New Revision: ed4f4edea20caa13a468ab279a0df20b9ba667fb
URL: https://github.com/llvm/llvm-project/commit/ed4f4edea20caa13a468ab279a0df20b9ba667fb
DIFF: https://github.com/llvm/llvm-project/commit/ed4f4edea20caa13a468ab279a0df20b9ba667fb.diff
LOG: [libc] Allow target architecture customization
This patch provides a way to specify the default target cpu optimizations to use when compiling llvm-libc.
This ensures we don't rely on current compiler's default and allows compiling and cross compiling for a particular target.
Differential Revision: https://reviews.llvm.org/D101991
Added:
Modified:
libc/CMakeLists.txt
libc/cmake/modules/LLVMLibCLibraryRules.cmake
libc/cmake/modules/LLVMLibCObjectRules.cmake
libc/cmake/modules/LLVMLibCTestRules.cmake
Removed:
################################################################################
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 15a0b35bac655..30ffa35111db9 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -22,6 +22,9 @@ string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS)
# Defines LIBC_TARGET_ARCHITECTURE and associated macros.
include(LLVMLibCArchitectures)
+# Flags to pass down to the compiler while building the libc functions.
+set(LIBC_COMPILE_OPTIONS_DEFAULT "" CACHE STRING "Architecture to tell clang to optimize for (e.g. -march=... or -mcpu=...)")
+
# Check --print-resource-dir to find the compiler resource dir if this flag
# is supported by the compiler.
execute_process(
diff --git a/libc/cmake/modules/LLVMLibCLibraryRules.cmake b/libc/cmake/modules/LLVMLibCLibraryRules.cmake
index bdc361a719de8..c863f22fc7692 100644
--- a/libc/cmake/modules/LLVMLibCLibraryRules.cmake
+++ b/libc/cmake/modules/LLVMLibCLibraryRules.cmake
@@ -81,11 +81,7 @@ function(add_entrypoint_library target_name)
STATIC
${objects}
)
- set_target_properties(
- ${target_name}
- PROPERTIES
- ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- )
+ set_target_properties(${target_name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endfunction(add_entrypoint_library)
# Rule to build a shared library of redirector objects.
@@ -112,18 +108,9 @@ function(add_redirector_library target_name)
SHARED
${obj_files}
)
- set_target_properties(${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-
- target_link_libraries(
- ${target_name}
- -nostdlib -lc -lm
- )
-
- set_target_properties(
- ${target_name}
- PROPERTIES
- LINKER_LANGUAGE "C"
- )
+ set_target_properties(${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries(${target_name} -nostdlib -lc -lm)
+ set_target_properties(${target_name} PROPERTIES LINKER_LANGUAGE "C")
endfunction(add_redirector_library)
set(HDR_LIBRARY_TARGET_TYPE "HDR_LIBRARY")
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 9afbedcd0c9bf..8c4e6bf8cb244 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -1,5 +1,9 @@
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)
+endfunction()
+
# Rule which is essentially a wrapper over add_library to compile a set of
# sources to object files.
# Usage:
@@ -37,12 +41,8 @@ function(add_object_library target_name)
${LIBC_SOURCE_DIR}
${LIBC_BUILD_DIR}
)
- if(ADD_OBJECT_COMPILE_OPTIONS)
- target_compile_options(
- ${fq_target_name}
- PRIVATE ${ADD_OBJECT_COMPILE_OPTIONS}
- )
- endif()
+ _get_common_compile_options(compile_options ${ADD_OBJECT_COMPILE_OPTIONS})
+ target_compile_options(${fq_target_name} PRIVATE ${compile_options})
get_fq_deps_list(fq_deps_list ${ADD_OBJECT_DEPENDS})
if(fq_deps_list)
@@ -148,7 +148,7 @@ function(add_entrypoint_object target_name)
message(FATAL_ERROR "`add_entrypoint_object` rule requires HDRS to be specified.")
endif()
- set(common_compile_options -fpie ${LLVM_CXX_STD_default} -ffreestanding ${ADD_ENTRYPOINT_OBJ_COMPILE_OPTIONS})
+ _get_common_compile_options(common_compile_options ${ADD_ENTRYPOINT_OBJ_COMPILE_OPTIONS})
set(internal_target_name ${fq_target_name}.__internal__)
set(include_dirs ${LIBC_BUILD_DIR}/include ${LIBC_SOURCE_DIR} ${LIBC_BUILD_DIR})
get_fq_deps_list(fq_deps_list ${ADD_ENTRYPOINT_OBJ_DEPENDS})
@@ -176,9 +176,7 @@ function(add_entrypoint_object target_name)
${ADD_ENTRYPOINT_OBJ_SRCS}
${ADD_ENTRYPOINT_OBJ_HDRS}
)
- target_compile_options(
- ${fq_target_name} BEFORE PRIVATE ${common_compile_options} -DLLVM_LIBC_PUBLIC_PACKAGING
- )
+ target_compile_options(${fq_target_name} BEFORE PRIVATE ${common_compile_options} -DLLVM_LIBC_PUBLIC_PACKAGING)
target_include_directories(${fq_target_name} PRIVATE ${include_dirs})
add_dependencies(${fq_target_name} ${full_deps_list})
@@ -277,6 +275,6 @@ function(add_redirector_object target_name)
)
target_compile_options(
${target_name}
- BEFORE PRIVATE -fPIC
+ BEFORE PRIVATE -fPIC ${LIBC_COMPILE_OPTIONS_DEFAULT}
)
endfunction(add_redirector_object)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 267db1d6ffc56..4a49981d85dbd 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -127,6 +127,10 @@ function(add_libc_unittest target_name)
${LIBC_BUILD_DIR}
${LIBC_BUILD_DIR}/include
)
+ target_compile_options(
+ ${fq_target_name}
+ PRIVATE ${LIBC_COMPILE_OPTIONS_DEFAULT}
+ )
if(LIBC_UNITTEST_COMPILE_OPTIONS)
target_compile_options(
${fq_target_name}
More information about the libc-commits
mailing list