public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/100724] New: -fwhole-program breaks module use
@ 2021-05-22 14:21 fx at gnu dot org
  2021-05-23 19:19 ` [Bug fortran/100724] " anlauf at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: fx at gnu dot org @ 2021-05-22 14:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100724

            Bug ID: 100724
           Summary: -fwhole-program breaks module use
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fx at gnu dot org
  Target Milestone: ---

I found that trying gfortran -fwhole-program failed to link a case I tried,
with undefined references to routines with interface blocks.  It's OK with
gfortran 10.
Here's a trivial example (on Debian 10, but I don't suppose that matters):

$ gfortran-11 --version
GNU Fortran (GCC) 11.1.0
$ cat test.f90
module tw
  interface
     real function twice (x)
     end function twice
  end interface
end module tw

real function twice (x)
  twice = 2*x
end function twice

use tw
read *, x
print *, twice (x)
end
$ gfortran-11 -O -fwhole-program test.f90 
/usr/bin/ld: /tmp/ccBKHiLp.o: in function `MAIN__':
test.f90:(.text+0x7d): undefined reference to `twice_'
collect2: error: ld returned 1 exit status

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/100724] -fwhole-program breaks module use
  2021-05-22 14:21 [Bug fortran/100724] New: -fwhole-program breaks module use fx at gnu dot org
@ 2021-05-23 19:19 ` anlauf at gcc dot gnu.org
  2021-05-24 11:04 ` fx at gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-05-23 19:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100724

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |7.5.0
     Ever confirmed|0                           |1
           Keywords|                            |link-failure, wrong-code
   Last reconfirmed|                            |2021-05-23
                 CC|                            |anlauf at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from anlauf at gcc dot gnu.org ---
Interesting bug.

With optimization enabled (e.g. -O) I find a linking failure with 8.5.0
and newer, except when I add -ftlo.

With -fwhole-program -O -flto the program seems to work up to 11.1, but
fails with 12.0 (hangs).

With -fwhole-program -O0 it also hangs with 12.0, but not with 11.1.

So there are possibly two issues, a 12-regression and an 8+-regression.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/100724] -fwhole-program breaks module use
  2021-05-22 14:21 [Bug fortran/100724] New: -fwhole-program breaks module use fx at gnu dot org
  2021-05-23 19:19 ` [Bug fortran/100724] " anlauf at gcc dot gnu.org
@ 2021-05-24 11:04 ` fx at gnu dot org
  2021-05-24 19:59 ` anlauf at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: fx at gnu dot org @ 2021-05-24 11:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100724

--- Comment #2 from Dave Love <fx at gnu dot org> ---
The manual says not to use -flto with -fwhole-program.  Is that misleading?

I checked self-built gfortran 10.2.0 again, and it definitely works for me
without -flto on Debian 10, but it fails with Red Hat devtoolset's 10.2.1 on
RHEL7.  Odd...

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/100724] -fwhole-program breaks module use
  2021-05-22 14:21 [Bug fortran/100724] New: -fwhole-program breaks module use fx at gnu dot org
  2021-05-23 19:19 ` [Bug fortran/100724] " anlauf at gcc dot gnu.org
  2021-05-24 11:04 ` fx at gnu dot org
@ 2021-05-24 19:59 ` anlauf at gcc dot gnu.org
  2021-05-25  7:18 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-05-24 19:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100724

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |10.3.1, 11.1.0, 12.0,
                   |                            |8.5.0, 9.3.1
      Known to work|                            |9.2.0

--- Comment #3 from anlauf at gcc dot gnu.org ---
(In reply to Dave Love from comment #2)
> The manual says not to use -flto with -fwhole-program.  Is that misleading?

I guess the manual entry has a reason, but I do not know why the optimimzations
implied by these options should not be combined.

> I checked self-built gfortran 10.2.0 again, and it definitely works for me
> without -flto on Debian 10, but it fails with Red Hat devtoolset's 10.2.1 on
> RHEL7.  Odd...

I checked against gfortran 9.2.0, which works fine, whereas the current
development version 9.3.1 fails too.

The change likely happened in a newer developer version and was backported
to the release branches.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/100724] -fwhole-program breaks module use
  2021-05-22 14:21 [Bug fortran/100724] New: -fwhole-program breaks module use fx at gnu dot org
                   ` (2 preceding siblings ...)
  2021-05-24 19:59 ` anlauf at gcc dot gnu.org
@ 2021-05-25  7:18 ` rguenth at gcc dot gnu.org
  2021-05-25 10:48 ` fx at gnu dot org
  2021-05-25 19:19 ` hubicka at ucw dot cz
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-25  7:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100724

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
-fwhole-program means the program is entirely confined within a single TU,
using
modules might break this in subtle ways.  -fwhole-program is really sth
"legacy" meant to help with LTO and the case where no linker plugin is
available.  When a linker plugin is available just -flto is as powerful and
using -fwhole-program will only result in subtly to debug issues if you "lied"
to GCC.

