Skip to content

Commit dea50a1

Browse files
[flang][Driver] Enable FLANG_DEFAULT_LINKER (#149786)
The default linker can be changed by a CMake variable CLANG_DEFAULT_LINKER. However, it also changes the default linker invoked by clang. In fact, there already exists FLANG_DEFAULT_LINKER, but it does not work. This patch fixes it. Note that FLANG_DEFAULT_LINKER will have the same value as CLANG_DEFAULT_LINKER unless it is defined explicitly. That means this patch does not affect the current behavior. Fixes #73153 --------- Co-authored-by: Michael Kruse <[email protected]>
1 parent 06fd0f9 commit dea50a1

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

flang/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ if (NOT ENABLE_LINKER_BUILD_ID)
317317
set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
318318
endif()
319319

320-
set(FLANG_DEFAULT_LINKER "" CACHE STRING
320+
set(FLANG_DEFAULT_LINKER "${CLANG_DEFAULT_LINKER}" CACHE STRING
321321
"Default linker to use (linker name or absolute path, empty for platform default)")
322322

323323
set(FLANG_DEFAULT_RTLIB "" CACHE STRING
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#===-- include/flang/Config/config.h.cmake ---------------------------------===#
2-
#
3-
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4-
# See https://llvm.org/LICENSE.txt for license information.
5-
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6-
#
7-
#===------------------------------------------------------------------------===#
1+
//===-- include/flang/Config/config.h.cmake -------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
88

99
/* This generated file is for internal use. Do not include it from headers. */
1010

@@ -16,6 +16,8 @@
1616

1717
#define FLANG_VERSION "${FLANG_VERSION}"
1818

19+
#define FLANG_DEFAULT_LINKER "${FLANG_DEFAULT_LINKER}"
20+
1921
#endif
2022

2123

flang/test/Driver/linker-flags.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
! MINGW-SAME: -lflang_rt.runtime
7878
! MINGW-STATIC-FLANGRT: "{{.*}}{{\\|/}}libflang_rt.runtime.a"
7979

80-
! NOTE: This also matches lld-link (when CLANG_DEFAULT_LINKER=lld) and
80+
! NOTE: This also matches lld-link (when FLANG_DEFAULT_LINKER=lld) and
8181
! any .exe suffix that is added when resolving to the full path of
8282
! (lld-)link.exe on Windows platforms. The suffix may not be added
8383
! when the executable is not found or on non-Windows platforms.

flang/tools/flang-driver/driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#include "clang/Driver/Driver.h"
19+
#include "flang/Config/config.h"
1920
#include "flang/Frontend/CompilerInvocation.h"
2021
#include "flang/Frontend/TextDiagnosticPrinter.h"
2122
#include "clang/Basic/Diagnostic.h"
@@ -137,6 +138,7 @@ int main(int argc, const char **argv) {
137138
llvm::sys::getDefaultTargetTriple(), diags,
138139
"flang LLVM compiler");
139140
theDriver.setTargetAndMode(targetandMode);
141+
theDriver.setPreferredLinker(FLANG_DEFAULT_LINKER);
140142
#ifdef FLANG_RUNTIME_F128_MATH_LIB
141143
theDriver.setFlangF128MathLibrary(FLANG_RUNTIME_F128_MATH_LIB);
142144
#endif

0 commit comments

Comments
 (0)