[llvm] [llvm] Disable some LLVM arguments in runtimes mode (PR #73031)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 21 12:09:53 PST 2023


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/73031

Summary:
There are a few default options that LLVM adds that can be problematic
for runtimes builds. These options are generally intended to handle
building LLVM itself, but are also added when building in a runtimes
mode. One such issue I've run into is that in `libc` we deliberately use
`--target` to use a different device toolchain, which doesn't support
some linker arguments passed via `-Wl`. This is observed in
https://github.com/llvm/llvm-project/pull/73030 when attempting to use
these options.

This pass simply disables the `-Wl,--color-diagnostics` option as a
start. However, it may  be prudent to disable many such default options
when building the runtimes.


>From 1676111f525a2eb5bc430f401a367815ea836bd3 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 21 Nov 2023 14:06:38 -0600
Subject: [PATCH] [llvm] Disable some LLVM arguments in runtimes mode

Summary:
There are a few default options that LLVM adds that can be problematic
for runtimes builds. These options are generally intended to handle
building LLVM itself, but are also added when building in a runtimes
mode. One such issue I've run into is that in `libc` we deliberately use
`--target` to use a different device toolchain, which doesn't support
some linker arguments passed via `-Wl`. This is observed in
https://github.com/llvm/llvm-project/pull/73030 when attempting to use
these options.

This pass simply disables the `-Wl,--color-diagnostics` option as a
start. However, it may  be prudent to disable many such default options
when building the runtimes.
---
 llvm/cmake/modules/HandleLLVMOptions.cmake | 2 +-
 runtimes/CMakeLists.txt                    | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 6a3c49edc912ded..b97ea496c8f5d0a 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1064,7 +1064,7 @@ if (UNIX AND
 endif()
 
 # lld doesn't print colored diagnostics when invoked from Ninja
-if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja")
+if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja" AND NOT LLVM_RUNTIMES_BUILD)
   include(LLVMCheckLinkerFlag)
   llvm_check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS)
   append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics"
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 010ec879e44a322..69c3ec780ee76d0 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -151,6 +151,9 @@ endif()
 # Avoid checking whether the compiler is working.
 set(LLVM_COMPILER_CHECKED ON)
 
+# This can be used to detect whether we're in the runtimes build.
+set(LLVM_RUNTIMES_BUILD ON)
+
 # Handle common options used by all runtimes.
 include(AddLLVM)
 include(HandleLLVMOptions)
@@ -179,9 +182,6 @@ if(CMAKE_HOST_APPLE AND APPLE)
   include(UseLibtool)
 endif()
 
-# This can be used to detect whether we're in the runtimes build.
-set(LLVM_RUNTIMES_BUILD ON)
-
 foreach(entry ${runtimes})
   get_filename_component(projName ${entry} NAME)
 



More information about the llvm-commits mailing list