[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:57:43 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:

Yes, I hope to separate `do_start` out of `start.cpp` immediately after this patch. 

Some other related changes:
- `x86_64` does not have `do_start` for now, it can be changed to
```c++
extern "C" void _start() {
  app.args = reinterpret_cast<LIBC_NAMESPACE::Args *>(
        reinterpret_cast<uintptr_t *>(__builtin_frame_address(0)) + 1);
  __asm__ __volatile__("andq $0xfffffffffffffff0, %rsp\n\t");
  __asm__ __volatile__("andq $0xfffffffffffffff0, %rbp\n\t");
  do_start()
}
```
- for `riscv`, move the following to `_start`:
   ```c++
     LIBC_INLINE_ASM(".option push\n\t"
                  ".option norelax\n\t"
                  "lla gp, __global_pointer$\n\t"
                  ".option pop\n\t");
    ```


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


More information about the libc-commits mailing list