Skip to content

Commit d37d1c8

Browse files
authored
[flang][driver] deprecate manual usage of -lFortran_main (#79016)
Intended to warn users of the 18.x release not to do this. A better solution should be found for the 19.x release. See discussion in #78152. Unfortunately there is no warning on Windows currently. I am rushing to get this landed before 18.x branches.
1 parent be0c809 commit d37d1c8

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ def warn_drv_clang_unsupported : Warning<
427427
"the clang compiler does not support '%0'">;
428428
def warn_drv_deprecated_arg : Warning<
429429
"argument '%0' is deprecated, use '%1' instead">, InGroup<Deprecated>;
430+
def warn_drv_deprecated_custom : Warning<
431+
"argument '%0' is deprecated, %1">, InGroup<Deprecated>;
430432
def warn_drv_assuming_mfloat_abi_is : Warning<
431433
"unknown platform, assuming -mfloat-abi=%0">;
432434
def warn_drv_unsupported_float_abi_by_lib : Warning<

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,19 +1194,31 @@ static void addFortranMain(const ToolChain &TC, const ArgList &Args,
11941194
}
11951195

11961196
// 2. GNU and similar
1197+
const Driver &D = TC.getDriver();
1198+
const char *FortranMainLinkFlag = "-lFortran_main";
1199+
1200+
// Warn if the user added `-lFortran_main` - this library is an implementation
1201+
// detail of Flang and should be handled automaticaly by the driver.
1202+
for (const char *arg : CmdArgs) {
1203+
if (strncmp(arg, FortranMainLinkFlag, strlen(FortranMainLinkFlag)) == 0)
1204+
D.Diag(diag::warn_drv_deprecated_custom)
1205+
<< FortranMainLinkFlag
1206+
<< "see the Flang driver documentation for correct usage";
1207+
}
1208+
11971209
// The --whole-archive option needs to be part of the link line to make
11981210
// sure that the main() function from Fortran_main.a is pulled in by the
11991211
// linker. However, it shouldn't be used if it's already active.
12001212
// TODO: Find an equivalent of `--whole-archive` for Darwin and AIX.
12011213
if (!isWholeArchivePresent(Args) && !TC.getTriple().isMacOSX() &&
12021214
!TC.getTriple().isOSAIX()) {
12031215
CmdArgs.push_back("--whole-archive");
1204-
CmdArgs.push_back("-lFortran_main");
1216+
CmdArgs.push_back(FortranMainLinkFlag);
12051217
CmdArgs.push_back("--no-whole-archive");
12061218
return;
12071219
}
12081220

1209-
CmdArgs.push_back("-lFortran_main");
1221+
CmdArgs.push_back(FortranMainLinkFlag);
12101222
}
12111223

12121224
/// Add Fortran runtime libs

flang/test/Driver/linker-flags.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
! RUN: %flang -### --target=x86_64-unknown-dragonfly %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX
1212
! RUN: %flang -### --target=x86_64-unknown-haiku %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,HAIKU
1313
! RUN: %flang -### --target=x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MINGW
14+
! RUN: %flang -### --target=aarch64-unknown-linux-gnu %S/Inputs/hello.f90 -lFortran_main 2>&1 | FileCheck %s --check-prefixes=DEPRECATED
1415

1516
! NOTE: Clang's driver library, clangDriver, usually adds 'oldnames' on Windows,
1617
! but it is not needed when compiling Fortran code and they might bring in
@@ -53,3 +54,6 @@
5354
! MSVC-LABEL: link
5455
! MSVC-SAME: /subsystem:console
5556
! MSVC-SAME: "[[object_file]]"
57+
58+
! Check that we warn when using -lFortran_main
59+
! DEPRECATED: warning: argument '-lFortran_main' is deprecated, see the Flang driver documentation for correct usage [-Wdeprecated]

0 commit comments

Comments
 (0)