Bug 61418 - [4.9/4.10 Regression] HDF5 build failure with -flto: libgfortran.spec: attempt to rename spec 'lib' to already defined spec 'liborig'
Summary: [4.9/4.10 Regression] HDF5 build failure with -flto: libgfortran.spec: attemp...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.9.1
: P3 normal
Target Milestone: 4.9.2
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-05 06:36 UTC by Markus Trippelsdorf
Modified: 2014-06-05 14:28 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-linux-gnu
Build:
Known to work: 4.7.3, 4.8.3
Known to fail: 4.10.0, 4.9.0
Last reconfirmed: 2014-06-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2014-06-05 06:36:40 UTC
Building HDF5 with -flto fails:

/bin/sh ../../libtool  --tag=FC   --mode=link x86_64-pc-linux-gnu-gfortran -I/var/tmp/portage/sci-libs/hdf5-1.8.13/work/hdf5-1.8.13/src -I/var/tmp/portage/sci-libs/hdf5-1.8.13/work/hdf5-1.8.13/fortran/src -O2 -pipe -version-info 8:2 :0  -Wl,--hash-style=gnu,--as-needed,--gc-sections,--icf=all,--icf-iterations=3 -o libhdf5_fortran.la -rpath /usr/lib64 H5f90global.lo H5fortran_types.lo H5_ff_F90.lo H5_ff.lo H5Aff.lo H5Dff.lo H5Eff.lo H5Fff.lo H5Gff.lo H5Iff.lo H5Lff.lo H5Off.lo H5Pff.lo H5Rff.lo H5Sff.lo H5Tff.lo H5Zff.lo H5_DBLE_InterfaceInclude.lo H5f90kit.lo H5_f.lo H5Af.lo H5Df.lo H5Ef.lo H5Ff.lo H5Gf.lo H5If.lo H5Lf.lo H5Of.lo H5Pf.lo H5Rf.lo H5Sf.lo H5Tf.lo H5Zf.lo H5Aff_F90.lo H5Dff_F90.lo H5Eff_F90.lo H5Fff_F90.lo H5Lff_F90.lo H5Off_F90.lo H5Pff_F90.lo H5Rff_F90.lo H5Tff_F90.lo HDF5.lo ../../src/libhdf5.la -lz -ldl -lm 
libtool: link: x86_64-pc-linux-gnu-gfortran -shared  -fPIC  .libs/H5f90global.o .libs/H5fortran_types.o .libs/H5_ff_F90.o .libs/H5_ff.o .libs/H5Aff.o .libs/H5Dff.o .libs/H5Eff.o .libs/H5Fff.o .libs/H5Gff.o .libs/H5Iff.o .libs/H5Lff.o .libs/H5Off.o .libs/H5Pff.o .libs/H5Rff.o .libs/H5Sff.o .libs/H5Tff.o .libs/H5Zff.o .libs/H5_DBLE_InterfaceInclude.o .libs/H5f90kit.o .libs/H5_f.o .libs/H5Af.o .libs/H5Df.o .libs/H5Ef.o .libs/H5Ff.o .libs/H5Gf.o .libs/H5If.o .libs/H5Lf.o .libs/H5Of.o .libs/H5Pf.o .libs/H5Rf.o .libs/H5Sf.o .libs/H5Tf.o .libs/H5Zf.o .libs/H5Aff_F90.o .libs/H5Dff_F90.o .libs/H5Eff_F90.o .libs/H5Fff_F90.o .libs/H5Lff_F90.o .libs/H5Off_F90.o .libs/H5Pff_F90.o .libs/H5Rff_F90.o .libs/H5Tff_F90.o .libs/HDF5.o   ../../src/.libs/libhdf5.so -lz -ldl -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../.. /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libgfortran.so /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libquadmath.so -lm -lc -lgcc_s  -O2 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,--gc-sections -Wl,--icf=all -Wl,--icf-iterations=3   -Wl,-soname -Wl,libhdf5_fortran.so.8 -o .libs/libhdf5_fortran.so.8.0.2
x86_64-pc-linux-gnu-gfortran: fatal error: /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libgfortran.spec: attempt to rename spec 'lib' to already defined spec 'liborig'
compilation terminated.
lto-wrapper: /usr/x86_64-pc-linux-gnu/gcc-bin/4.9.1/x86_64-pc-linux-gnu-gfortran returned 1 exit status
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../x86_64-pc-linux-gnu/bin/ld: fatal error: lto-wrapper failed

