[llvm] [BOLT] Enable standalone build (PR #97130)

Konrad Kleine via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 12 13:13:14 PST 2025


kwk wrote:

Hi. I'm building BOLT without in non-standalone mode on linux. We recently began building BOLT in this non-standalone mode and I noticed a few odd things.

It looks like these two line changes ([1](https://github.com/llvm/llvm-project/commit/abc2eae68290c453e1899a94eccc4ed5ea3b69c1#diff-c1fe33ffbaf21dd8428f3b040d340236973a944c5a28da8cf877ca7a63456bceL19) and [2](https://github.com/llvm/llvm-project/commit/abc2eae68290c453e1899a94eccc4ed5ea3b69c1#diff-c1fe33ffbaf21dd8428f3b040d340236973a944c5a28da8cf877ca7a63456bceL24)) broke the build of bolt for any recent Git version of LLVM. 19.1.6 compiles fine but that didn't include those aforementioned changed.

Now I wonder if `CMAKE_INSTALL_LIBDIR` is something we should consider setting (differently) or if the patch is bogus. I can get bolt to compile when changing the lines back like so:

```diff
/builddir/build/BUILD/llvm-20.0.0_pre20250109.g5b76a2e51bd276-build/llvm-project-5b76a2e51bd2765ad702cc1b249b9aacac9ea44e/bolt/runtime/CMakeLists.txt
--- /builddir/build/BUILD/llvm-20.0.0_pre20250109.g5b76a2e51bd276-build/llvm-project-5b76a2e51bd2765ad702cc1b249b9aacac9ea44e/bolt/runtime/CMakeLists.txt.old   2025-01-09 10:36:24.486488408 +0000
+++ /builddir/build/BUILD/llvm-20.0.0_pre20250109.g5b76a2e51bd276-build/llvm-project-5b76a2e51bd2765ad702cc1b249b9aacac9ea44e/bolt/runtime/CMakeLists.txt       2025-01-09 11:05:25.691488408 +0000
@@ -16,19 +16,13 @@
   instr.cpp
   ${CMAKE_CURRENT_BINARY_DIR}/config.h
   )
-set_target_properties(bolt_rt_instr PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
+set_target_properties(bolt_rt_instr PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${LLVM_LIBRARY_DIR}")
+
 add_library(bolt_rt_hugify STATIC
   hugify.cpp
   ${CMAKE_CURRENT_BINARY_DIR}/config.h
   )
-set_target_properties(bolt_rt_hugify PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
-
-if(NOT BOLT_BUILT_STANDALONE)
-  add_custom_command(TARGET bolt_rt_instr POST_BUILD
-    COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib/libbolt_rt_instr.a" "${LLVM_LIBRARY_DIR}")
-  add_custom_command(TARGET bolt_rt_hugify POST_BUILD
-    COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib/libbolt_rt_hugify.a" "${LLVM_LIBRARY_DIR}")
-endif()
+set_target_properties(bolt_rt_hugify PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${LLVM_LIBRARY_DIR}")
 
 set(BOLT_RT_FLAGS
   -ffreestanding
```

Apparently `CMAKE_INSTALL_LIBDIR` is set [here](https://github.com/llvm/llvm-project/blob/main/llvm/CMakeLists.txt#L51-L54):

```if (NOT DEFINED CMAKE_INSTALL_LIBDIR AND DEFINED LLVM_LIBDIR_SUFFIX)
  # Must go before `include(GNUInstallDirs)`.
  set(CMAKE_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")
endif()```

For that case the definition of `${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}` in the patch that broke bolt makes no sense IMHO.

`CMAKE_INSTALL_LIBDIR` expands to `lib${LLVM_LIBDIR_SUFFIX}` and so `${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}` expands to `lib${LLVM_LIBDIR_SUFFIX}${LLVM_LIBDIR_SUFFIX}` which doesn't seem right. Or am I not seeing through this correctly?

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


More information about the llvm-commits mailing list