[libc-commits] [libc] [libc] [startup] add cmake function to merge separated crt1 objects (PR #75413)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Wed Dec 13 16:32:21 PST 2023


================
@@ -1,3 +1,42 @@
+# This function merges multiple objects into a single relocatable object
+#                     cc -r obj1.o obj2.o -o obj.o
+# A relocatable object is an object file that is not fully linked into an
+# executable or a shared library. It is an intermediate file format that can
+# be passed into the linker.
+# A crt object have arch-specific code and arch-agnostic code. To reduce code
+# cohesion, the implementation is splitted into multiple units. As a result,
+# we need to merge them into a single relocatable object.
+function(merge_relocatable_object name)
+  set(obj_list "")
+  set(fq_link_libraries "")
+  get_fq_deps_list(fq_dep_list ${ARGN})
+  foreach(target IN LISTS fq_dep_list)
+    list(APPEND obj_list "$<TARGET_OBJECTS:${target}>")
+    get_target_property(libs ${target} DEPS)
+    list(APPEND fq_link_libraries "${libs}")
+  endforeach()
+  get_fq_target_name(${name} fq_name)
+  add_custom_command(
----------------
SchrodingerZhu wrote:

There are internal uses of crt1 as an object library. See integration tests.

https://github.com/llvm/llvm-project/pull/75413


More information about the libc-commits mailing list