I can reproduce the -fwhole-program issue with GCC 10 as well and this likely
means the Fortran FE creates invalid GENERIC and thus two distinct 'twice'
function declarations.

With -flto the WPA stage will unify those, "fixing" the issue (basically
treating the single TU as two distinct TUs which they appearantly are).

When I -fdump-ipa-cgraph-details I indeed see:

twice_/10 (twice) @0x7ffff69cdca8
  Type: function
  Visibility: external public
  References:
  Referring:
  Function flags:
  Called by: MAIN__/1
  Calls:
twice_/0 (twice) @0x7ffff69cd000
  Type: function definition analyzed
  Visibility: public
  Aux: @0x7ffff69cd2d0
  References:
  Referring:
  Function flags: body
  Called by:
  Calls:

so there's an external 'twice' called by main and a distinct, unused,
definition 'twice'.  With -fwhole-program you tell GCC that there are
no external users and thus the definition gets promoted 'static' and
is eliminated as unused (GCC doesn't consider it resolving the call
to the external 'twice' which we might consider a bug - but we expect
the frontends to resolve those internal bindings).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/100724] -fwhole-program breaks module use
  2021-05-22 14:21 [Bug fortran/100724] New: -fwhole-program breaks module use fx at gnu dot org
                   ` (3 preceding siblings ...)
  2021-05-25  7:18 ` rguenth at gcc dot gnu.org
@ 2021-05-25 10:48 ` fx at gnu dot org
  2021-05-25 19:19 ` hubicka at ucw dot cz
  5 siblings, 0 replies; 7+ messages in thread
From: fx at gnu dot org @ 2021-05-25 10:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100724

--- Comment #5 from Dave Love <fx at gnu dot org> ---
Thanks for the explanation.

Could the manual entry for -fwhole-program just be amended to clarify that it's
a fallback for when a linker plugin isn't available for -flto.  That may be
what it was intended to say, but it's not clear to me.  I used -fwhole-program
because it seemed to fit my case exactly.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/100724] -fwhole-program breaks module use
  2021-05-22 14:21 [Bug fortran/100724] New: -fwhole-program breaks module use fx at gnu dot org
                   ` (4 preceding siblings ...)
  2021-05-25 10:48 ` fx at gnu dot org
@ 2021-05-25 19:19 ` hubicka at ucw dot cz
  5 siblings, 0 replies; 7+ messages in thread
From: hubicka at ucw dot cz @ 2021-05-25 19:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100724

--- Comment #6 from Jan Hubicka <hubicka at ucw dot cz> ---
> Could the manual entry for -fwhole-program just be amended to clarify that it's
> a fallback for when a linker plugin isn't available for -flto.  That may be
> what it was intended to say, but it's not clear to me.  I used -fwhole-program
> because it seemed to fit my case exactly.

It can be also used in non-lto if your program has only one source file
and FE is not producing duplicated decls...

Honza

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-25 19:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-22 14:21 [Bug fortran/100724] New: -fwhole-program breaks module use fx at gnu dot org
2021-05-23 19:19 ` [Bug fortran/100724] " anlauf at gcc dot gnu.org
2021-05-24 11:04 ` fx at gnu dot org
2021-05-24 19:59 ` anlauf at gcc dot gnu.org
2021-05-25  7:18 ` rguenth at gcc dot gnu.org
2021-05-25 10:48 ` fx at gnu dot org
2021-05-25 19:19 ` hubicka at ucw dot cz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).