Without -flto it builds just fine.
4.8.3 with -flto also works fine.

To reproduce start with an empty test-file:

markus@x4 /tmp % touch H5Zf.i
markus@x4 /tmp % gcc -flto -c H5Zf.i

markus@x4 /tmp % /usr/x86_64-pc-linux-gnu/gcc-bin/4.8.3/gfortran -shared -fPIC H5Zf.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../..

markus@x4 /tmp % /usr/x86_64-pc-linux-gnu/gcc-bin/4.9.1/gfortran -shared -fPIC H5Zf.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../..
gfortran: fatal error: /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../libgfortran.spec: attempt to rename spec ‘lib’ to already defined spec ‘liborig’
compilation terminated.
lto-wrapper: /usr/x86_64-pc-linux-gnu/gcc-bin/4.9.1/gfortran returned 1 exit status
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../x86_64-pc-linux-gnu/bin/ld: fatal error: lto-wrapper failed
collect2: error: ld returned 1 exit status
Comment 1 Markus Trippelsdorf 2014-06-05 06:55:27 UTC
Sorry for the noise. There was an old stale /usr/lib/libgfortran.spec
on my system. Deleting it fixed the issue.
Comment 2 Markus Trippelsdorf 2014-06-05 07:14:28 UTC
No. The issue is still there:

markus@x4 /tmp % /usr/x86_64-pc-linux-gnu/gcc-bin/4.9.1/gfortran -v -shared -fPIC H5Zf.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1

Driving: /usr/x86_64-pc-linux-gnu/gcc-bin/4.9.1/gfortran -v -shared -fPIC H5Zf.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1 -l gfortran -l m -shared-libgcc -specs=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libgfortran.spec
Using built-in specs.
Reading specs from /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libgfortran.spec
rename spec lib to liborig
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.1/gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.1 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.1 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.1/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.1/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-lto --enable-nls --without-included-gettext --with-system-zlib --disable-werror --enable-initfini-array --with-gold --enable-secureplt --disable-multilib --disable-libvtv --disable-libitm --disable-libcilkrts --disable-libssp --disable-libgomp --enable-cld --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.9.1/python --enable-checking=release --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --with-boot-ldflags=-Wl,-O1,--hash-style=gnu,--as-needed,--gc-sections,--icf=safe,--icf-iterations=3 --enable-version-specific-runtime-libs --disable-libstdcxx-pch --enable-libstdcxx-time=yes --with-build-config=bootstrap-lto
Thread model: posix
gcc version 4.9.1 20140605 (prerelease) (GCC) 
COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.1/:/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.1/:/usr/libexec/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../x86_64-pc-linux-gnu/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../x86_64-pc-linux-gnu/lib/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-shared' '-fPIC' '-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1' '-shared-libgcc' '-specs=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libgfortran.spec' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.1/collect2 -plugin /usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.1/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.1/lto-wrapper -plugin-opt=-fresolution=/tmp/ccP7xwbZ.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lquadmath -plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s --eh-frame-hdr -m elf_x86_64 -shared /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/crtbeginS.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../.. H5Zf.o -lgfortran -lm -lgcc_s -lquadmath -lm -lgcc_s -lc -lgcc_s /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../lib64/crtn.o
 /usr/x86_64-pc-linux-gnu/gcc-bin/4.9.1/gfortran @/tmp/ccmQ0Tqk.args
