[libc-commits] [PATCH] D79185: [libc] Include object files from alias entrypoints also in entrypoint libraries.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Apr 30 11:15:07 PDT 2020


sivachandra created this revision.
sivachandra added a reviewer: abrachet.
Herald added subscribers: libc-commits, tschuett, mgorny.
Herald added a project: libc-project.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79185

Files:
  libc/cmake/modules/LLVMLibCLibraryRules.cmake
  libc/cmake/modules/LLVMLibCObjectRules.cmake


Index: libc/cmake/modules/LLVMLibCObjectRules.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -110,6 +110,7 @@
       ${fq_target_name}
       PROPERTIES
         "TARGET_TYPE" ${ENTRYPOINT_OBJ_TARGET_TYPE}
+        "IS_ALIAS" "YES"
         "OBJECT_FILE" ""
         "OBJECT_FILE_RAW" ""
         "DEPS" "${fq_dep_name}"
Index: libc/cmake/modules/LLVMLibCLibraryRules.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCLibraryRules.cmake
+++ libc/cmake/modules/LLVMLibCLibraryRules.cmake
@@ -32,6 +32,40 @@
   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 @@
       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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79185.261284.patch
Type: text/x-patch
Size: 2606 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20200430/87f4b553/attachment.bin>


More information about the libc-commits mailing list