[libc-commits] [libc] 9ae2564 - [libc] Include object files from alias entrypoints also in entrypoint libraries.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Mon May 4 11:40:17 PDT 2020
Author: Siva Chandra Reddy
Date: 2020-05-04T11:39:37-07:00
New Revision: 9ae2564396984cdffefb53767246d90cd32cbd66
URL: https://github.com/llvm/llvm-project/commit/9ae2564396984cdffefb53767246d90cd32cbd66
DIFF: https://github.com/llvm/llvm-project/commit/9ae2564396984cdffefb53767246d90cd32cbd66.diff
LOG: [libc] Include object files from alias entrypoints also in entrypoint libraries.
Reviewers: abrachet
Differential Revision: https://reviews.llvm.org/D79185
Added:
Modified:
libc/cmake/modules/LLVMLibCLibraryRules.cmake
libc/cmake/modules/LLVMLibCObjectRules.cmake
Removed:
################################################################################
diff --git a/libc/cmake/modules/LLVMLibCLibraryRules.cmake b/libc/cmake/modules/LLVMLibCLibraryRules.cmake
index ca79ad123ce4..4c9f9a6ae982 100644
--- a/libc/cmake/modules/LLVMLibCLibraryRules.cmake
+++ b/libc/cmake/modules/LLVMLibCLibraryRules.cmake
@@ -32,6 +32,40 @@ function(get_object_files_for_entrypoint_library result)
set(${result} ${object_files} PARENT_SCOPE)
endfunction()
+# This is a helper function and not a build rule. Given an entrypoint object
+# target, it returns the object file produced by this target in |result|.
+# If the given entrypoint target is an alias, then it traverses up to the
+# aliasee to get the object file.
+function(get_entrypoint_object_file entrypoint_target result)
+ get_target_property(target_type ${entrypoint_target} "TARGET_TYPE")
+ if(NOT (${target_type} STREQUAL ${ENTRYPOINT_OBJ_TARGET_TYPE}))
+ message(FATAL_ERROR
+ "Expected an target added using `add_entrypoint_object` rule.")
+ endif()
+
+ get_target_property(objfile ${entrypoint_target} "OBJECT_FILE")
+ if(objfile)
+ set(${result} ${objfile} PARENT_SCOPE)
+ return()
+ endif()
+
+ # If the entrypoint is an alias, fetch the object file from the aliasee.
+ get_target_property(is_alias ${entrypoint_target} "IS_ALIAS")
+ if(is_alias)
+ get_target_property(aliasee ${entrypoint_target} "DEPS")
+ if(NOT aliasee)
+ message(FATAL_ERROR
+ "Entrypoint alias ${entrypoint_target} does not have an aliasee.")
+ endif()
+ get_entrypoint_object_file(${aliasee} objfile)
+ set(${result} ${objfile} PARENT_SCOPE)
+ return()
+ endif()
+
+ message(FATAL_ERROR
+ "Entrypoint ${entrypoint_target} does not produce an object file.")
+endfunction(get_entrypoint_object_file)
+
# A rule to build a library from a collection of entrypoint objects.
# Usage:
# add_entrypoint_library(
@@ -62,7 +96,7 @@ function(add_entrypoint_library target_name)
message(FATAL_ERROR "Dependency '${dep}' of 'add_entrypoint_collection' is "
"not an 'add_entrypoint_object' target.")
endif()
- get_target_property(objfile ${dep} "OBJECT_FILE")
+ get_entrypoint_object_file(${dep} objfile)
list(APPEND obj_list ${objfile})
endforeach(dep)
list(REMOVE_DUPLICATES obj_list)
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 947154ce392e..e4bf15723129 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -110,6 +110,7 @@ function(add_entrypoint_object target_name)
${fq_target_name}
PROPERTIES
"TARGET_TYPE" ${ENTRYPOINT_OBJ_TARGET_TYPE}
+ "IS_ALIAS" "YES"
"OBJECT_FILE" ""
"OBJECT_FILE_RAW" ""
"DEPS" "${fq_dep_name}"
More information about the libc-commits
mailing list