Driving: /usr/x86_64-pc-linux-gnu/gcc-bin/4.9.1/gfortran -xlto -c -fno-trapv -fno-strict-overflow -mtune=generic -march=x86-64 -v -shared -fPIC -L /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1 -shared-libgcc -specs=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libgfortran.spec -mtune=generic -march=x86-64 -fltrans-output-list=/tmp/ccbFnDE1.ltrans.out -fwpa -fresolution=/tmp/ccP7xwbZ.res H5Zf.o -specs=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libgfortran.spec
Using built-in specs.
Reading specs from /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libgfortran.spec
rename spec lib to liborig
Reading specs from /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libgfortran.spec
gfortran: fatal error: /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/libgfortran.spec: attempt to rename spec ‘lib’ to already defined spec ‘liborig’
compilation terminated.
lto-wrapper: /usr/x86_64-pc-linux-gnu/gcc-bin/4.9.1/gfortran returned 1 exit status
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/../../../../x86_64-pc-linux-gnu/bin/ld: fatal error: lto-wrapper failed
collect2: error: ld returned 1 exit status
Comment 3 Markus Trippelsdorf 2014-06-05 08:27:30 UTC
Started with r208375.
Comment 4 Richard Biener 2014-06-05 09:05:01 UTC
I can reproduce it with the instructions from comment#2, it works fine when
dropping the unneeded linker path.

It seems to read libgfortran.spec twice.

I can reproduce the same issue with 4.8 when adding -flto and a similar
unneeded linker path.

So 4.8 doesn't really work (with LTO).
Comment 5 Richard Biener 2014-06-05 09:18:03 UTC
Index: gcc/lto-wrapper.c
===================================================================
--- gcc/lto-wrapper.c   (revision 210514)
+++ gcc/lto-wrapper.c   (working copy)
@@ -719,6 +719,12 @@ run_gcc (unsigned argc, char *argv[])
          /* We generate new intermediate output, drop this arg.  */
          continue;
 
+       case OPT_specs_:
+         /* Drop spec overrides from the original link command, we'll
+            re-introduce them when doing the real link.  Otherwise
+            this will confuse the LTO driver, see PR61418.  */
+         continue;
+
        case OPT_save_temps:
          debug = 1;
          break;
Comment 6 Richard Biener 2014-06-05 09:21:55 UTC
Though the issue is probably that they get into COLLECT_GCC_OPTIONS at all
(they only get there with that weird -L path).  And they also get there
with 4.8 and without -flto, but only with that weird path.

And that's probably not a regression at all.

Btw, the patch will likely break users purposely using -specs=
Comment 7 Richard Biener 2014-06-05 09:33:08 UTC
gfortranspec.c does

        case OPT_L:
          if (!spec_file)
            spec_file = find_spec_file (decoded_options[i].arg);
          break;
...
  /* Read the specs file corresponding to libgfortran.
     If we didn't find the spec file on the -L path, we load it
     via lang_specific_pre_link.  */
  if (spec_file)
    append_option (OPT_specs_, spec_file, 1);

seemingly copied from Java I guess.  lang_specific_pre_link doesn't add
-specs.

int
lang_specific_pre_link (void)
{
  free (spec_file);
  if (spec_file == NULL && library)
    do_spec ("%:include(libgfortran.spec)");

  return 0;
}

I suppose it could simply do
 
 do_spec ("%:include(<expand spec_file here>)");

