From 65fbe16e16e0db5fe3ea2cedb9ed99ab1f73f5db Mon Sep 17 00:00:00 2001 From: Simon Maertens Date: Tue, 5 May 2026 19:18:02 +0100 Subject: [PATCH] NAG Fortran: Use `-xldarg @` to pass response files to the linker The `nagfor` compiler driver does not invoke the linker directly. Instead it runs the system C compiler driver, which then invokes the linker. Passing `@` to NAG Fortran expands the response file before it reaches the linker, which might lead to too long linker lines. `-Wl,@`, used since commit 10d6c3a635 (NAG: Pass response files through front-end to the linker, 2018-08-01, v3.13.0-rc1~244^2), can lead to wrong placement of the response file on the linker line and doesn't work at all when the response file is the only object file passed to the NAG Fortran frontend. Instead use `-xldarg @` to pass a response file through to the linker without any intermediate expansion. However, the response file generated by Ninja can contain flags meant for the compiler driver, so we need to disable response files for these flags altogether. Fixes: #23577 --- Modules/Compiler/NAG-Fortran.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Modules/Compiler/NAG-Fortran.cmake b/Modules/Compiler/NAG-Fortran.cmake index 4eb316224d..7d5a431114 100644 --- a/Modules/Compiler/NAG-Fortran.cmake +++ b/Modules/Compiler/NAG-Fortran.cmake @@ -44,8 +44,13 @@ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free") set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-PIC") set(CMAKE_Fortran_COMPILE_OPTIONS_PIE "-PIC") -set(CMAKE_Fortran_RESPONSE_FILE_LINK_FLAG "-Wl,@") -set(CMAKE_Fortran_RESPONSE_FILE_ARCHIVE_FLAG "@") +if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2) + set(CMAKE_Fortran_RESPONSE_FILE_LINK_FLAG "-xldarg @") + set(CMAKE_Fortran_RESPONSE_FILE_ARCHIVE_FLAG "@") + set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_LIBRARIES 0) +else() + set(CMAKE_Fortran_RESPONSE_FILE_LINK_FLAG "@") +endif() set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-fpp") set(CMAKE_Fortran_LINK_MODE DRIVER)