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).