instead.
Comment 8 Richard Biener 2014-06-05 09:35:58 UTC
(In reply to Richard Biener from comment #7)
> gfortranspec.c does
> 
>         case OPT_L:
>           if (!spec_file)
>             spec_file = find_spec_file (decoded_options[i].arg);
>           break;
> ...
>   /* Read the specs file corresponding to libgfortran.
>      If we didn't find the spec file on the -L path, we load it
>      via lang_specific_pre_link.  */
>   if (spec_file)
>     append_option (OPT_specs_, spec_file, 1);
> 
> seemingly copied from Java I guess.  lang_specific_pre_link doesn't add
> -specs.

Oh, and that of course conflicts with manually adding -specs=libgfortran.spec.\
That is, the symtom is the same as if you do

> gfortran-4.8 t.o -shared -fPIC -specs=/usr/lib64/gcc/x86_64-suse-linux/4.8/libgfortran.spec 
gfortran-4.8: fatal error: /usr/lib64/gcc/x86_64-suse-linux/4.8/libgfortran.spec: attempt to rename spec ‘lib’ to already defined spec ‘liborig’
compilation terminated.

Really a long-standing gfortran and java driver issue.
Comment 9 Richard Biener 2014-06-05 09:40:42 UTC
Index: gfortranspec.c
===================================================================
--- gfortranspec.c      (revision 211228)
+++ gfortranspec.c      (working copy)
@@ -449,12 +449,6 @@ For more information about these matters
 
 #endif
 
-  /* Read the specs file corresponding to libgfortran.
-     If we didn't find the spec file on the -L path, we load it
-     via lang_specific_pre_link.  */
-  if (spec_file)
-    append_option (OPT_specs_, spec_file, 1);
-
   if (verbose && g77_new_decoded_options != g77_x_decoded_options)
     {
       fprintf (stderr, _("Driving:"));
@@ -473,8 +467,17 @@ For more information about these matters
 int
 lang_specific_pre_link (void)
 {
-  free (spec_file);
-  if (spec_file == NULL && library)
+  if (!library)
+    return 0;
+
+  if (spec_file)
+    {
+      char cmd = asprintf (&cmd, "%%:include(%s)", spec_file);
+      do_spec (cmd);
+      free (cmd);
+      free (spec_file);
+    }
+  else if (library)
     do_spec ("%:include(libgfortran.spec)");
 
   return 0;
Comment 10 Richard Biener 2014-06-05 09:43:21 UTC
But I'm not really familiar with this lang-specific specs additions.

libgomp for example simply does

    %{fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)}\

thus doesn't bother with finding the specs file in the library search path.

Maybe that code copied from libjava is really old, crufty and not necessary at all and gfortran should simply add a link spec similar to the one above.
Comment 11 Richard Biener 2014-06-05 10:16:32 UTC
Patch posted.
Comment 12 Markus Trippelsdorf 2014-06-05 11:51:09 UTC
(In reply to Richard Biener from comment #11)
> Patch posted.

Hmm, I see no patch. Forgot to post?
Comment 13 rguenther@suse.de 2014-06-05 11:55:58 UTC
On Thu, 5 Jun 2014, trippels at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61418
> 
> --- Comment #12 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
> (In reply to Richard Biener from comment #11)
> > Patch posted.
> 
> Hmm, I see no patch. Forgot to post?

Oops, posted to fortran@ only.
Comment 14 Richard Biener 2014-06-05 14:27:52 UTC
Author: rguenth
Date: Thu Jun  5 14:27:20 2014
New Revision: 211280

URL: http://gcc.gnu.org/viewcvs?rev=211280&root=gcc&view=rev
Log:
2014-06-05  Richard Biener  <rguenther@suse.de>

	PR fortran/61418
	* gfortranspec.c (spec_file): Remove.
	(find_spec_file): Likewise.
	(lang_specific_driver): Do not look for specs file in -L
	or append -specs command line argument.
	(lang_specific_pre_link): Always %:include libgfortran.spec.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortranspec.c
Comment 15 Richard Biener 2014-06-05 14:28:42 UTC
Fixed.
Comment 16 Richard Biener 2014-06-05 14:28:55 UTC
Author: rguenth
Date: Thu Jun  5 14:28:23 2014
New Revision: 211281

URL: http://gcc.gnu.org/viewcvs?rev=211281&root=gcc&view=rev
Log:
2014-06-05  Richard Biener  <rguenther@suse.de>

	PR fortran/61418
	* gfortranspec.c (spec_file): Remove.
	(find_spec_file): Likewise.
	(lang_specific_driver): Do not look for specs file in -L
	or append -specs command line argument.
	(lang_specific_pre_link): Always %:include libgfortran.spec.

Modified:
    branches/gcc-4_9-branch/gcc/fortran/ChangeLog
    branches/gcc-4_9-branch/gcc/fortran/gfortranspec.c