[llvm] [DRAFT][Runtimes] Don't execute flang during the runtimes configure step (PR #205458)
Eugene Epshteyn via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 23 17:01:30 PDT 2026
https://github.com/eugeneepshteyn updated https://github.com/llvm/llvm-project/pull/205458
>From 9b762ef45977260423ddb32b62179061696aa791 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Tue, 23 Jun 2026 19:56:45 -0400
Subject: [PATCH] [Runtimes] Don't execute flang during the runtimes configure
step
The runtimes external-project configure step runs `flang` for CMake's Fortran
compiler identification and ABI detection (`enable_language(Fortran)` in
`runtimes/cmake/config-Fortran.cmake`). #198205 deliberately removed `flang`
from the configure dependency so the runtimes configure can run concurrently
with the (heavy) flang/MLIR build; the mock `flang-lazy`/`fakeflang` driver was
added so the identification probe could pass without the real compiler.
That is not enough in a shared-library build: the just-built `flang` and its
shared libraries (e.g. `libFortranLower.so`) are produced by independent build
steps, and on an incremental build a real `bin/flang` left over from a previous
build is executed while this build is relinking those libraries. Running it
then fails with "error while loading shared libraries: libFortranLower.so:
file too short", aborting the runtimes configure (llvm/llvm-project#205360).
Rather than re-adding a dependency on the full `flang` target -- which would
serialize the heavy compiler build ahead of the configure step and dramatically
increase build times -- force the Fortran compiler identity so
`enable_language(Fortran)` does not execute the compiler at all.
`CMAKE_Fortran_COMPILER_ID_RUN` skips identification and
`CMAKE_Fortran_COMPILER_FORCED` skips the ABI/works probe; `flang` is therefore
never run during configure, eliminating the race while keeping the configure
step off flang's build critical path. This was previously done only for
CMake < 3.24 (via the now-removed `CMAKE_FORCE_Fortran_COMPILER`); it now
applies to all supported CMake versions, with CMake 3.24+ still supplying the
LLVMFlang command templates.
---
runtimes/cmake/config-Fortran.cmake | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake
index 74fd15021f0a0..d3d219ea73bf5 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -88,15 +88,27 @@ if (CMAKE_Fortran_COMPILER)
# cannot use CMAKE_Fortran_COMPILER_ID.
cmake_path(GET CMAKE_Fortran_COMPILER STEM _Fortran_COMPILER_STEM)
if (_Fortran_COMPILER_STEM STREQUAL "flang-new" OR _Fortran_COMPILER_STEM STREQUAL "flang")
+ # Force the Fortran compiler identity instead of letting CMake detect it by
+ # executing the compiler. enable_language(Fortran) below would otherwise run
+ # `flang` for both compiler identification and ABI detection. In a
+ # bootstrapping runtimes build, the just-built `flang` and its shared
+ # libraries (e.g. libFortranLower.so) are produced by independent build
+ # steps, so executing `flang` during the (deliberately early, see #198205)
+ # runtimes configure step can race with the linking or relinking of those
+ # libraries -- "error while loading shared libraries: ...: file too short".
+ # Forcing the identity keeps the runtimes configure off flang's build
+ # critical path while avoiding that race (llvm-project#205360).
+ # CMAKE_Fortran_COMPILER_ID_RUN skips compiler identification and
+ # CMAKE_Fortran_COMPILER_FORCED skips the ABI/works probe, so neither
+ # executes flang.
+ set(CMAKE_Fortran_COMPILER_ID "LLVMFlang")
+ set(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
+ set(CMAKE_Fortran_COMPILER_FORCED TRUE)
+ set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
+
# CMake 3.24 is the first version of CMake that directly recognizes Flang.
# LLVM's requirement is only CMake 3.20, teach CMake 3.20-3.23 how to use Flang, if used.
if (CMAKE_VERSION VERSION_LESS "3.24")
- include(CMakeForceCompiler)
- CMAKE_FORCE_Fortran_COMPILER("${CMAKE_Fortran_COMPILER}" "LLVMFlang")
-
- set(CMAKE_Fortran_COMPILER_ID "LLVMFlang")
- set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
-
set(CMAKE_Fortran_SUBMODULE_SEP "-")
set(CMAKE_Fortran_SUBMODULE_EXT ".mod")
More information about the llvm-commits
mailing list