Skip to content

[libc] Make crt1.o available to clang for GPU builds #100599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2024
Merged

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Jul 25, 2024

Summary:
We want to provide the crt1.o object inside of the current build so
that other projects can use it for tests. Because it's currently an
object library (as is also required for the dependencies for the
hermetic tests) this cannot be renamed and is not emitted by default.
Here we simply add an executable that emits bitcode so that CMake will
give it a name.

@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2024

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

Changes

Summary:
We want to provide the crt1.o object inside of the current build so
that other projects can use it for tests. Because it's currently an
object library (as is also required for the dependencies for the
hermetic tests) this cannot be renamed and is not emitted by default.
Here we simply add an executable that emits bitcode so that CMake will
give it a name.


Full diff: https://github.com/llvm/llvm-project/pull/100599.diff

1 Files Affected:

  • (modified) libc/startup/gpu/CMakeLists.txt (+11)
diff --git a/libc/startup/gpu/CMakeLists.txt b/libc/startup/gpu/CMakeLists.txt
index 6f67fa9ff44f7..f1706c1a2e317 100644
--- a/libc/startup/gpu/CMakeLists.txt
+++ b/libc/startup/gpu/CMakeLists.txt
@@ -26,6 +26,16 @@ function(add_startup_object name)
     PROPERTIES
       OUTPUT_NAME ${name}.o
   )
+
+  # Make an executable target of relocatable bitcode for clang if needed.
+  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
+    add_executable(${fq_target_name}.exe $<TARGET_OBJECTS:${fq_target_name}>)
+    set_target_properties(${fq_target_name}.exe PROPERTIES
+      RUNTIME_OUTPUT_DIRECTORY ${LIBC_LIBRARY_DIR}
+      RUNTIME_OUTPUT_NAME ${name}.o)
+    target_link_options(${fq_target_name}.exe PRIVATE 
+                        "-flto" "-Wl,--lto-emit-llvm" "-march=sm_90")
+  endif()
 endfunction()
 
 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
@@ -44,6 +54,7 @@ set(startup_components crt1)
 foreach(target IN LISTS startup_components)
   set(fq_target_name libc.startup.gpu.${target})
   add_dependencies(libc-startup ${fq_target_name})
+
   install(FILES $<TARGET_OBJECTS:${fq_target_name}>
           DESTINATION ${LIBC_INSTALL_LIBRARY_DIR}
           RENAME $<TARGET_PROPERTY:${fq_target_name},OUTPUT_NAME>

RUNTIME_OUTPUT_DIRECTORY ${LIBC_LIBRARY_DIR}
RUNTIME_OUTPUT_NAME ${name}.o)
target_link_options(${fq_target_name}.exe PRIVATE
"-flto" "-Wl,--lto-emit-llvm" "-march=sm_90")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to hard-code the -march here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a hack, I can probably patch clang for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It pretty much just needs to be there to make clang happy, I'll just leave it blank for now.

@jhuber6 jhuber6 force-pushed the Startup branch 2 times, most recently from 441c12a to d1d1a89 Compare July 26, 2024 12:26
@jhuber6
Copy link
Contributor Author

jhuber6 commented Jul 26, 2024

I think I can use this trick to get the bitcode version as well without needing llvm-link.

Summary:
We want to provide the `crt1.o` object inside of the current build so
that other projects can use it for tests. Because it's currently an
object library (as is also required for the dependencies for the
hermetic tests) this cannot be renamed and is not emitted by default.
Here we simply add an executable that emits bitcode so that CMake will
give it a name.
@jhuber6 jhuber6 merged commit 0fa53d5 into llvm:main Jul 26, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants