-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Driver] Link Flang runtime on Solaris #65644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I noticed that `flang-new` cannot link Fortran executables on Solaris since the runtime libs are missing. This patch fixes this, following `Gnu.cpp`. The `linker-flags.f90` testcase is augmented to test for this. Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and `x86_64-pc-linux-gnu`.
flang/test/Driver/linker-flags.f90
Outdated
@@ -4,6 +4,7 @@ | |||
|
|||
! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,GNU | |||
! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN | |||
! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,GNU |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solaris is not GNU ;-) Please use a dedicated prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but how many more copies of the same patterns do we want? Add FreeBSD, OpenBSD, ... whenever they arrive? Isn't the common pattern <linker> <object file> <flang rt libs>
with or without -lm
? How about putting the first under one label and the -lm
part under another, used where appropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, reducing duplication would be nice. Could you propose something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@banach-space How should we proceed with this one? Really introduce separate labels for each OS, even if the checks are identical? Or consolidate labels as I suggested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consolidate like you suggested. Perhaps the common prefix cold be "ALL-RT-LIBS" or "FLANG-RT-LIBS"? Suggestions welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add FreeBSD, OpenBSD, ... whenever they arrive?
Bumping into this PR that'll be happening much sooner for all of the *BSD's now.
One thing to add to this. I noticed the Gnu addition does not check for |
Because of where the chunk is being added in the Solaris ToolChain (and what I had in my tree for *BSD's) it is checking for the tools::gnutools::Linker::ConstructJob
solaris::Linker::ConstructJob
|
I'd argue that handling the Flang runtime libs like C++ is the right thing to do here. However, |
Looking at the GNU linker it seems to ignore -Bdynamic once -r is specified. Not sure how LLD handles things. The OpenBSD driver might need adjustments for the same thing. |
The different behaviour can easily be seen since Solaris
I'll either fix the Solaris driver code not to pass However, for the patch at hand this is moot while
I wonder how to proceed with the patch at hand. |
I'm not a Solaris expert, but based on this discussion I'd consider adding support for One important rule of thumb that I'd stick to:
In cases where there's different behavior between these compilers, just go for whatever feels most sensible, but please document your design decision. |
I'd like for this to move forward. |
Support of However, Flang accepts none of those options yet, which it should for compatiblity with both
Fully agreed: I've now checked that gfortran handles all of |
Agreed: AFAICS the only open issue is whether the Solaris test should use the |
I think having additional tests makes sense if there is some variation on what is being checked but not when it's just copying and pasting the same thing with a different label. |
I feel that we are bike-shedding here a bit. Please prioritise correctness - using
Unless I am missing something? |
I'd go for renaming the label to |
That would be fine with me. |
@llvm/pr-subscribers-clang Author: Rainer Orth (rorth) ChangesI noticed that This patch fixes this, following Tested on Full diff: https://github.com/llvm/llvm-project/pull/65644.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp
index 36fe12608eefc6c..252c71d3379eab4 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -223,6 +223,14 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
CmdArgs.push_back("-lm");
}
+ // Additional linker set-up and flags for Fortran. This is required in order
+ // to generate executables. As Fortran runtime depends on the C runtime,
+ // these dependencies need to be listed before the C runtime below.
+ if (D.IsFlangMode()) {
+ addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
+ addFortranRuntimeLibs(getToolChain(), CmdArgs);
+ CmdArgs.push_back("-lm");
+ }
if (Args.hasArg(options::OPT_fstack_protector) ||
Args.hasArg(options::OPT_fstack_protector_strong) ||
Args.hasArg(options::OPT_fstack_protector_all)) {
diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..fd61825eb4023a5 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -2,8 +2,9 @@
! invocation. These libraries are added on top of other standard runtime
! libraries that the Clang driver will include.
-! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX
! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX
! RUN: %flang -### -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MINGW
! NOTE: Clang's driver library, clangDriver, usually adds 'libcmt' and
@@ -21,12 +22,12 @@
! run on any other platform, such as Windows that use a .exe
! suffix. Clang's driver will try to resolve the path to the ld
! executable and may find the GNU linker from MinGW or Cygwin.
-! GNU-LABEL: "{{.*}}ld{{(\.exe)?}}"
-! GNU-SAME: "[[object_file]]"
-! GNU-SAME: -lFortran_main
-! GNU-SAME: -lFortranRuntime
-! GNU-SAME: -lFortranDecimal
-! GNU-SAME: -lm
+! UNIX-LABEL: "{{.*}}ld{{(\.exe)?}}"
+! UNIX-SAME: "[[object_file]]"
+! UNIX-SAME: -lFortran_main
+! UNIX-SAME: -lFortranRuntime
+! UNIX-SAME: -lFortranDecimal
+! UNIX-SAME: -lm
! DARWIN-LABEL: "{{.*}}ld{{(\.exe)?}}"
! DARWIN-SAME: "[[object_file]]"
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for all the improvements!
Before merging, could you update the summary and briefly mention the additional changes made here? Otherwise people might think that these changes are required, but that's not strictly the case.
As discussed in [[Driver] Link Flang runtime on Solaris](llvm#65644), `clang -r` incorrectly passes both `-Bdynamic` and `-e _start` to `ld` which lets the linker choke. This patch fixes this, omitting `-Bdynamic` completely which is the linker default. Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
As discussed in [[Driver] Link Flang runtime on Solaris](#65644), `clang -r` incorrectly passes both `-Bdynamic` and `-e _start` to `ld` which lets the linker choke. This patch fixes this, omitting `-Bdynamic` completely which is the linker default. Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
I noticed that
flang-new
cannot link Fortran executables on Solaris since the runtime libs are missing.This patch fixes this, following
Gnu.cpp
. Thelinker-flags.f90
testcase is augmented to test for this.Tested on
amd64-pc-solaris2.11
,sparcv9-sun-solaris2.11
, andx86_64-pc-linux-gnu
.