This is an archive of the discontinued LLVM Phabricator instance.

[flang][driver] Allow main program to be in an archive
ClosedPublic

Authored by ekieri on Sep 28 2022, 12:16 PM.

Details

Summary

Add --undefined=_QQmain to the link line, so that a Fortran main program
will be included in the link job even if it is in an archive (unless we
are building a shared object). For now, this is only applied to the Gnu
toolchain.

We also add a section on the linker invocation to docs/FlangDriver.md.

The new tests require llvm-ar to construct an archive we can include in
the link job. This is a new dependency for flang/test (which already
depends on similar tools such as llvm-objdump).

See discussions in
https://github.com/llvm/llvm-project/issues/54787
which this patch fixes.

Diff Detail

Event Timeline

ekieri created this revision.Sep 28 2022, 12:16 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 28 2022, 12:16 PM
ekieri requested review of this revision.Sep 28 2022, 12:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2022, 12:16 PM

CI fail noted, update will come.

ekieri updated this revision to Diff 463998.Sep 29 2022, 12:46 PM

Fix test link-f90-main.f90, which was failing for statically linked builds.

awarzynski accepted this revision.EditedSep 29 2022, 1:55 PM

Great stuff @ekieri , thanks for doing this!

You may want add a note in the summary that you've updated the docs as well. This is consistent with what we discussed in https://github.com/llvm/llvm-project/issues/54787. I've left a few minor comments, but otherwise LGTM.

Edit Please address my comments before landing :) Also, allow a couple more days for other reviewers to comment.

clang/lib/Driver/ToolChains/Gnu.cpp
601–603

I would add a reference to the GitHub issue too.

flang/docs/FlangDriver.md
152–158

Oh, good catch, completely forgot about this!

This is an unrelated change, but the noise is low and I'm happy for it to be included. You can also submit it as a separate patch if you want.

202
202–204
208

;-)

211
214

add default options

Perhaps clarify "where" (i.e. to the frontend driver and the linker invocations).

220
223
224
226
229
231
233
flang/test/Driver/link-c-main.c
8

Same for the other test. Let me know if you'd like somebody to test this for you on AArch64 ;-)

26–27

I'd be tempted to add a note that:

  • main ought to be defined as it's specified in this file
  • _QQmain should remain undefined as no Fortran-based object file generated by Flang is linked in

This is quite tricky stuff and in such cases "more is more" :)

flang/test/Driver/linker-flags.f90
63–67

How is this different to GNU-SAME?

This revision is now accepted and ready to land.Sep 29 2022, 1:55 PM

Please fix the clang-format issue.

ekieri abandoned this revision.Apr 24 2023, 10:42 AM

Sorry to drop out on this. I got interrupted by other duties in life, and now I am no longer able to continue this work. If anybody wants to pick up the ball from here, please feel free to commandeer the patch.

I would like to help land this patch.

Address comments

This revision is now accepted and ready to land.Apr 24 2023, 11:28 AM

Thanks for all the great effort, @ekieri !

@sunshaoce , mostly makes sense, just a few small suggestions. @peixin , wdyt?

clang/lib/Driver/ToolChains/Gnu.cpp
601–603

WDYT>

flang/test/Driver/link-c-main.c
4
6
flang/test/Driver/linker-flags.f90
15

Please, could you clarify that in this case _QQmain should not be flagged as undefined?

64

Address @awarzynski's comments

Any further suggestions?

awarzynski accepted this revision.Apr 27 2023, 5:51 AM

Any further suggestions?

I am happy for you to land this, thanks! LGTM

This revision was landed with ongoing or failed builds.Apr 27 2023, 6:53 PM
This revision was automatically updated to reflect the committed changes.

I've just reverted this patch - for context please see https://reviews.llvm.org/D149429.

@sunshaoce This was committed without acknowledging @ekieri 's contribution, so didn't follow the official guidelines: Attribution of Changes. IMHO, we should keep Emil as the author of this change (he has done the lion share of this highly non-trivial work) and add you as a co-author. Unless @ekieri has some other preference :) (I am happy as long as we follow the guidelines).

Either way, thank you both for contributing! Now, lets try to figure out what caused the issue with the bots.

I've just reverted this patch - for context please see https://reviews.llvm.org/D149429.

@sunshaoce This was committed without acknowledging @ekieri 's contribution, so didn't follow the official guidelines: Attribution of Changes. IMHO, we should keep Emil as the author of this change (he has done the lion share of this highly non-trivial work) and add you as a co-author. Unless @ekieri has some other preference :) (I am happy as long as we follow the guidelines).

Either way, thank you both for contributing! Now, lets try to figure out what caused the issue with the bots.

Sorry for not following the official attribution guidelines. I agree with your suggestion to keep @ekieri as the main author. Thank you!

peixin added a comment.May 3 2023, 5:56 PM

@peixin , wdyt?

@awarzynski Hi Andrzej, sorry for the late reply. I am distracted by several internal projects and other things in my life recently (just came back from vacation). My boss has not decided to let me continue working on LLVM Flang this year, yet.

@peixin , wdyt?

@awarzynski Hi Andrzej, sorry for the late reply. I am distracted by several internal projects and other things in my life recently (just came back from vacation). My boss has not decided to let me continue working on LLVM Flang this year, yet.

No worries, thank you for letting us know Peixin!