[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
Mon Dec 18 14:46:28 PST 2023


================
@@ -27,18 +70,24 @@ function(add_startup_object name)
   )
 endfunction()
 
+check_cxx_compiler_flag("-r" LIBC_LINKER_SUPPORTS_RELOCATABLE)
+
+if(NOT LIBC_LINKER_SUPPORTS_RELOCATABLE)
+  message(STATUS "Skipping startup for target architecture ${LIBC_TARGET_ARCHITECTURE}: linker does not support -r")
+  return()
+endif()
+
 if(NOT (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}))
   message(STATUS "Skipping startup for target architecture ${LIBC_TARGET_ARCHITECTURE}")
   return()
 endif()
 
 add_subdirectory(${LIBC_TARGET_ARCHITECTURE})
 
-add_startup_object(
+# TODO: factor out crt1 into multiple objects
----------------
SchrodingerZhu wrote:

Sure.

The `do_start` function is actually architecture-independent. With this patch, we can have something like:

```
+ x86_64
  - start.cpp (provides _start, set_tls_ptr, init_tls)
+ aarch64
  - start.cpp (provides _start, set_tls_ptr, init_tls)
+ riscv
  - start.cpp (provides _start, set_tls_ptr, init_tls)
+ do_start.cpp (or some other proper name, provides `do_start` function)
```

Then `do_start.cpp.o` and `{arch}/start.cpp.o` can be merged and generate the final `crt1.o`.


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


More information about the libc-commits mailing list