This breaks a lot of benchmarks in SPEC CPU 2000. t.c int i; t2.c int i; int main() { return i; } $ ./xgcc -B. -o t t1.c t2.c $ ./xgcc -B. -o t t1.c t2.c -flto t2.c:1:5: error: 'i' has already been defined t1.c:1:5: error: previously defined here lto-wrapper: ././xgcc returned 1 exit status collect2: lto-wrapper returned 1 exit status the LTO behavior is wrong for C. The testcase would violate the C++ ODR, but LTO should not reject the valid C program (note ODR violations do not need to be diagnosed).
Cases like t1.c int i = 2; t2.c int i = 1; int main() { return i; } are diagnosed by the linker - not ideal, but not different from -fno-lto either. Index: lto-symtab.c =================================================================== --- lto-symtab.c (revision 149512) +++ lto-symtab.c (working copy) @@ -568,15 +568,17 @@ lto_symtab_merge_decl (tree new_decl, if (resolution == LDPR_PREVAILING_DEF || resolution == LDPR_PREVAILING_DEF_IRONLY) { - if (old_resolution == LDPR_PREVAILING_DEF - || old_resolution == LDPR_PREVAILING_DEF_IRONLY) + if ((old_resolution == LDPR_PREVAILING_DEF + || old_resolution == LDPR_PREVAILING_DEF_IRONLY) + && old_resolution != resolution) { error ("%J%qD has already been defined", new_decl, new_decl); error ("%Jpreviously defined here", old_decl); return; } gcc_assert (old_resolution == LDPR_PREEMPTED_IR - || old_resolution == LDPR_RESOLVED_IR); + || old_resolution == LDPR_RESOLVED_IR + || old_resolution == resolution); lto_symtab_set_identifier_decl (name, new_decl); return; }
Note this is only true for the non -fno-common case. Really this is an extension to the standard C language but we should support it.
Subject: Re: [LTO] complains about two tentative definitions On Sat, 11 Jul 2009, pinskia at gcc dot gnu dot org wrote: > ------- Comment #2 from pinskia at gcc dot gnu dot org 2009-07-11 18:05 ------- > Note this is only true for the non -fno-common case. Really this is an > extension to the standard C language but we should support it. You mean it is only true for -fcommon (which is the default)? Richard.
(In reply to comment #3) > Subject: Re: [LTO] complains about two tentative > definitions > > On Sat, 11 Jul 2009, pinskia at gcc dot gnu dot org wrote: > > > ------- Comment #2 from pinskia at gcc dot gnu dot org 2009-07-11 18:05 ------- > > Note this is only true for the non -fno-common case. Really this is an > > extension to the standard C language but we should support it. > > You mean it is only true for -fcommon (which is the default)? What I write is the same as what your wrote (I had two negatives ;) . -- Pinski
Confirmed.
Subject: Bug 40721 Author: rguenth Date: Mon Jul 13 13:42:03 2009 New Revision: 149587 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149587 Log: 2009-07-13 Richard Guenther <rguenther@suse.de> PR lto/40721 * lto-opts.c (register_user_option_p): Handle OPT_fcommon. (handle_common_option): Likewise. * lto-symtab.c (lto_symtab_merge_decl): Merge re-definitions if flag_no_common is not set. Modified: branches/lto/gcc/ChangeLog.lto branches/lto/gcc/lto-opts.c branches/lto/gcc/lto-symtab.c
Fixed.