-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[flang][driver] Don't use -whole-archive on Darwin #75393
[flang][driver] Don't use -whole-archive on Darwin #75393
Conversation
@llvm/pr-subscribers-flang-driver @llvm/pr-subscribers-clang Author: Andrzej Warzyński (banach-space) ChangesDirect follow-up of #7312 - the linker on Darwin does not support For context: Full diff: https://github.com/llvm/llvm-project/pull/75393.diff 1 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 51b336216c5653..4ce456d52c3e5e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1128,20 +1128,24 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
// --whole-archive flag to the link line. If it's not, add a proper
// --whole-archive/--no-whole-archive bracket to the link line.
bool WholeArchiveActive = false;
- for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
- if (Arg)
+ for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA)) {
+ if (Arg) {
for (StringRef ArgValue : Arg->getValues()) {
if (ArgValue == "--whole-archive")
WholeArchiveActive = true;
if (ArgValue == "--no-whole-archive")
WholeArchiveActive = false;
}
+ }
+ }
- if (!WholeArchiveActive)
+ if (!WholeArchiveActive && !TC.getTriple().isMacOSX()) {
CmdArgs.push_back("--whole-archive");
- CmdArgs.push_back("-lFortran_main");
- if (!WholeArchiveActive)
+ CmdArgs.push_back("-lFortran_main");
CmdArgs.push_back("--no-whole-archive");
+ } else {
+ CmdArgs.push_back("-lFortran_main");
+ }
// Perform regular linkage of the remaining runtime libraries.
CmdArgs.push_back("-lFortranRuntime");
|
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. Worked fine on my machine.
NOTE: tested by replacing CommonArgs.cpp
in main, to avoid conflicts.
954ebbb
to
95b4db0
Compare
Thanks for checking and apologies for the merge conflict - I thought that I was up to date :( I've just rebased and force-pushed. I will be landing this today if there are no further comments 🙏🏻 |
This patch seems to hide the original problem of the compiler not erroring out when multiple definitions of main happen. I think we should rather inject the proper linker equivalent of --whole-archive on Darwin, too. I'd be OK to land this patch for now, if we agree to have a follow up PR to (re-)instantiate the error handling also for Darwin. |
To clarify - this patch is a warkaround to avoid reverting #73124. And to buy ourselves some time. I did a bit of research and couldn't find any equivalents for Darwin for
That would be ideal, but I won't have the bandwidth for that. We'll need a volunteer. Another option is to revert #73124. Either way, we need to unblock our Darwin users ASAP :) |
Add an extra comment
The equivalent of |
Some sources (https://stackoverflow.com/questions/16082470/osx-how-do-i-convert-a-static-library-to-a-dynamic-one) suggest the use of
Using it I get a |
I build and
|
I tested this with our build on Mac and we are working again so it fixed the issue we were having. Thanks. |
Let's get this in. I agree with the assessment by @banach-space. The PR looks good to me. |
Unrelated to this PR, but may I ask how do you configure flang, to make it link without errors and without extra flags? |
Disable the test on Darwin
AFAIK, what you really want is this:
But there's no guarantee that this won't change in the future. Now, one should be able to "fix it" within one build of Clang with DEFAULT_SYSROOT. If that works for you - could you document in the Flang docs? 🙏🏻 |
I do not have any special configure. Here is my
|
I already have |
Ok, thanks, I'll try with But it's good to know that using |
Direct follow-up of #73124 - the linker on Darwin does not support
-whole-archive
, so that needs to be removed from the linkerinvocation.
For context: