[llvm] [BOLT] Enable cross compilation of runtime libraries (PR #101180)

Peter Waller via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 3 05:36:56 PDT 2024


================
@@ -135,36 +134,168 @@ if (LLVM_INCLUDE_TESTS)
   endif()
 endif()
 
-if (BOLT_ENABLE_RUNTIME)
-  message(STATUS "Building BOLT runtime libraries for X86")
-  set(extra_args "")
-  if(CMAKE_SYSROOT)
-    list(APPEND extra_args -DCMAKE_SYSROOT=${CMAKE_SYSROOT})
+set(AARCH64_GNU_C_COMPILER aarch64-linux-gnu-gcc)
+set(AARCH64_GNU_CXX_COMPILER aarch64-linux-gnu-g++)
+set(X86_64_GNU_C_COMPILER x86_64-linux-gnu-gcc)
+set(X86_64_GNU_CXX_COMPILER x86_64-linux-gnu-g++)
+set(RISCV_GNU_C_COMPILER riscv64-linux-gnu-gcc)
+set(RISCV_GNU_CXX_COMPILER riscv64-linux-gnu-g++)
+
+function(bolt_rt_target_supported_clang target supported)
+
+    if(${target} STREQUAL ${HOST_NAME})
+      set(${supported} TRUE PARENT_SCOPE)
+      return()
+    elseif(${target} STREQUAL "X86")
+      set(CMAKE_CXX_FLAGS "--target=x86_64-linux-gnu")
+    elseif(${target} STREQUAL "AArch64")
+      set(CMAKE_CXX_FLAGS "--target=aarch64-linux-gnu")
+    elseif(${target} STREQUAL "RISCV")
+      set(CMAKE_CXX_FLAGS "--target=riscv64-linux-gnu")
+    endif()
+
+    try_compile(CROSS_COMP
+      ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeScratch
+      SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/test/test.cpp
+      CMAKE_FLAGS ${CMAKE_CXX_FLAGS}
+      TRY_COMP_OUTPUT)
----------------
peterwaller-arm wrote:

My read of the docs is that CMAKE_FLAGS accepts flags intended for an underyling cmake invocation used for the try compile. [It says](https://cmake.org/cmake/help/v3.20/command/try_compile.html):

> `CMAKE_FLAGS`: Specify flags of the form -DVAR:TYPE=VALUE to be passed to the cmake command-line used to drive the test build. The above example shows how values for variables INCLUDE_DIRECTORIES, LINK_DIRECTORIES, and LINK_LIBRARIES are used.

If this is to be believed, then saying `CMAKE_FLAGS --target=x86_64-linux-gnu` would be wrong since `--target` is a compiler flag, not a cmake flag.

I imagine that cmake is also passing `CMAKE_CXX_FLAGS` through within `try_compile`, which is probably why it works. But usually this is coming from the cmake cache and can be specified by the user on the command line, so I'm not sure if you'd want to wholesale overwrite it here. That said we're cross compiling here and I'm not quite certain what the right thing to do would be. Maybe what you're doing is fine-- except, does it work if you drop `CMAKE_FLAGS ${CMAKE_CXX_FLAGS}`? If so that suggests my hypothesis about cmake passing it within try_compile.

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


More information about the llvm-commits mailing list